All our tests are all located inside test.js.
They can be run with:
cd web
npm test
The dynamic website tests also uses Mocha just like the tests for OurBigBook CLI and OurBigBook Library, so similar usage patterns apply, e.g. to run just a single test:
or to show database queries being done in the tests:
npm test -- -g 'substring of test title'
DEBUG='*:sql:*' npm test
To run the tests on PostgreSQL instead of SQLite, first setup as in local run as identical to deployment as possible, and then:
Run only matching tests on PostgreSQL:
npm run test-pg
npm run test-pg -- -g 'substring of test title'
Note that this will erase all data present in the database used. In order to point to a custom database use:
We don't use
DATABASE_URL_TEST=postgres://realworld_next_user:a@localhost:5432/realworld_next_test npm run test-pg
DATABASE_URL
when running tests as a safeguard to reduce the likelihood of accidentally nuking the production database.The tests include two broad classes of tests:
- API tests: launch the server on a random port, and run API commands, thus testing the entire backend
- smaller unit tests that only call certain functions directly
- TODO: create frontend tests: github.com/cirosantilli/node-express-sequelize-nextjs-realworld-example-app/issues/11