Skip to content
Open
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
16 changes: 16 additions & 0 deletions test/isolateStorageDir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';

import { afterAll } from 'vitest';

// Vitest runs test files in parallel worker processes, but every Configuration
// defaults to the same cwd-relative `./storage` dir — one file's purge-on-init
// races against another file's reads/writes (ENOENT from the fs backend), so
// this setup file (wired in vitest.config.mts) points each file at its own dir.
const storageDir = await mkdtemp(join(tmpdir(), 'apify-sdk-test-storage-'));
process.env.CRAWLEE_STORAGE_DIR = storageDir;

afterAll(async () => {
await rm(storageDir, { recursive: true, force: true });
});
3 changes: 3 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export default defineConfig({
},
clearMocks: true,
restoreMocks: true,
// Give each test file its own storage dir - parallel workers must not
// share (and purge) the same on-disk `./storage`.
setupFiles: ['./test/isolateStorageDir.ts'],
testTimeout: 60_000,
hookTimeout: 60_000,
alias: [
Expand Down
Loading