Created
July 5, 2020 07:37
-
-
Save jsdecena/4ca3345f2bbed1486449637062f96c97 to your computer and use it in GitHub Desktop.
Simple TDD in Nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
/* | |
|-------------------------------------------------------------------------- | |
| Vow file | |
|-------------------------------------------------------------------------- | |
| | |
| The vow file is loaded before running your tests. This is the best place | |
| to hook operations `before` and `after` running the tests. | |
| | |
*/ | |
// Uncomment when want to run migrations | |
const ace = require('@adonisjs/ace') | |
module.exports = (cli, runner) => { | |
runner.before(async () => { | |
/* | |
|-------------------------------------------------------------------------- | |
| Start the server | |
|-------------------------------------------------------------------------- | |
| | |
| Starts the http server before running the tests. You can comment this | |
| line, if http server is not required | |
| | |
*/ | |
use('Adonis/Src/Server').listen(process.env.HOST, process.env.PORT) | |
/* | |
|-------------------------------------------------------------------------- | |
| Run migrations | |
|-------------------------------------------------------------------------- | |
| | |
| Migrate the database before starting the tests. | |
| | |
*/ | |
await ace.call('migration:run', {}, { silent: true }) | |
}) | |
runner.after(async () => { | |
/* | |
|-------------------------------------------------------------------------- | |
| Shutdown server | |
|-------------------------------------------------------------------------- | |
| | |
| Shutdown the HTTP server when all tests have been executed. | |
| | |
*/ | |
use('Adonis/Src/Server').getInstance().close() | |
/* | |
|-------------------------------------------------------------------------- | |
| Rollback migrations | |
|-------------------------------------------------------------------------- | |
| | |
| Once all tests have been completed, we should reset the database to it's | |
| original state | |
| | |
*/ | |
await ace.call('migration:reset', {}, { silent: true }) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment