Open AlirezaEthDev opened 1 week ago
@AlirezaEthDev I'm having the same issue for an Adonisjs functional test:
import { test } from '@japa/runner'
// import { UserFactory } from '#database/factories/user_factory'
import { Sports, TournamentFormats } from '#types/tournament'
import ace from '@adonisjs/core/services/ace'
import User from '#models/user'
test.group('Tournament store', async (group) => {
group.setup(async () => {
await ace.exec('db:mytruncate', [])
})
const userData = {
username: 'username23',
firstName: 'First',
lastName: 'Last',
email: 'some@example.com',
password: 'mypassword',
}
// const user = await UserFactory.create()
const user = await User.create(userData)
const storeData = {
name: 'Liga ABC',
sport: Sports.Basketball,
format: TournamentFormats.RegularSeason,
areInscriptionsOpen: true,
}
test('example test', async ({ assert, client }) => {
const r = await client.post('/tournaments').json(storeData).loginAs(user)
r.assertStatus(201)
assert.include(r.body(), storeData)
})
})
I'm getting:
Error: Cannot import japa test file directly. It must be imported by calling the "japa.run" method
at <anonymous> tests/functional/tournament/store.spec.ts:29
27| }
28|
❯ 29| test('example test', async ({ assert, client }) => {
30| const r = await client.post('/tournaments').json(storeData).loginAs(user)
31| r.assertStatus(201)
⁃ Validator.ensureIsInPlanningPhase
node_modules/@japa/runner/src/validator.ts:33
⁃ test
node_modules/@japa/runner/index.ts:67
I noticed it throws the error whenever I import the User
model or UserFactory
. This is very odd, since I have another Adonis project where I do the same but don't get this error.
I use
test
method in a module (calledtrade.js
) that is included in the main test code (that isfunctional.spec.js
and is intests\functional
folder of Japa project's directory). That's this:In there
./testRequests.js
is a http client. The below isfunctional.spec.js
that includestrade.js
:And this is
bin\test.js
file:But when I try it with
node bin\test.js functional
, after six iterations oftrad.trade()
offunctional.spec,js
, this error thrown: