Open himanshu64 opened 7 years ago
@caio-ribeiro-pereira please check this
I'm facing the same issue.
I'm facing the same issue.
I'm facing the same issue
Sorry for the delay of answering this issue......soon I will update all modules and code of this project to fix all current bugs and I will tell you guys, thanks!
Olá Caio, o erro ainda continua.
` Routes: Index GET / √ returns the API status
Routes: Token POST /token status 200 1) returns authenticated user token status 401 √ throws error when password is incorrect √ throws error when email not exist √ throws error when email and password are blank
4 passing (1s) 1 failing
1) Routes: Token POST /token status 200 returns authenticated user token:
Uncaught AssertionError: expected {} to contain key 'token'
+ expected - actual
-[]
+[
+ "token"
+]
at Test.<anonymous> (D:/Cursos/Nodejs/Api Restful/ntask/test/routes/token.js:25:41)
at Test.assert (node_modules\supertest\lib\test.js:181:6)
at Server.localAssert (node_modules\supertest\lib\test.js:131:12)
at emitCloseNT (net.js:1618:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR! Test failed. See above for more details.`
Tem uma solução para esse erro?
Hi guys! Sorry for the delay....
To solve this current issue, please, try to initialize the api server first using npm start
, this will run all database migrations, then close this api command (CTRL+C or COMMAND+C) and try to run again the npm test
.
I know, this is not the best way, but it works here and I promise I will update this project codebase using all latest modules and new resources soon.
Caio, continua dando o mesmo erro, mesmo após executar o npm start e demais processos descritos acima.
@allancmello ja tentou excluir o ntastk.sqlite
para rodar npm start
, fecha e em seguida npm test
?
Caio, fiz o que vc pediu e o resultado agora e:
D:\Cursos\Nodejs\Api Restful\ntask>npm test
ntask@1.0.0 test D:\Cursos\Nodejs\Api Restful\ntask SET NODE_ENV=test&&mocha test/*/.js
Routes: Index GET / 1) returns the API status
Routes: Tasks GET /tasks status 200 2) returns a list of tasks POST /tasks status 200 3) creates a new task GET /tasks/:id status 200 4) returns one task status 404 5) throws error when task not exist PUT /tasks/:id status 204 6) updates a task DELETE /tasks/:id status 204 7) removes a task
Routes: Token POST /token status 200 8) returns authenticated user token status 401 √ throws error when password is incorrect √ throws error when email not exist √ throws error when email and password are blank
3 passing (4s) 8 failing
1) Routes: Index GET / returns the API status:
Uncaught AssertionError: expected { status: 'Task API' } to deeply equal { status: 'NTask API' }
+ expected - actual
{
- "status": "Task API"
+ "status": "NTask API"
}
at Test.<anonymous> (D:/Cursos/Nodejs/Api Restful/ntask/test/routes/index.js:10:41)
at Test.assert (node_modules\supertest\lib\test.js:181:6)
at Server.localAssert (node_modules\supertest\lib\test.js:131:12)
at emitCloseNT (net.js:1618:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
2) Routes: Tasks
GET /tasks
status 200
returns a list of tasks:
Uncaught AssertionError: expected {} to have property 'length'
at Test.
3) Routes: Tasks
POST /tasks
status 200
creates a new task:
Uncaught AssertionError: expected undefined to deeply equal 'Run'
at Test.
4) Routes: Tasks
GET /tasks/:id
status 200
returns one task:
Uncaught AssertionError: expected undefined to deeply equal 'Work'
at Test.
5) Routes: Tasks GET /tasks/:id status 404 throws error when task not exist: Error: expected 404 "Not Found", got 401 "Unauthorized" at Test._assertStatus (node_modules\supertest\lib\test.js:268:12) at Test._assertFunction (node_modules\supertest\lib\test.js:283:11) at Test.assert (node_modules\supertest\lib\test.js:173:18) at Server.localAssert (node_modules\supertest\lib\test.js:131:12) at emitCloseNT (net.js:1618:8) at process._tickCallback (internal/process/next_tick.js:63:19)
6) Routes: Tasks PUT /tasks/:id status 204 updates a task: Error: expected 204 "No Content", got 401 "Unauthorized" at Test._assertStatus (node_modules\supertest\lib\test.js:268:12) at Test._assertFunction (node_modules\supertest\lib\test.js:283:11) at Test.assert (node_modules\supertest\lib\test.js:173:18) at Server.localAssert (node_modules\supertest\lib\test.js:131:12) at emitCloseNT (net.js:1618:8) at process._tickCallback (internal/process/next_tick.js:63:19)
7) Routes: Tasks DELETE /tasks/:id status 204 removes a task: Error: expected 204 "No Content", got 401 "Unauthorized" at Test._assertStatus (node_modules\supertest\lib\test.js:268:12) at Test._assertFunction (node_modules\supertest\lib\test.js:283:11) at Test.assert (node_modules\supertest\lib\test.js:173:18) at Server.localAssert (node_modules\supertest\lib\test.js:131:12) at emitCloseNT (net.js:1618:8) at process._tickCallback (internal/process/next_tick.js:63:19)
8) Routes: Token POST /token status 200 returns authenticated user token:
Uncaught AssertionError: expected {} to contain key 'token'
+ expected - actual
-[]
+[
+ "token"
+]
at Test.<anonymous> (D:/Cursos/Nodejs/Api Restful/ntask/test/routes/token.js:24:49)
at Test.assert (node_modules\supertest\lib\test.js:181:6)
at Server.localAssert (node_modules\supertest\lib\test.js:131:12)
at emitCloseNT (net.js:1618:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR! Test failed. See above for more details.
Erros que antes de apagar o ntask.sqlite não apareciam.
Creio que estes erros devem ter relação com as versões atuais. Meu packge.json:
{ "name": "ntask", "version": "1.0.0", "description": "Api Task", "main": "index.js", "scripts": { "dev": "nodemon index.js", "start": "npm run apidoc && npm run clusters", "clusters": "babel-node cluster.js", "apidoc": "apidoc -i routes/ -o public/apidoc", "test": "SET NODE_ENV=test&&mocha test/*/.js" }, "apidoc": { "name": "Documentação - Node Task API", "template": { "forceLanguage": "pt_br" } }, "author": "Alan Melo", "devDependencies": { "apidoc": "^0.17.7", "babel-cli": "^6.26.0", "babel-preset-es2015": "^6.24.1", "babel-register": "^6.26.0", "bcrypt": "^3.0.5", "body-parser": "^1.18.3", "chai": "^4.2.0", "compression": "^1.7.4", "consign": "^0.1.6", "cors": "^2.8.5", "express": "^4.16.4", "helmet": "^3.16.0", "jwt-simple": "^0.5.5", "mocha": "^6.0.2", "morgan": "^1.9.1", "passport": "^0.4.0", "passport-jwt": "^4.0.0", "supertest": "^4.0.2", "winston": "^3.2.1" }, "dependencies": { "sequelize": "^5.1.1", "sqlite3": "^4.0.6" } }
Para suas considerações.
@allancmello sugiro que utilize a versão antiga do sequelize, pois surgiram diversas break changes
desde a versão desse repositorio vs com a versão atual, repare que os erros dos seus testes ocorrem somente em rotas que tentam consumir o bando de dados, sugestão ou vc utiliza a versão antiga ou se aventure nas documentações do sequelize para aplicar os códigos novos da versão 5.x.
No meu caso estava dando o mesmo erro o motivo foi o fechamento das chaves do "describe("POST /token", () => { }"estava fechando antes "describe("status 200", () => {}"
Routes: Token POST /token status 200
**Unhandled rejection SequelizeBaseError: null**
Unhandled rejection SequelizeBaseError: null at /home/dell/Workspace/Web/ntask-api/node_modules/sequelize/lib/instance-validator.js:74:14 at tryCatcher (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:512:31) at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:569:18) at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10) at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18) at Promise._fulfill (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:638:18) at PromiseArray._resolve (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:126:19) at PromiseArray._promiseFulfilled (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:144:14) at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:574:26) at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10) at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18) at Async._drainQueue (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:133:16) at Async._drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:143:10) at Immediate.Async.drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:17:14) at runCallback (timers.js:672:20) at tryOnImmediate (timers.js:645:5) at processImmediate [as _immediateCallback] (timers.js:617:5)
Unhandled rejection SequelizeBaseError: null at /home/dell/Workspace/Web/ntask-api/node_modules/sequelize/lib/instance-validator.js:74:14 at tryCatcher (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:512:31) at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:569:18) at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10) at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18) at Promise._fulfill (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:638:18) at PromiseArray._resolve (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:126:19) at PromiseArray._promiseFulfilled (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:144:14) at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:574:26) at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10) at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18) at Async._drainQueue (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:133:16) at Async._drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:143:10) at Immediate.Async.drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:17:14) at runCallback (timers.js:672:20) at tryOnImmediate (timers.js:645:5) at processImmediate [as _immediateCallback] (timers.js:617:5)
Unhandled rejection SequelizeBaseError: null at /home/dell/Workspace/Web/ntask-api/node_modules/sequelize/lib/instance-validator.js:74:14 at tryCatcher (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:512:31) at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:569:18) at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10) at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18) at Promise._fulfill (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:638:18) at PromiseArray._resolve (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:126:19) at PromiseArray._promiseFulfilled (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:144:14) at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:574:26) at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10) at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18) at Async._drainQueue (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:133:16) at Async._drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:143:10) at Immediate.Async.drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:17:14) at runCallback (timers.js:672:20) at tryOnImmediate (timers.js:645:5) at processImmediate [as _immediateCallback] (timers.js:617:5)
4 passing (187ms) 1 failing
1) Routes: Token POST /token status 200 returns authenticated user token: