TASKS-1823 WebManager module

This commit is contained in:
Igor Martyniuk
2026-08-28 08:35:58 +00:00
parent fdb2cf3837
commit c93d8c025b
654 changed files with 26232 additions and 6075 deletions
+39 -8
View File
@@ -2,7 +2,6 @@
import { assert } from '@japa/assert'
import { apiClient } from '@japa/api-client'
import { pluginAdonisJS } from '@japa/plugin-adonisjs'
import { specReporter } from '@japa/spec-reporter'
import type { Config } from '@japa/runner/types'
import app from '@adonisjs/core/services/app'
@@ -18,22 +17,54 @@ export const plugins: Config['plugins'] = [assert(), apiClient(), pluginAdonisJS
*/
export const reporters: Config['reporters'] = {
activated: ['spec'],
list: [
{
name: 'spec',
handler: specReporter(),
},
],
}
/**
* Global setup/teardown (for ALL suites)
*
* Runs migrations against the test database (`.env.test` → adonis_test) before
* the suites and rolls them back afterwards. DB-backed specs additionally wrap
* each test in a global transaction via `testUtils.db().wrapInGlobalTransaction()`
* in their own group hooks.
*/
export const runnerHooks: Required<Pick<Config, 'setup' | 'teardown'>> = {
setup: [],
setup: [() => ensureTestDatabase(), () => testUtils.db().migrate()],
teardown: [],
}
/**
* Creates the test database on first run so a fresh checkout only needs the
* postgres container up. Guarded to `*_test` names so a misconfigured
* `.env.test` can never provision anything else.
*/
async function ensureTestDatabase() {
const { default: env } = await import('#start/env')
const database = env.get('DB_DATABASE')
if (!database.endsWith('_test')) {
throw new Error(
`Refusing to run tests against "${database}": DB_DATABASE in .env.test must end with "_test"`
)
}
const { Client } = await import('pg')
const client = new Client({
host: env.get('DB_HOST'),
port: env.get('DB_PORT'),
user: env.get('DB_USER'),
password: env.get('DB_PASSWORD'),
database: 'postgres',
})
await client.connect()
try {
const exists = await client.query('SELECT 1 FROM pg_database WHERE datname = $1', [database])
if (exists.rowCount === 0) {
await client.query(`CREATE DATABASE "${database}"`)
}
} finally {
await client.end()
}
}
/**
* Per-suite configuration (start HTTP server for HTTP tests)
*/