Skip to content

Instantly share code, notes, and snippets.

@jsdecena
Created July 5, 2020 07:37
Show Gist options
  • Save jsdecena/4ca3345f2bbed1486449637062f96c97 to your computer and use it in GitHub Desktop.
Save jsdecena/4ca3345f2bbed1486449637062f96c97 to your computer and use it in GitHub Desktop.
Simple TDD in Nodejs
'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