backend-test-utils: skip mock directory cleanup in CI

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-10-02 19:01:10 +02:00
parent b7ae05d5b8
commit da0ef5a98f
2 changed files with 8 additions and 24 deletions
@@ -269,28 +269,6 @@ describe('createMockDirectory', () => {
);
});
describe('cleanup', () => {
let cleanupMockDir: MockDirectory;
describe('inner', () => {
cleanupMockDir = createMockDirectory();
it('should populate a directory', () => {
cleanupMockDir.setContent({
'a.txt': 'a',
});
expect(cleanupMockDir.content()).toEqual({
'a.txt': 'a',
});
});
});
it('should clean up after itself automatically', () => {
expect(cleanupMockDir.content()).toBeUndefined();
});
});
describe('tmpdir mock', () => {
let tmpDirMock: MockDirectory;
@@ -351,14 +351,20 @@ export function createMockDirectory(
os.tmpdir = () => mocker.path;
}
process.on('beforeExit', mocker.remove);
// In CI we expect there to be no need to clean up temporary directories
const needsCleanup = !process.env.CI;
if (needsCleanup) {
process.on('beforeExit', mocker.remove);
}
try {
afterAll(() => {
if (origTmpdir) {
os.tmpdir = origTmpdir;
}
mocker.remove();
if (needsCleanup) {
mocker.remove();
}
});
} catch {
/* ignore */