aboutsummaryrefslogtreecommitdiffstats
path: root/bin/test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'bin/test.ts')
-rw-r--r--bin/test.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/bin/test.ts b/bin/test.ts
new file mode 100644
index 0000000..fe7e950
--- /dev/null
+++ b/bin/test.ts
@@ -0,0 +1,60 @@
1/*
2|--------------------------------------------------------------------------
3| Test runner entrypoint
4|--------------------------------------------------------------------------
5|
6| The "test.ts" file is the entrypoint for running tests using Japa.
7|
8| Either you can run this file directly or use the "test"
9| command to run this file and monitor file changes.
10|
11*/
12
13process.env.NODE_ENV = 'test'
14
15import 'reflect-metadata'
16import { Ignitor, prettyPrintError } from '@adonisjs/core'
17import { configure, processCLIArgs, run } from '@japa/runner'
18
19/**
20 * URL to the application root. AdonisJS need it to resolve
21 * paths to file and directories for scaffolding commands
22 */
23const APP_ROOT = new URL('../', import.meta.url)
24
25/**
26 * The importer is used to import files in context of the
27 * application.
28 */
29const IMPORTER = (filePath: string) => {
30 if (filePath.startsWith('./') || filePath.startsWith('../')) {
31 return import(new URL(filePath, APP_ROOT).href)
32 }
33 return import(filePath)
34}
35
36new Ignitor(APP_ROOT, { importer: IMPORTER })
37 .tap((app) => {
38 app.booting(async () => {
39 await import('#start/env')
40 })
41 app.listen('SIGTERM', () => app.terminate())
42 app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate())
43 })
44 .testRunner()
45 .configure(async (app) => {
46 const { runnerHooks, ...config } = await import('../tests/bootstrap.js')
47
48 processCLIArgs(process.argv.splice(2))
49 configure({
50 ...app.rcFile.tests,
51 ...config,
52 setup: runnerHooks.setup,
53 teardown: [...runnerHooks.teardown, () => app.terminate()],
54 })
55 })
56 .run(() => run())
57 .catch((error) => {
58 process.exitCode = 1
59 prettyPrintError(error)
60 })