Skip to content

Commit 3e04bf8

Browse files
boneskullclaude
andcommitted
test(integration): update bail.test.ts to use fixtures
Remove temp dir creation - use existing failing.bench.js and success.bench.js fixtures. Update assertions to check for suite names instead of filenames. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent efd8535 commit 3e04bf8

File tree

1 file changed

+24
-115
lines changed

1 file changed

+24
-115
lines changed

test/integration/bail.test.ts

Lines changed: 24 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,62 @@
11
import { expect } from 'bupkis';
2-
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
3-
import { tmpdir } from 'node:os';
4-
import { join } from 'node:path';
5-
import { afterEach, beforeEach, describe, it } from 'node:test';
2+
import { describe, it } from 'node:test';
63

74
import { runCommand } from '../util.js';
5+
import { fixtures } from './fixture-paths.js';
86

97
/**
108
* Integration tests for --bail flag functionality. The bail flag should stop
119
* execution on the first benchmark failure
1210
*/
1311

1412
describe('Bail flag (--bail)', () => {
15-
let tempDir: string;
16-
17-
beforeEach(async () => {
18-
tempDir = await mkdtemp(join(tmpdir(), 'modestbench-test-'));
19-
await mkdir(join(tempDir, 'benchmarks'), { recursive: true });
20-
});
21-
22-
afterEach(async () => {
23-
await rm(tempDir, { force: true, recursive: true });
24-
});
25-
2613
it('should stop execution after first failing benchmark', async () => {
27-
// Create first benchmark file that will fail
28-
const failingBench = join(tempDir, 'benchmarks', '1-failing.bench.js');
29-
await writeFile(
30-
failingBench,
31-
`
32-
export default {
33-
suites: {
34-
'Failing Suite': {
35-
benchmarks: {
36-
'failing task': {
37-
fn: () => {
38-
throw new Error('Intentional failure');
39-
}
40-
}
41-
}
42-
}
43-
}
44-
};
45-
`,
46-
);
47-
48-
// Create second benchmark file that should NOT run
49-
const successBench = join(tempDir, 'benchmarks', '2-success.bench.js');
50-
await writeFile(
51-
successBench,
52-
`
53-
export default {
54-
suites: {
55-
'Success Suite': {
56-
benchmarks: {
57-
'success task': {
58-
fn: () => 1
59-
}
60-
}
61-
}
62-
}
63-
};
64-
`,
65-
);
66-
67-
// Run with --bail flag
68-
const result = await runCommand(
69-
[
70-
'run',
71-
join(tempDir, 'benchmarks', '*.bench.js'),
72-
'--bail',
73-
'--reporter',
74-
'human',
75-
],
76-
tempDir,
77-
);
14+
// Run with --bail flag - failing fixture runs first (alphabetically)
15+
// failing.bench.js comes before success.bench.js
16+
const result = await runCommand([
17+
'run',
18+
fixtures.failing,
19+
fixtures.success,
20+
'--bail',
21+
'--reporter',
22+
'human',
23+
]);
7824

7925
// Should exit with non-zero code due to failure
8026
expect(result.exitCode, 'to be greater than', 0);
8127

8228
const combinedOutput = result.stdout + result.stderr;
8329

8430
// Verify first benchmark ran and failed
85-
expect(combinedOutput, 'to match', /1-failing\.bench\.js/);
31+
expect(combinedOutput, 'to match', /Failing Suite/);
8632
expect(combinedOutput, 'to match', /failing task/);
8733
expect(combinedOutput, 'to match', /Intentional failure/);
8834

89-
// Second benchmark file should NOT appear in output when --bail is used
35+
// Second benchmark suite should NOT appear in output when --bail is used
9036
// (this is the key assertion that will pass once bail is implemented)
91-
expect(combinedOutput, 'not to match', /2-success\.bench\.js/);
37+
expect(combinedOutput, 'not to match', /Success Suite/);
9238
expect(combinedOutput, 'not to match', /success task/);
9339
});
9440

9541
it('should run all benchmarks without --bail flag (control)', async () => {
96-
// Create first benchmark file that will fail
97-
const failingBench = join(tempDir, 'benchmarks', '1-failing.bench.js');
98-
await writeFile(
99-
failingBench,
100-
`
101-
export default {
102-
suites: {
103-
'Failing Suite': {
104-
benchmarks: {
105-
'failing task': {
106-
fn: () => {
107-
throw new Error('Intentional failure');
108-
}
109-
}
110-
}
111-
}
112-
}
113-
};
114-
`,
115-
);
116-
117-
// Create second benchmark file
118-
const successBench = join(tempDir, 'benchmarks', '2-success.bench.js');
119-
await writeFile(
120-
successBench,
121-
`
122-
export default {
123-
suites: {
124-
'Success Suite': {
125-
benchmarks: {
126-
'success task': {
127-
fn: () => 1
128-
}
129-
}
130-
}
131-
}
132-
};
133-
`,
134-
);
135-
13642
// Run WITHOUT --bail flag - both benchmarks should run
137-
const result = await runCommand(
138-
['run', join(tempDir, 'benchmarks', '*.bench.js'), '--reporter', 'human'],
139-
tempDir,
140-
);
43+
const result = await runCommand([
44+
'run',
45+
fixtures.failing,
46+
fixtures.success,
47+
'--reporter',
48+
'human',
49+
]);
14150

14251
// Should exit with non-zero code due to failure
14352
expect(result.exitCode, 'to be greater than', 0);
14453

14554
const combinedOutput = result.stdout + result.stderr;
14655

14756
// Both benchmarks should appear in output (default behavior without --bail)
148-
expect(combinedOutput, 'to match', /1-failing\.bench\.js/);
57+
expect(combinedOutput, 'to match', /Failing Suite/);
14958
expect(combinedOutput, 'to match', /failing task/);
150-
expect(combinedOutput, 'to match', /2-success\.bench\.js/);
59+
expect(combinedOutput, 'to match', /Success Suite/);
15160
expect(combinedOutput, 'to match', /success task/);
15261
});
15362
});

0 commit comments

Comments
 (0)