gothinkster / node-express-realworld-example-app

3.58k stars 1.61k forks source link

Most of the tests fail #61

Open mjgs opened 6 years ago

mjgs commented 6 years ago

I'm not familiar with newman, so no idea how to debug this, there is just two json files, where is the code?

/tmp $ git clone https://github.com/gothinkster/node-express-realworld-example-app
Cloning into 'node-express-realworld-example-app'...
remote: Counting objects: 250, done.
remote: Total 250 (delta 0), reused 0 (delta 0), pack-reused 250
Receiving objects: 100% (250/250), 127.33 KiB | 149.00 KiB/s, done.
Resolving deltas: 100% (116/116), done.
/tmp $ cd node-express-realworld-example-app/
/tmp/node-express-realworld-example-app $ npm install
npm WARN deprecated ejs@2.4.1: Critical security bugs fixed in 2.5.5
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
npm WARN deprecated tough-cookie@2.2.2: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
npm WARN deprecated mongodb@2.1.10: Please upgrade to 2.2.19 or higher

> fsevents@1.2.4 install /private/tmp/node-express-realworld-example-app/node_modules/fsevents
> node install

[fsevents] Success: "/private/tmp/node-express-realworld-example-app/node_modules/fsevents/lib/binding/Release/node-v59-darwin-x64/fse.node" is installed via remote

> nodemon@1.18.2 postinstall /private/tmp/node-express-realworld-example-app/node_modules/nodemon
> node bin/postinstall || exit 0

npm notice created a lockfile as package-lock.json. You should commit this file.
added 653 packages in 31.609s
/tmp/node-express-realworld-example-app $ npm test

> conduit-node@1.0.0 test /private/tmp/node-express-realworld-example-app
> newman run ./tests/api-tests.postman.json -e ./tests/env-api-tests.postman.json

newman

Conduit API Tests

❏ Auth
↳ Register
  POST http://localhost:3000/api/users   2⠄ JSONError in test-script

↳ Login
  POST http://localhost:3000/api/users/login   4⠄ JSONError in test-script

↳ Login and Remember Token
  POST http://localhost:3000/api/users/login   6⠄ JSONError in test-script

↳ Current User
  GET http://localhost:3000/api/user   8⠄ JSONError in test-script

↳ Update User
  PUT http://localhost:3000/api/user  10⠄ JSONError in test-script

❏ Articles with authentication
↳ Feed
  GET http://localhost:3000/api/articles/feed  12. Response code is 200 OK

↳ All Articles
  GET http://localhost:3000/api/articles  14. Response code is 200 OK

↳ All Articles with auth
  GET http://localhost:3000/api/articles  16. Response code is 200 OK

↳ Articles by Author
  GET http://localhost:3000/api/articles?author=johnjacob  18. Response code is 200 OK

↳ Articles by Author with auth
  GET http://localhost:3000/api/articles?author=johnjacob  20. Response code is 200 OK

↳ Articles Favorited by Username
  GET http://localhost:3000/api/articles?favorited=jane  22. Response code is 200 OK

↳ Articles Favorited by Username with auth
  GET http://localhost:3000/api/articles?favorited=jane  24. Response code is 200 OK

↳ Articles by Tag
  GET http://localhost:3000/api/articles?tag=dragons  26. Response code is 200 OK

↳ Create Article
  POST http://localhost:3000/api/articles  28⠄ JSONError in test-script

↳ Single Article by slug
  GET http://localhost:3000/api/articles/{{slug}}  30⠄ JSONError in test-script

↳ Update Article
  PUT http://localhost:3000/api/articles/{{slug}}  32⠄ JSONError in test-script

↳ Favorite Article
  POST http://localhost:3000/api/articles/{{slug}}/favorite  34⠄ JSONError in test-script

↳ Unfavorite Article
  DELETE http://localhost:3000/api/articles/{{slug}}/favorite  36⠄ JSONError in test-script

❏ Articles
↳ All Articles
  GET http://localhost:3000/api/articles  38. Response code is 200 OK

↳ Articles by Author
  GET http://localhost:3000/api/articles?author=johnjacob  40. Response code is 200 OK

↳ Articles Favorited by Username
  GET http://localhost:3000/api/articles?favorited=jane  42. Response code is 200 OK

↳ Articles by Tag
  GET http://localhost:3000/api/articles?tag=dragons  44. Response code is 200 OK

↳ Single Article by slug
  GET http://localhost:3000/api/articles/{{slug}}  46⠄ JSONError in test-script

❏ Comments
↳ All Comments for Article
  GET http://localhost:3000/api/articles/{{slug}}/comments  48. Response code is 200 OK

↳ Create Comment for Article
  POST http://localhost:3000/api/articles/{{slug}}/comments  50⠄ JSONError in test-script

