-
The configure hook on the suite property doesn't execute before the files. this is my configuration: import 'reflect-metadata'
import sourceMapSupport from 'source-map-support'
import getPort from 'get-port'
import execa from 'execa'
import { assert } from '@japa/assert'
import { specReporter } from '@japa/spec-reporter'
import { processCliArgs, configure, run } from '@japa/runner'
import { join } from 'path'
import type { HttpServer } from '@adonisjs/core/build/src/Ignitor/HttpServer'
process.env.ADONIS_ACE_CWD = join(__dirname)
sourceMapSupport.install({ handleUncaughtExceptions: false })
async function createServer() {
const { Ignitor } = await import('@adonisjs/core/build/src/Ignitor')
process.env.PORT = String(await getPort())
return new Ignitor(join(__dirname)).httpServer()
}
async function setupFunctionalSuite() {
let server: HttpServer;
try {
execa.node('ace', ['migration:fresh'], { stdio: 'inherit' })
server = await createServer()
await server.start()
} catch (error) {
console.log(error)
}
return async () => await server.close()
}
configure({
...processCliArgs(process.argv.slice(2)),
...{
suites: [
{
name: 'functional',
files: ['japa/functional/**/*.fixture.ts'],
configure(suite) {
suite.setup(async () => await setupFunctionalSuite())
},
}
],
plugins: [assert()],
reporters: [specReporter()],
importer: (filePath) => import(filePath)
},
})
run() this is a simple test that does nothing, it imports a model, only to show the problem import { test } from '@japa/runner'
import Lancamento from 'App/lancamento/Lancamento'
test('Japa Test').run(async ({ assert }) => {
console.log(await Lancamento.all())
}) I can't import nothing that uses alias or ioc because the httpServer has not started
How can i make the configureSuite execute before? |
Beta Was this translation helpful? Give feedback.
Answered by
guntribam
Mar 20, 2022
Replies: 2 comments
-
@RomainLanz @thetutlage please help ... |
Beta Was this translation helpful? Give feedback.
0 replies
-
Solved. The correct way is to use the runner setup before the configureSuite setup import 'reflect-metadata'
import sourceMapSupport from 'source-map-support'
import execa from 'execa'
import { assert } from '@japa/assert'
import { specReporter } from '@japa/spec-reporter'
import { processCliArgs, configure, run } from '@japa/runner'
import { join } from 'path'
import type { HttpServer } from '@adonisjs/core/build/src/Ignitor/HttpServer'
import { Ignitor } from '@adonisjs/core/build/src/Ignitor'
sourceMapSupport.install({ handleUncaughtExceptions: false })
async function setupServer() {
let server: HttpServer;
try {
server = new Ignitor(join(__dirname, '..')).httpServer()
await server.start()
} catch (error) {
console.log("Erro ao subir o servidor de testes", error)
}
return async () => await server.close()
}
async function initTestBaseState() {
const Database = (await import('@ioc:Adonis/Lucid/Database')).default;
const { initCacheBaseState, resetCache } = (await import('Database/samples/SamplesUtils'));
try {
await execa.node('ace', ['migration:fresh', '--seed'], { stdio: 'inherit' });
initCacheBaseState();
await Database.beginGlobalTransaction()
} catch (error) {
console.log("Erro ao rodar migration:fresh", error)
}
return async () => {
await Database.commitGlobalTransaction()
resetCache();
}
}
async function restoreTestBaseState() {
const Database = (await import('@ioc:Adonis/Lucid/Database')).default;
const { restoreCacheBaseState } = (await import('Database/samples/SamplesUtils'));
await Database.rollbackGlobalTransaction()
restoreCacheBaseState();
await Database.beginGlobalTransaction()
}
configure({
...processCliArgs(process.argv.slice(2)),
...{
suites: [
{
name: 'unit',
files: ['japa/unit/**/*.fixture.ts'],
},
{
name: 'acceptance',
files: ['japa/acceptance/**/*.fixture.ts'],
configure: (suite) => {
suite.setup(initTestBaseState)
suite.onTest(test => test.setup(restoreTestBaseState))
}
}
],
setup: [setupServer],
plugins: [assert()],
reporters: [specReporter()],
importer: (filePath) => import(filePath)
},
})
run() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
guntribam
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solved.
The correct way is to use the runner setup before the configureSuite setup