diff --git a/playground/config/env/test/database.ts b/playground/config/env/test/database.ts index d8812c29..042b49ff 100644 --- a/playground/config/env/test/database.ts +++ b/playground/config/env/test/database.ts @@ -2,14 +2,17 @@ import path from 'path'; export default ({ env }) => ({ connection: { - client: "sqlite", + client: 'sqlite', connection: { filename: path.join( __dirname, + // Get out of config/env/test + '..', + '..', '..', // We need to go back once more to get out of the dist folder '..', - env("DATABASE_TEST_FILENAME", ".tmp/test.db"), + env('DATABASE_TEST_FILENAME', '.tmp/test.db'), ), }, useNullAsDefault: true, diff --git a/playground/tests/helpers.ts b/playground/tests/helpers.ts index c466cdcb..890af7e6 100644 --- a/playground/tests/helpers.ts +++ b/playground/tests/helpers.ts @@ -1,7 +1,9 @@ +import fs from 'node:fs'; +import assert from 'node:assert'; import { createStrapi } from '@strapi/strapi'; -import fs, { PathLike } from 'fs'; +import type { Core } from '@strapi/types'; -let instance; +let instance: Core.Strapi | undefined; /** * Setups strapi for futher testing @@ -12,12 +14,10 @@ export async function setupStrapi() { appDir: './playground', distDir: './playground/dist', }).load(); + strapi.server.mount(); instance = strapi; // strapi is global now - - await instance.server.mount(); } - return instance; } /** @@ -25,16 +25,20 @@ export async function setupStrapi() { */ export async function stopStrapi() { if (instance) { - await instance.server.httpServer.close(); - await instance.db.connection.destroy(); - instance.destroy(); - const tmpDbFile = strapi.config.get( + const tmpDbFile = instance.config.get( 'database.connection.connection.filename', ); - if (fs.existsSync(tmpDbFile as PathLike)) { - fs.unlinkSync(tmpDbFile as PathLike); + assert(typeof tmpDbFile === 'string'); + + instance.server.httpServer.close(); + await instance.db.connection.destroy(); + await instance.destroy(); + + if (fs.existsSync(tmpDbFile)) { + fs.unlinkSync(tmpDbFile); } + + instance = undefined; } - return instance; }