↳ Delete Comment for Article
  DELETE http://localhost:3000/api/articles/{{slug}}/comments/1
❏ Profiles
↳ Profile
  GET http://localhost:3000/api/profiles/johnjacob  53. Response code is 200 OK

↳ Follow Profile
  POST http://localhost:3000/api/profiles/johnjacob/follow  55. Response code is 200 OK

↳ Unfollow Profile
  DELETE http://localhost:3000/api/profiles/johnjacob/follow  57. Response code is 200 OK

❏ Tags
↳ All Tags
  GET http://localhost:3000/api/tags  59. Response code is 200 OK

❏ Cleanup
↳ Delete Article
  DELETE http://localhost:3000/api/articles/{{slug}}
┌─────────────────────────┬──────────┬──────────┐
│                         │ executed │   failed │
├─────────────────────────┼──────────┼──────────┤
│              iterations │        1 │        0 │
├─────────────────────────┼──────────┼──────────┤
│                requests │       31 │       31 │
├─────────────────────────┼──────────┼──────────┤
│            test-scripts │       29 │       12 │
├─────────────────────────┼──────────┼──────────┤
│      prerequest-scripts │        0 │        0 │
├─────────────────────────┼──────────┼──────────┤
│              assertions │       17 │       17 │
├─────────────────────────┴──────────┴──────────┤
│ total run duration: 772ms                     │
├───────────────────────────────────────────────┤
│ total data received: 0B (approx)              │
├───────────────────────────────────────────────┤
│ average response time: 0ms                    │
└───────────────────────────────────────────────┘

   #  failure                    detail

 01.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Auth / Register"

 02.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Auth / Register"

 03.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Auth / Login"

 04.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Auth / Login"

 05.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Auth / Login and Remember Token"

 06.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Auth / Login and Remember Token"

 07.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Auth / Current User"

 08.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Auth / Current User"

 09.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Auth / Update User"

 10.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Auth / Update User"

 11.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Feed"

 12.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Feed"

 13.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / All Articles"

 14.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / All Articles"

 15.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / All Articles with auth"

 16.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / All Articles with auth"

 17.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Articles by Author"

 18.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Articles by Author"

 19.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Articles by Author with auth"

 20.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Articles by Author with auth"

 21.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Articles Favorited by Username"

 22.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Articles Favorited by Username"

 23.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Articles Favorited by Username with auth"

 24.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Articles Favorited by Username with auth"

 25.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Articles by Tag"

 26.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Articles by Tag"

 27.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Create Article"

 28.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles with authentication / Create Article"

 29.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Single Article by slug"

 30.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles with authentication / Single Article by slug"

 31.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Update Article"

 32.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles with authentication / Update Article"

 33.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Favorite Article"

 34.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles with authentication / Favorite Article"

 35.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Unfavorite Article"

 36.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles with authentication / Unfavorite Article"

 37.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles / All Articles"

 38.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles / All Articles"

 39.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles / Articles by Author"

 40.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles / Articles by Author"

 41.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles / Articles Favorited by Username"

 42.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles / Articles Favorited by Username"

 43.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles / Articles by Tag"

 44.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles / Articles by Tag"

 45.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles / Single Article by slug"

 46.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles / Single Article by slug"

 47.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Comments / All Comments for Article"

 48.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Comments / All Comments for Article"

 49.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Comments / Create Comment for Article"

 50.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Comments / Create Comment for Article"

 51.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Comments / Delete Comment for Article"

 52.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Profiles / Profile"

 53.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Profiles / Profile"

 54.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Profiles / Follow Profile"

 55.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Profiles / Follow Profile"

 56.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Profiles / Unfollow Profile"

 57.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Profiles / Unfollow Profile"

 58.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Tags / All Tags"

 59.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Tags / All Tags"

 60.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Cleanup / Delete Article"
npm ERR! Test failed.  See above for more details.
/tmp/node-express-realworld-example-app $ node -v
v9.2.0
migliozziz commented 6 years ago

You ran the test without starting the application. Be sure to npm run dev before you npm run test. You can find your test files in ./test.

mjgs commented 6 years ago

Right, that's better. Might be an idea to have the app start in whatever the newman equivalent of a before hook is. All the tests now pass apart from:

Auth ↳ Register POST http://localhost:3000/api/users [422 Unprocessable Entity, 358B, 163ms]

  1. Response contains "user" property
  2. User has "email" property
  3. User has "username" property
  4. User has "token" property

I can see the test code in the json file now, how do I run and debug it? Is there some way to extract the code so I can run it in a debugger?

ftes commented 5 years ago

I suggest closing this issue. The tests run fine if the app is first started. I think that's a fair precondition.