Skip to content

Commit

Permalink
test: remove sqlite db parent dir on clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 16, 2024
1 parent 1ae5187 commit 72787fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 0 additions & 2 deletions tests/access_tokens/token_providers/db.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ test.group('Access tokens provider | DB | create', () => {

test('throw error when user is not an instance of the associated model', async ({ assert }) => {
const db = await createDatabase()
console.log('db created')
await createTables(db)
console.log('tables created')

class User extends BaseModel {
@column({ isPrimary: true })
Expand Down
10 changes: 7 additions & 3 deletions tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { join } from 'node:path'
import timekeeper from 'timekeeper'
import { Hash } from '@adonisjs/hash'
import { configDotenv } from 'dotenv'
import { mkdir } from 'node:fs/promises'
import { mkdir, rm } from 'node:fs/promises'
import { getActiveTest } from '@japa/runner'
import { Emitter } from '@adonisjs/core/events'
import { BaseModel } from '@adonisjs/lucid/orm'
Expand Down Expand Up @@ -44,7 +44,8 @@ export async function createDatabase() {
throw new Error('Cannot use "createDatabase" outside of a Japa test')
}

await mkdir(test.context.fs.basePath)
const basePath = test.context.fs.basePath
await mkdir(basePath)

const app = new AppFactory().create(test.context.fs.baseUrl, () => {})
const logger = new LoggerFactory().create()
Expand Down Expand Up @@ -98,7 +99,10 @@ export async function createDatabase() {
emitter
)

test.cleanup(() => db.manager.closeAll())
test.cleanup(async () => {
db.manager.closeAll()
await rm(basePath, { force: true, recursive: true, maxRetries: 3 })
})
BaseModel.useAdapter(db.modelAdapter())
return db
}
Expand Down

0 comments on commit 72787fa

Please sign in to comment.