2024-08-09 23:51:41 +02:00
|
|
|
#!/usr/bin/env -S node --import=tsx
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test runner entrypoint
|
|
|
|
*
|
|
|
|
* Entrypoint for running tests using Japa.
|
|
|
|
*/
|
|
|
|
|
|
|
|
process.env["NODE_ENV"] = "test"
|
2024-08-12 14:21:34 +02:00
|
|
|
process.env["PORT"] = "3333"
|
2024-08-12 15:13:24 +02:00
|
|
|
process.env["LIMITER_STORE"] = "memory"
|
2024-08-15 15:14:21 +02:00
|
|
|
process.env["LOG_LEVEL"] = "error"
|
2024-08-09 23:51:41 +02:00
|
|
|
|
|
|
|
import { Ignitor, prettyPrintError } from "@adonisjs/core"
|
|
|
|
import { configure, processCLIArgs, run } from "@japa/runner"
|
|
|
|
import "reflect-metadata"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 = async (filePath: string): Promise<unknown> => {
|
|
|
|
if (filePath.startsWith("./") || filePath.startsWith("../")) {
|
|
|
|
return await import(new URL(filePath, APP_ROOT).href)
|
|
|
|
}
|
|
|
|
return await import(filePath)
|
|
|
|
}
|
|
|
|
|
|
|
|
const ignitor = new Ignitor(APP_ROOT, { importer: IMPORTER })
|
|
|
|
|
|
|
|
try {
|
|
|
|
await ignitor
|
|
|
|
.tap((app) => {
|
|
|
|
app.booting(async () => {
|
2024-08-15 15:14:21 +02:00
|
|
|
await import("#start/env.ts")
|
2024-08-09 23:51:41 +02:00
|
|
|
})
|
|
|
|
app.listen("SIGTERM", async () => {
|
|
|
|
return await app.terminate()
|
|
|
|
})
|
|
|
|
app.listenIf(app.managedByPm2, "SIGINT", async () => {
|
|
|
|
return await app.terminate()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.testRunner()
|
|
|
|
.configure(async (app) => {
|
2024-08-15 15:14:21 +02:00
|
|
|
const { runnerHooks, ...config } = await import("#tests/bootstrap.ts")
|
2024-08-09 23:51:41 +02:00
|
|
|
|
|
|
|
processCLIArgs(process.argv.splice(2))
|
|
|
|
configure({
|
|
|
|
...app.rcFile.tests,
|
|
|
|
...config,
|
|
|
|
...{
|
|
|
|
setup: runnerHooks.setup,
|
|
|
|
teardown: runnerHooks.teardown.concat([
|
|
|
|
async () => {
|
|
|
|
return await app.terminate()
|
|
|
|
},
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.run(async () => {
|
|
|
|
return await run()
|
|
|
|
})
|
|
|
|
} catch (error) {
|
|
|
|
process.exitCode = 1
|
|
|
|
await prettyPrintError(error)
|
|
|
|
}
|