mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-10-17 05:14:19 +02:00
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
/*
|
|
|--------------------------------------------------------------------------
|
|
| 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'
|
|
|
|
// Keep a clean checkout able to boot the test runner without requiring a
|
|
// developer's database/Redis credentials. A checked-in .env.test still wins
|
|
// through Adonis' normal environment loading; these values only fill gaps.
|
|
const testDefaults: Record<string, string> = {
|
|
PORT: '3333',
|
|
APP_KEY: 'test-only-app-key-not-for-production',
|
|
HOST: '127.0.0.1',
|
|
URL: 'http://127.0.0.1:3333',
|
|
LOG_LEVEL: 'error',
|
|
DB_HOST: '127.0.0.1',
|
|
DB_PORT: '3306',
|
|
DB_USER: 'root',
|
|
DB_DATABASE: 'nomad_test',
|
|
REDIS_HOST: '127.0.0.1',
|
|
REDIS_PORT: '6379',
|
|
}
|
|
|
|
for (const [key, value] of Object.entries(testDefaults)) {
|
|
process.env[key] ??= value
|
|
}
|
|
|
|
import 'reflect-metadata'
|
|
import { Ignitor, prettyPrintError } from '@adonisjs/core'
|
|
import { configure, processCLIArgs, run } from '@japa/runner'
|
|
|
|
/**
|
|
* 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)
|
|
|
|
/**
|
|
* 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)
|
|
}
|
|
|
|
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())
|
|
})
|
|
.testRunner()
|
|
.configure(async (app) => {
|
|
const { runnerHooks, ...config } = await import('../tests/bootstrap.js')
|
|
|
|
processCLIArgs(process.argv.splice(2))
|
|
configure({
|
|
...app.rcFile.tests,
|
|
...config,
|
|
...{
|
|
setup: runnerHooks.setup,
|
|
teardown: runnerHooks.teardown.concat([() => app.terminate()]),
|
|
},
|
|
})
|
|
})
|
|
.run(() => run())
|
|
.catch((error) => {
|
|
process.exitCode = 1
|
|
prettyPrintError(error)
|
|
})
|