Skip to content

Commit 741d07d

Browse files
d4mationclaude
andcommitted
ENG-219: Add createTempProject helper for test isolation
Tests that modify .puprc now use isolated temp directories instead of the shared fixture directory, allowing parallel test execution. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3fb3385 commit 741d07d

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
import {
22
runPup,
3-
resetFixtures,
4-
fakeProjectDir,
3+
createTempProject,
4+
cleanupTempProjects,
55
} from '../helpers/setup.js';
66
import fs from 'fs-extra';
77
import path from 'node:path';
88

99
describe('invalid .puprc', () => {
10+
let projectDir: string;
11+
12+
beforeEach(() => {
13+
projectDir = createTempProject();
14+
});
15+
1016
afterEach(() => {
11-
resetFixtures();
17+
cleanupTempProjects();
1218
});
1319

1420
it('should handle invalid JSON in .puprc', async () => {
15-
const puprcPath = path.join(fakeProjectDir, '.puprc');
21+
const puprcPath = path.join(projectDir, '.puprc');
1622
fs.writeFileSync(puprcPath, '{invalid json}');
1723

18-
const result = await runPup('info');
24+
const result = await runPup('info', { cwd: projectDir });
1925
// Should still run but report invalid config
20-
expect(result.stdout + result.stderr).toBeTruthy();
26+
expect(result.output).toContain('could not be parsed');
2127
});
2228
});

tests/helpers/setup.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from 'node:path';
2+
import os from 'node:os';
23
import { execFile } from 'node:child_process';
34
import fs from 'fs-extra';
45

@@ -10,6 +11,7 @@ export const fakeProjectWithTbdsDir = path.resolve(fixturesDir, 'fake-project-wi
1011
export const cliPath = path.resolve(pupRoot, 'dist', 'cli.js');
1112

1213
const tempFiles: string[] = [];
14+
const tempDirs: string[] = [];
1315

1416
export function getDefaultPuprc(): Record<string, unknown> {
1517
return {
@@ -85,6 +87,38 @@ export function runPup(
8587
});
8688
}
8789

90+
/**
91+
* Creates an isolated copy of a fixture directory in a temp location.
92+
*
93+
* @since TBD
94+
*
95+
* @param {string} fixture - The fixture directory name to copy (e.g. 'fake-project').
96+
*
97+
* @returns {string} The path to the isolated temp directory.
98+
*/
99+
export function createTempProject(fixture = 'fake-project'): string {
100+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), `pup-test-${fixture}-`));
101+
fs.copySync(path.resolve(fixturesDir, fixture), tmpDir);
102+
tempDirs.push(tmpDir);
103+
return tmpDir;
104+
}
105+
106+
/**
107+
* Removes all temp directories created by createTempProject.
108+
*
109+
* @since TBD
110+
*
111+
* @returns {void}
112+
*/
113+
export function cleanupTempProjects(): void {
114+
for (const dir of tempDirs) {
115+
if (fs.existsSync(dir)) {
116+
fs.removeSync(dir);
117+
}
118+
}
119+
tempDirs.length = 0;
120+
}
121+
88122
export function resetFixtures(): void {
89123
// Remove any .puprc files we wrote
90124
for (const f of tempFiles) {

0 commit comments

Comments
 (0)