tethys.backend/bin/test.ts

63 lines
1.8 KiB
TypeScript
Raw Permalink Normal View History

2024-03-14 19:25:27 +00:00
/*
|--------------------------------------------------------------------------
| Test runner entrypoint
|--------------------------------------------------------------------------
|
| The "test.ts" file is the entrypoint for running tests using Japa.
|
| Either you can run this file directly or use the "test"
| command to run this file and monitor file changes.
|
*/
process.env.NODE_ENV = 'test';
2024-03-14 19:25:27 +00:00
import 'reflect-metadata';
import { Ignitor, prettyPrintError } from '@adonisjs/core';
import { configure, processCLIArgs, run } from '@japa/runner';
2024-03-14 19:25:27 +00:00
/**
* URL to the application root. AdonisJS need it to resolve
* paths to file and directories for scaffolding commands
*/
const APP_ROOT = new URL('../', import.meta.url);
2024-03-14 19:25:27 +00:00
/**
* The importer is used to import files in context of the
* application.
*/
const IMPORTER = (filePath: string) => {
if (filePath.startsWith('./') || filePath.startsWith('../')) {
return import(new URL(filePath, APP_ROOT).href);
}
return import(filePath);
};
2024-03-14 19:25:27 +00:00
new Ignitor(APP_ROOT, { importer: IMPORTER })
.tap((app) => {
app.booting(async () => {
await import('#start/env');
});
app.listen('SIGTERM', () => app.terminate());
app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate());
2024-03-14 19:25:27 +00:00
})
.testRunner()
.configure(async (app) => {
const { runnerHooks, ...config } = await import('../tests/bootstrap.js');
2024-03-14 19:25:27 +00:00
processCLIArgs(process.argv.splice(2));
configure({
...app.rcFile.tests,
...config,
...{
setup: runnerHooks.setup,
teardown: runnerHooks.teardown.concat([() => app.terminate()]),
},
});
2024-03-14 19:25:27 +00:00
})
.run(() => run())
.catch((error) => {
process.exitCode = 1;
prettyPrintError(error);
});