Skip to content

Commit

Permalink
test(seeds): new environment config
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainLanz committed Jun 23, 2022
1 parent 6bfe2a5 commit 454f5cf
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/seeds/seeds-runner.spec.ts
Expand Up @@ -96,4 +96,62 @@ test.group('Seeds Runner', (group) => {
delete process.env.NODE_ENV
await db.manager.closeAll()
})

test('mark file as ignored when "environment = production" and not running in production mode', async ({
assert,
}) => {
process.env.NODE_ENV = 'development'

const app = await setupApplication()
const db = getDb(app)
const runner = new SeedsRunner(db, app)

await fs.add(
'database/seeders/User.ts',
`export default class FooSeeder {
public static invoked = false
public static environment = ['production']
run () {
(this.constructor as any).invoked = true
}
}`
)

const files = await runner.getList()
const report = await runner.run(files[0])
assert.equal(report.status, 'ignored')

delete process.env.NODE_ENV
await db.manager.closeAll()
})

test('mark file as ignored when "environment = development" and not running in development mode', async ({
assert,
}) => {
process.env.NODE_ENV = 'production'

const app = await setupApplication()
const db = getDb(app)
const runner = new SeedsRunner(db, app)

await fs.add(
'database/seeders/User.ts',
`export default class FooSeeder {
public static invoked = false
public static environment = ['development']
run () {
(this.constructor as any).invoked = true
}
}`
)

const files = await runner.getList()
const report = await runner.run(files[0])
assert.equal(report.status, 'ignored')

delete process.env.NODE_ENV
await db.manager.closeAll()
})
})

0 comments on commit 454f5cf

Please sign in to comment.