Skip to content

Commit 4cfba7e

Browse files
boneskullclaude
andcommitted
test(integration): extract benchmark fixtures from dynamic file creation
Refactors integration tests to use static fixture files instead of dynamically writing benchmark files to temp directories at runtime. Changes: - Add test/integration/fixture/ directory with 35 static benchmark fixtures - Add test/integration/fixture-paths.ts helper module with typed fixture paths - Update integration tests to import fixtures instead of using writeFile - Tests that need output files still use temp dirs, but only for output This improves test reliability and makes benchmark definitions easier to maintain and review. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d49bd84 commit 4cfba7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1459
-1886
lines changed

test/integration/baseline-commands.test.ts

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,23 @@
11
import { expect } from 'bupkis';
2-
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
2+
import { mkdir, mkdtemp, rm } from 'node:fs/promises';
33
import { tmpdir } from 'node:os';
44
import { join } from 'node:path';
55
import { afterEach, beforeEach, describe, it } from 'node:test';
66

77
import { runCommand } from '../util.js';
8+
import { fixtures } from './fixture-paths.js';
89

910
/**
1011
* Integration tests for baseline management commands
1112
*/
1213

1314
describe('Baseline management commands', () => {
15+
// Temp dir needed for baseline storage
1416
let tempDir: string;
15-
let benchFile: string;
1617

1718
beforeEach(async () => {
18-
tempDir = await mkdtemp(join(tmpdir(), 'modestbench-baseline-test-'));
19+
tempDir = await mkdtemp(join(tmpdir(), 'modestbench-baseline-'));
1920
await mkdir(join(tempDir, '.modestbench'), { recursive: true });
20-
21-
// Create a simple benchmark file
22-
benchFile = join(tempDir, 'test.bench.js');
23-
await writeFile(
24-
benchFile,
25-
`
26-
export default {
27-
suites: {
28-
'Test Suite': {
29-
benchmarks: {
30-
'fast task': { fn: () => 1 + 1 },
31-
'slow task': { fn: () => { let x = 0; for (let i = 0; i < 1000; i++) x += i; return x; } }
32-
}
33-
}
34-
}
35-
};
36-
`,
37-
);
3821
});
3922

4023
afterEach(async () => {
@@ -44,7 +27,10 @@ describe('Baseline management commands', () => {
4427
describe('baseline set command', () => {
4528
it('should save most recent run as baseline', async () => {
4629
// Run benchmark to create history
47-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
30+
await runCommand(
31+
['run', fixtures.baselineTest, '--iterations', '10'],
32+
tempDir,
33+
);
4834

4935
// Save as baseline
5036
const result = await runCommand(
@@ -57,7 +43,10 @@ describe('Baseline management commands', () => {
5743
});
5844

5945
it('should accept --commit option', async () => {
60-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
46+
await runCommand(
47+
['run', fixtures.baselineTest, '--iterations', '10'],
48+
tempDir,
49+
);
6150

6251
const result = await runCommand(
6352
[
@@ -74,7 +63,10 @@ describe('Baseline management commands', () => {
7463
});
7564

7665
it('should accept --branch option', async () => {
77-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
66+
await runCommand(
67+
['run', fixtures.baselineTest, '--iterations', '10'],
68+
tempDir,
69+
);
7870

7971
const result = await runCommand(
8072
['baseline', 'set', 'test-baseline', '--branch', 'main'],
@@ -85,7 +77,10 @@ describe('Baseline management commands', () => {
8577
});
8678

8779
it('should accept --default flag', async () => {
88-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
80+
await runCommand(
81+
['run', fixtures.baselineTest, '--iterations', '10'],
82+
tempDir,
83+
);
8984

9085
const result = await runCommand(
9186
['baseline', 'set', 'test-baseline', '--default'],
@@ -98,7 +93,7 @@ describe('Baseline management commands', () => {
9893

9994
it('should accept --run-id option', async () => {
10095
const runResult = await runCommand(
101-
['run', benchFile, '--iterations', '10'],
96+
['run', fixtures.baselineTest, '--iterations', '10'],
10297
tempDir,
10398
);
10499

@@ -138,10 +133,16 @@ describe('Baseline management commands', () => {
138133
describe('baseline list command', () => {
139134
it('should list all baselines', async () => {
140135
// Create history and baselines
141-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
136+
await runCommand(
137+
['run', fixtures.baselineTest, '--iterations', '10'],
138+
tempDir,
139+
);
142140
await runCommand(['baseline', 'set', 'baseline1'], tempDir);
143141

144-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
142+
await runCommand(
143+
['run', fixtures.baselineTest, '--iterations', '10'],
144+
tempDir,
145+
);
145146
await runCommand(['baseline', 'set', 'baseline2'], tempDir);
146147

147148
const result = await runCommand(['baseline', 'list'], tempDir);
@@ -159,7 +160,10 @@ describe('Baseline management commands', () => {
159160
});
160161

161162
it('should indicate default baseline', async () => {
162-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
163+
await runCommand(
164+
['run', fixtures.baselineTest, '--iterations', '10'],
165+
tempDir,
166+
);
163167
await runCommand(
164168
['baseline', 'set', 'default-baseline', '--default'],
165169
tempDir,
@@ -174,7 +178,10 @@ describe('Baseline management commands', () => {
174178

175179
describe('baseline show command', () => {
176180
it('should show baseline details', async () => {
177-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
181+
await runCommand(
182+
['run', fixtures.baselineTest, '--iterations', '10'],
183+
tempDir,
184+
);
178185
await runCommand(['baseline', 'set', 'test-baseline'], tempDir);
179186

180187
const result = await runCommand(
@@ -200,7 +207,10 @@ describe('Baseline management commands', () => {
200207

201208
describe('baseline delete command', () => {
202209
it('should delete a baseline', async () => {
203-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
210+
await runCommand(
211+
['run', fixtures.baselineTest, '--iterations', '10'],
212+
tempDir,
213+
);
204214
await runCommand(['baseline', 'set', 'test-baseline'], tempDir);
205215

206216
const result = await runCommand(
@@ -231,7 +241,10 @@ describe('Baseline management commands', () => {
231241
it('should analyze recent runs and suggest budgets', async () => {
232242
// Run benchmarks multiple times to create history
233243
for (let i = 0; i < 5; i++) {
234-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
244+
await runCommand(
245+
['run', fixtures.baselineTest, '--iterations', '10'],
246+
tempDir,
247+
);
235248
}
236249

237250
const result = await runCommand(['baseline', 'analyze'], tempDir);
@@ -242,7 +255,10 @@ describe('Baseline management commands', () => {
242255

243256
it('should accept --runs option', async () => {
244257
for (let i = 0; i < 3; i++) {
245-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
258+
await runCommand(
259+
['run', fixtures.baselineTest, '--iterations', '10'],
260+
tempDir,
261+
);
246262
}
247263

248264
const result = await runCommand(
@@ -255,7 +271,10 @@ describe('Baseline management commands', () => {
255271

256272
it('should accept --confidence option', async () => {
257273
for (let i = 0; i < 3; i++) {
258-
await runCommand(['run', benchFile, '--iterations', '10'], tempDir);
274+
await runCommand(
275+
['run', fixtures.baselineTest, '--iterations', '10'],
276+
tempDir,
277+
);
259278
}
260279

261280
const result = await runCommand(

0 commit comments

Comments
 (0)