helper.js 846 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict'
  2. // This file contains code that we reuse
  3. // between our tests.
  4. const { build: buildApplication } = require('fastify-cli/helper')
  5. const path = require('path')
  6. const AppPath = path.join(__dirname, '..', 'app.js')
  7. // Fill in this config with all the configurations
  8. // needed for testing the application
  9. function config () {
  10. return {}
  11. }
  12. // automatically build and tear down our instance
  13. async function build (t) {
  14. // you can set all the options supported by the fastify CLI command
  15. const argv = [AppPath]
  16. // fastify-plugin ensures that all decorators
  17. // are exposed for testing purposes, this is
  18. // different from the production setup
  19. const app = await buildApplication(argv, config())
  20. // tear down our app after we are done
  21. t.teardown(app.close.bind(app))
  22. return app
  23. }
  24. module.exports = {
  25. config,
  26. build
  27. }