From 72787fa4b28c8985348e793e150371f26b6df210 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Mon, 16 Dec 2024 23:57:20 +0530 Subject: [PATCH] test: remove sqlite db parent dir on clean up --- tests/access_tokens/token_providers/db.spec.ts | 2 -- tests/helpers.ts | 10 +++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/access_tokens/token_providers/db.spec.ts b/tests/access_tokens/token_providers/db.spec.ts index b5ed7bc..c41afb9 100644 --- a/tests/access_tokens/token_providers/db.spec.ts +++ b/tests/access_tokens/token_providers/db.spec.ts @@ -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 }) diff --git a/tests/helpers.ts b/tests/helpers.ts index d2648fa..933e47d 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -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' @@ -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() @@ -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 }