Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions packages/testtools/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import prismaPlugin from 'zenstack/plugins/prisma';
*/
export const FILE_SPLITTER = '#FILE_SPLITTER#';

const tempDirs: string[] = [];
tmp.setGracefulCleanup();

export type FullDbClientContract = CrudContract & {
Expand Down Expand Up @@ -254,6 +255,7 @@ export function createProjectAndCompile(schema: string, options: SchemaLoadOptio
let projectDir = opt.projectDir;
if (!projectDir) {
const r = tmp.dirSync({ unsafeCleanup: true });
tempDirs.push(r.name);
projectDir = r.name;
}

Expand Down Expand Up @@ -423,3 +425,17 @@ function loadModule(module: string, basePath: string): any {
const modulePath = require.resolve(module, { paths: [basePath] });
return require(modulePath);
}

export function cleanUpTemps() {
tempDirs.forEach((d) => {
console.log('Cleaning up temp dir:', d);
if (fs.existsSync(d)) {
try {
fs.rmSync(d, { recursive: true, force: true });
} catch {
// ignore
}
}
});
tempDirs.splice(0, tempDirs.length);
}
5 changes: 5 additions & 0 deletions tests/integration/test-setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cleanUpTemps } from '@zenstackhq/testtools';
import {
toBeRejectedByPolicy,
toBeNotFound,
Expand All @@ -15,3 +16,7 @@ expect.extend({
toResolveNull,
toBeRejectedWithCode,
});

afterAll(() => {
cleanUpTemps();
});
5 changes: 5 additions & 0 deletions tests/regression/test-setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cleanUpTemps } from '@zenstackhq/testtools';
import {
toBeNotFound,
toBeRejectedByPolicy,
Expand All @@ -15,3 +16,7 @@ expect.extend({
toResolveNull,
toBeRejectedWithCode,
});

afterAll(() => {
cleanUpTemps();
});
Loading