diff options
author | MCMXC <16797721+mcmxcdev@users.noreply.github.com> | 2024-02-10 18:19:14 -0700 |
---|---|---|
committer | Vijay A <vraravam@users.noreply.github.com> | 2024-02-13 06:59:44 +0530 |
commit | 7584d2d7a7110aef0331ebfa178b2295842c59fa (patch) | |
tree | 900cd71237e6231b57936fcce77ff229cd459041 /bin/test.ts | |
parent | upgrade recipes submodule (diff) | |
download | ferdium-server-7584d2d7a7110aef0331ebfa178b2295842c59fa.tar.gz ferdium-server-7584d2d7a7110aef0331ebfa178b2295842c59fa.tar.zst ferdium-server-7584d2d7a7110aef0331ebfa178b2295842c59fa.zip |
refactor: project maintenance
- work in progress
Diffstat (limited to 'bin/test.ts')
-rw-r--r-- | bin/test.ts | 60 |
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 | |||
13 | process.env.NODE_ENV = 'test' | ||
14 | |||
15 | import 'reflect-metadata' | ||
16 | import { Ignitor, prettyPrintError } from '@adonisjs/core' | ||
17 | import { 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 | */ | ||
23 | const APP_ROOT = new URL('../', import.meta.url) | ||
24 | |||
25 | /** | ||
26 | * The importer is used to import files in context of the | ||
27 | * application. | ||
28 | */ | ||
29 | const 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 | |||
36 | new 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 | }) | ||