Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions playground/config/env/test/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 16 additions & 12 deletions playground/tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,29 +14,31 @@ 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;
}

/**
* Closes strapi after testing
*/
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;
}