bootstrap.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * File source: https://bit.ly/3ukaHTz
  3. *
  4. * Feel free to let us know via PR, if you find something broken in this contract
  5. * file.
  6. */
  7. import type { Config } from '@japa/runner'
  8. import TestUtils from '@ioc:Adonis/Core/TestUtils'
  9. import { assert, runFailedTests, specReporter, apiClient } from '@japa/preset-adonis'
  10. /*
  11. |--------------------------------------------------------------------------
  12. | Japa Plugins
  13. |--------------------------------------------------------------------------
  14. |
  15. | Japa plugins allows you to add additional features to Japa. By default
  16. | we register the assertion plugin.
  17. |
  18. | Feel free to remove existing plugins or add more.
  19. |
  20. */
  21. export const plugins: Required<Config>['plugins'] = [assert(), runFailedTests(), apiClient()]
  22. /*
  23. |--------------------------------------------------------------------------
  24. | Japa Reporters
  25. |--------------------------------------------------------------------------
  26. |
  27. | Japa reporters displays/saves the progress of tests as they are executed.
  28. | By default, we register the spec reporter to show a detailed report
  29. | of tests on the terminal.
  30. |
  31. */
  32. export const reporters: Required<Config>['reporters'] = [specReporter()]
  33. /*
  34. |--------------------------------------------------------------------------
  35. | Runner hooks
  36. |--------------------------------------------------------------------------
  37. |
  38. | Runner hooks are executed after booting the AdonisJS app and
  39. | before the test files are imported.
  40. |
  41. | You can perform actions like starting the HTTP server or running migrations
  42. | within the runner hooks
  43. |
  44. */
  45. export const runnerHooks: Pick<Required<Config>, 'setup' | 'teardown'> = {
  46. setup: [() => TestUtils.ace().loadCommands()],
  47. teardown: []
  48. }
  49. /*
  50. |--------------------------------------------------------------------------
  51. | Configure individual suites
  52. |--------------------------------------------------------------------------
  53. |
  54. | The configureSuite method gets called for every test suite registered
  55. | within ".adonisrc.json" file.
  56. |
  57. | You can use this method to configure suites. For example: Only start
  58. | the HTTP server when it is a functional suite.
  59. */
  60. export const configureSuite: Required<Config>['configureSuite'] = (suite) => {
  61. if (suite.name === 'functional') {
  62. suite.setup(() => TestUtils.httpServer().start())
  63. }
  64. }