Skip to content

Commit efd8535

Browse files
boneskullclaude
andcommitted
test(integration): add fixtures for directory-paths tests
Add nested directory and extension test fixtures: - fixture/nested/suite1.bench.js and nested/deep/suite2.bench.js - fixture/extension-test.bench.mts and extension-test.bench.cts Update directory-paths.test.ts to use fixtures where possible. Note: The default pattern test still needs dynamic files since it tests discovery relative to cwd. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4cfba7e commit efd8535

File tree

6 files changed

+79
-29
lines changed

6 files changed

+79
-29
lines changed

test/integration/directory-paths.test.ts

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { expect } from 'bupkis';
22
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
33
import { tmpdir } from 'node:os';
4-
import { join } from 'node:path';
4+
import { dirname, 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
describe('CLI directory path handling', () => {
1011
let tempDir: string;
@@ -18,19 +19,10 @@ describe('CLI directory path handling', () => {
1819
});
1920

2021
it('should find benchmark files recursively when given directory path', async () => {
21-
await mkdir(join(tempDir, 'my-benchmarks', 'nested'), { recursive: true });
22-
await writeFile(
23-
join(tempDir, 'my-benchmarks', 'test1.bench.js'),
24-
'export default { suites: { "Suite 1": { benchmarks: { "test": { fn: () => 1 } } } } };',
25-
);
26-
await writeFile(
27-
join(tempDir, 'my-benchmarks', 'nested', 'test2.bench.js'),
28-
'export default { suites: { "Suite 2": { benchmarks: { "test": { fn: () => 1 } } } } };',
29-
);
30-
22+
// Use fixture nested directory which contains Suite 1 and Suite 2 (in deep/)
3123
const result = await runCommand(
32-
['run', join(tempDir, 'my-benchmarks'), '--iterations', '1'],
33-
tempDir,
24+
['run', fixtures.nestedDir, '--iterations', '1'],
25+
dirname(fixtures.nestedDir),
3426
);
3527

3628
expect(result.exitCode, 'to equal', 0);
@@ -39,6 +31,9 @@ describe('CLI directory path handling', () => {
3931
});
4032

4133
it('should use sensible defaults when no paths provided', async () => {
34+
// This test requires specific directory structure relative to cwd
35+
// so we need to create files dynamically
36+
4237
// Top-level file (should NOT be found with default pattern bench/**/*.bench.*)
4338
await writeFile(
4439
join(tempDir, 'top.bench.js'),
@@ -68,20 +63,16 @@ describe('CLI directory path handling', () => {
6863
});
6964

7065
it('should support all extensions including .cts and .mts', async () => {
71-
await mkdir(join(tempDir, 'benchmarks'), { recursive: true });
72-
73-
await writeFile(
74-
join(tempDir, 'benchmarks', 'test.bench.mts'),
75-
'export default { suites: { "MTS": { benchmarks: { "test": { fn: () => 1 } } } } };',
76-
);
77-
await writeFile(
78-
join(tempDir, 'benchmarks', 'test.bench.cts'),
79-
'export default { suites: { "CTS": { benchmarks: { "test": { fn: () => 1 } } } } };',
80-
);
81-
66+
// Use fixture directory containing .mts and .cts files
8267
const result = await runCommand(
83-
['run', join(tempDir, 'benchmarks'), '--iterations', '1'],
84-
tempDir,
68+
[
69+
'run',
70+
fixtures.extensionMts,
71+
fixtures.extensionCts,
72+
'--iterations',
73+
'1',
74+
],
75+
dirname(fixtures.extensionMts),
8576
);
8677

8778
expect(result.exitCode, 'to equal', 0);

test/integration/fixture-paths.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const fixtures = {
2626
// Specialized
2727
/** Array.push/unshift benchmarks */
2828
arrayOperations: join(FIXTURE_DIR, 'array-operations.bench.js'),
29+
2930
/** Async operations (Promise.resolve) */
3031
asyncOperations: join(FIXTURE_DIR, 'async-operations.bench.js'),
3132
// Baseline command tests
@@ -34,11 +35,15 @@ export const fixtures = {
3435
// Configuration tests
3536
/** Benchmark for configuration file tests */
3637
configTest: join(FIXTURE_DIR, 'config-test.bench.js'),
37-
3838
/** CSV reporter tests */
3939
csvTasks: join(FIXTURE_DIR, 'csv-tasks.bench.js'),
4040
/** Task that throws with specific error message */
4141
errorThrowing: join(FIXTURE_DIR, 'error-throwing.bench.js'),
42+
/** Extension test - .cts format */
43+
extensionCts: join(FIXTURE_DIR, 'extension-test.bench.cts'),
44+
45+
/** Extension test - .mts format */
46+
extensionMts: join(FIXTURE_DIR, 'extension-test.bench.mts'),
4247
// Error scenarios
4348
/** Task that throws an error */
4449
failing: join(FIXTURE_DIR, 'failing.bench.js'),
@@ -48,29 +53,35 @@ export const fixtures = {
4853
historyDetailed: join(FIXTURE_DIR, 'history-detailed.bench.js'),
4954
/** Performance suite for detailed history comparison */
5055
historyPerformance: join(FIXTURE_DIR, 'history-performance.bench.js'),
51-
5256
// History viewing tests
5357
/** Simple benchmark for history tests */
5458
historySimple: join(FIXTURE_DIR, 'history-simple.bench.js'),
5559

5660
/** Benchmark for history trends tests */
5761
historyTrends: join(FIXTURE_DIR, 'history-trends.bench.js'),
62+
5863
// Reporter tests
5964
/** Human reporter output tests */
6065
humanOutput: join(FIXTURE_DIR, 'human-output.bench.js'),
6166
/** Benchmark with inline config for merge tests */
6267
inlineConfig: join(FIXTURE_DIR, 'inline-config.bench.js'),
6368
/** Invalid structure (`{ invalid: true }`) */
6469
invalid: join(FIXTURE_DIR, 'invalid.bench.js'),
65-
6670
/** Fast benchmark for iteration count tests */
6771
iterationCount: join(FIXTURE_DIR, 'iteration-count.bench.js'),
72+
6873
/** Measurement consistency tests */
6974
measurement: join(FIXTURE_DIR, 'measurement.bench.js'),
7075
/** Good task, failing task, another good task */
7176
mixedResults: join(FIXTURE_DIR, 'mixed-results.bench.js'),
7277
/** Three tasks (task 1/2/3) */
7378
multiTask: join(FIXTURE_DIR, 'multi-task.bench.js'),
79+
// Directory path tests
80+
/**
81+
* Nested directory containing Suite 1 and Suite 2 (deep) for recursive
82+
* discovery tests
83+
*/
84+
nestedDir: join(FIXTURE_DIR, 'nested'),
7485
// Profile command scripts (not benchmarks)
7586
/** Script with hot function for profile command testing */
7687
profileHotFunction: join(FIXTURE_DIR, 'profile-hot-function.js'),
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Extension test - .cts format. Used by: directory-paths.test.ts
3+
*/
4+
export default {
5+
suites: {
6+
CTS: {
7+
benchmarks: {
8+
test: { fn: () => 1 },
9+
},
10+
},
11+
},
12+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Extension test - .mts format. Used by: directory-paths.test.ts
3+
*/
4+
export default {
5+
suites: {
6+
MTS: {
7+
benchmarks: {
8+
test: { fn: () => 1 },
9+
},
10+
},
11+
},
12+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Nested directory test - Suite 2 (deep). Used by: directory-paths.test.ts
3+
*/
4+
export default {
5+
suites: {
6+
'Suite 2': {
7+
benchmarks: {
8+
test: { fn: () => 1 },
9+
},
10+
},
11+
},
12+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Nested directory test - Suite 1. Used by: directory-paths.test.ts
3+
*/
4+
export default {
5+
suites: {
6+
'Suite 1': {
7+
benchmarks: {
8+
test: { fn: () => 1 },
9+
},
10+
},
11+
},
12+
};

0 commit comments

Comments
 (0)