Skip to content

Commit a393236

Browse files
committed
fix(init): init templates now use proper default .modestbench/ dir for output
1 parent 38e7cef commit a393236

8 files changed

Lines changed: 65 additions & 34 deletions

File tree

modestbench.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"version": "1.0.0",
88
"description": "Demonstration benchmarks for ModestBench framework"
99
},
10-
"outputDir": "./benchmark-results",
10+
"outputDir": "./.modestbench",
1111
"pattern": "examples/**/*.bench.{js,ts}",
1212
"quiet": false,
1313
"reporterConfig": {

src/cli/commands/init.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import { createInterface } from 'node:readline';
1717

1818
import type { CliContext } from '../index.js';
1919

20+
import {
21+
DEFAULT_BENCHMARK_DIR,
22+
DEFAULT_OUTPUT_DIR,
23+
SITE_URL,
24+
} from '../../constants.js';
2025
import {
2126
InvalidArgumentError,
2227
UnsupportedConfigFormatError,
@@ -43,40 +48,44 @@ const PROJECT_TEMPLATES = {
4348
advanced: {
4449
configOptions: {
4550
iterations: 1000,
46-
outputDir: '.modestbench',
47-
pattern: 'bench/**/*.bench.{js,ts}',
51+
outputDir: DEFAULT_OUTPUT_DIR,
52+
pattern: `${DEFAULT_BENCHMARK_DIR}/**/*.bench.{js,ts}`,
4853
reporters: ['human', 'json'],
4954
time: 10000,
5055
warmup: 50,
5156
},
5257
description: 'Feature-rich setup with multiple reporters and configuration',
53-
directories: ['bench', '.modestbench'],
58+
directories: [DEFAULT_BENCHMARK_DIR, DEFAULT_OUTPUT_DIR],
5459
name: 'Advanced Project',
5560
},
5661
basic: {
5762
configOptions: {
5863
iterations: 100,
59-
outputDir: '.modestbench',
60-
pattern: 'bench/**/*.bench.{js,ts}',
64+
outputDir: DEFAULT_OUTPUT_DIR,
65+
pattern: `${DEFAULT_BENCHMARK_DIR}/**/*.bench.{js,ts}`,
6166
reporters: ['human'],
6267
time: 5000,
6368
},
6469
description: 'Simple benchmark setup for small projects',
65-
directories: ['bench', '.modestbench'],
70+
directories: [DEFAULT_BENCHMARK_DIR, DEFAULT_OUTPUT_DIR],
6671
name: 'Basic Project',
6772
},
6873
library: {
6974
configOptions: {
7075
bail: false,
7176
iterations: 5000,
72-
outputDir: '.modestbench',
73-
pattern: 'bench/**/*.bench.{js,ts}',
77+
outputDir: DEFAULT_OUTPUT_DIR,
78+
pattern: `${DEFAULT_BENCHMARK_DIR}/**/*.bench.{js,ts}`,
7479
reporters: ['human', 'json'],
7580
time: 15000,
7681
warmup: 100,
7782
},
7883
description: 'Optimized for library performance testing',
79-
directories: ['bench', 'bench/suites', '.modestbench'],
84+
directories: [
85+
DEFAULT_BENCHMARK_DIR,
86+
`${DEFAULT_BENCHMARK_DIR}/suites`,
87+
DEFAULT_OUTPUT_DIR,
88+
],
8089
name: 'Library Project',
8190
},
8291
} as const;
@@ -375,7 +384,7 @@ const createAdditionalFiles = async (
375384
// Create README.md
376385
const readmeContent = `# Benchmark Project
377386
378-
This project uses [ModestBench](https://github.com/your-org/modestbench) for performance testing.
387+
This project uses [ModestBench](${SITE_URL}) for performance testing.
379388
380389
## Getting Started
381390
@@ -386,7 +395,7 @@ modestbench run
386395
387396
Run specific benchmarks:
388397
\`\`\`bash
389-
modestbench run "bench/array-*.bench.js"
398+
modestbench run "${DEFAULT_BENCHMARK_DIR}/array-*.bench.js"
390399
\`\`\`
391400
392401
View benchmark history:
@@ -400,7 +409,7 @@ See \`modestbench.config.*\` for benchmark configuration options.
400409
401410
## Writing Benchmarks
402411
403-
Create new benchmark files in the \`bench/\` directory. See the examples for the expected format.
412+
Create new benchmark files in the \`${DEFAULT_BENCHMARK_DIR}/\` directory. See the examples for the expected format.
404413
`;
405414

406415
try {
@@ -423,7 +432,7 @@ const createOrUpdateGitignore = async (
423432
options?: { quiet?: boolean; yes?: boolean },
424433
): Promise<void> => {
425434
const gitignorePath = resolve(cwd, '.gitignore');
426-
const modestbenchEntry = '.modestbench/';
435+
const modestbenchEntry = `${DEFAULT_OUTPUT_DIR}/`;
427436
const modestbenchSection = `\n# ModestBench history\n${modestbenchEntry}\n`;
428437

429438
try {
@@ -436,13 +445,13 @@ const createOrUpdateGitignore = async (
436445
}
437446

438447
if (existingContent) {
439-
// File exists, check if .modestbench/ is already present
448+
// File exists, check if ${DEFAULT_OUTPUT_DIR}/ is already present
440449
if (existingContent.includes(modestbenchEntry)) {
441450
// Already present, nothing to do
442451
return;
443452
}
444453

445-
// Append .modestbench/ entry (--yes or --quiet means auto-accept)
454+
// Append default output dir entry (--yes or --quiet means auto-accept)
446455
if (options?.yes || options?.quiet) {
447456
// Ensure content ends with newline
448457
const contentToAppend = existingContent.endsWith('\n')
@@ -464,7 +473,6 @@ build/
464473
coverage/
465474
466475
# Benchmark output
467-
benchmark-results/
468476
${modestbenchSection}`;
469477
await writeFile(gitignorePath, newContent, 'utf8');
470478
}
@@ -550,7 +558,7 @@ const createDirectories = async (
550558
* Create example benchmark files
551559
*/
552560
const createExampleBenchmarks = async (cwd: string): Promise<void> => {
553-
const benchmarksDir = resolve(cwd, 'bench');
561+
const benchmarksDir = resolve(cwd, DEFAULT_BENCHMARK_DIR);
554562

555563
for (const [name, example] of Object.entries(EXAMPLE_BENCHMARKS)) {
556564
const filePath = join(benchmarksDir, example.filename);

src/cli/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
import { bootstrap } from '../bootstrap.js';
2525
import {
2626
ABORT_TIMEOUT,
27+
DEFAULT_BENCHMARK_DIR,
2728
DEFAULT_ENGINE,
2829
DEFAULT_REPORTER,
2930
Engines,
@@ -177,7 +178,7 @@ export const main = async (
177178
yargs
178179
.positional('pattern', {
179180
array: true,
180-
defaultDescription: '(auto-discovered from bench/ directory)',
181+
defaultDescription: `(auto-discovered from ${DEFAULT_BENCHMARK_DIR} directory)`,
181182
describe:
182183
'File paths, directory paths, or glob patterns for benchmark files',
183184
type: 'string',

src/constants.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,18 @@ export const ErrorCodes = {
131131
VALIDATION_TYPE_FAILED: 'ERR_MB_VALIDATION_TYPE_FAILED',
132132
//#endregion
133133
} as const;
134+
135+
/**
136+
* Default output directory for reporters, history, cache, etc.
137+
*/
138+
export const DEFAULT_OUTPUT_DIR = './.modestbench';
139+
140+
/**
141+
* Default directory containing `*.bench.*` files
142+
*/
143+
export const DEFAULT_BENCHMARK_DIR = 'bench';
144+
145+
/**
146+
* URL of the site
147+
*/
148+
export const SITE_URL = 'https://modestbench.dev';

src/errors/base.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
* documentation URLs, and consistent error display.
66
*/
77

8+
import { SITE_URL } from '../constants.js';
9+
810
/**
911
* Base URL for error documentation
1012
*/
11-
const ERROR_DOC_BASE_URL = 'https://modestbench.dev/reference/errors';
13+
const ERROR_DOC_BASE_URL = `${SITE_URL}/reference/errors`;
1214

1315
/**
1416
* Abstract base class for ModestBench aggregate errors

src/services/config-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
} from '../types/index.js';
2020

2121
import { safeParseConfig } from '../config/schema.js';
22-
import { ErrorCodes } from '../constants.js';
22+
import { DEFAULT_BENCHMARK_DIR, ErrorCodes } from '../constants.js';
2323
import { ConfigLoadError, ConfigValidationError } from '../errors/index.js';
2424

2525
/**
@@ -56,7 +56,7 @@ const DEFAULT_CONFIG: ModestBenchConfig = {
5656
limitBy: 'iterations', // Default to limiting by iteration count
5757
metadata: {},
5858
outputDir: undefined, // No default output directory - reporters will use stdout unless explicitly configured
59-
pattern: 'bench/**/*.bench.{js,ts,mjs,cjs,mts,cts}', // Search bench/ directory recursively
59+
pattern: `${DEFAULT_BENCHMARK_DIR}/**/*.bench.{js,ts,mjs,cjs,mts,cts}`, // Search bench/ directory recursively
6060
quiet: false,
6161
reporterConfig: {},
6262
reporters: [getDefaultReporter()],

test/fixtures/data-builders.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type {
2525
TaskResult,
2626
} from '../../src/types/index.js';
2727

28+
import { DEFAULT_OUTPUT_DIR } from '../../src/constants.js';
2829
import { createRunId } from '../../src/utils/identifiers.js';
2930

3031
/**
@@ -62,7 +63,7 @@ export const buildMockConfig = (
6263
iterations: 100,
6364
limitBy: 'iterations',
6465
metadata: {},
65-
outputDir: './benchmark-results',
66+
outputDir: DEFAULT_OUTPUT_DIR,
6667
pattern: '**/*.bench.{js,ts}',
6768
quiet: false,
6869
reporterConfig: {},

test/integration/init-command.test.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import { tmpdir } from 'node:os';
1515
import { join } from 'node:path';
1616
import { afterEach, beforeEach, describe, it } from 'node:test';
1717

18+
import {
19+
DEFAULT_BENCHMARK_DIR,
20+
DEFAULT_OUTPUT_DIR,
21+
} from '../../src/constants.js';
1822
import { ModestBenchConfigurationManager } from '../../src/services/config-manager.js';
1923
import { runCommand } from '../util.js';
2024

@@ -290,7 +294,7 @@ describe('modestbench init command - integration', () => {
290294
await runCommand(['init', '--no-examples'], tempDir);
291295

292296
// Bench directory should exist but be empty
293-
const benchmarksDir = join(tempDir, 'bench');
297+
const benchmarksDir = join(tempDir, DEFAULT_BENCHMARK_DIR);
294298
await access(benchmarksDir); // Directory exists
295299

296300
// Example files should not exist
@@ -304,7 +308,7 @@ describe('modestbench init command - integration', () => {
304308
await runCommand(['init', '--examples'], tempDir);
305309

306310
const exampleContent = await readFile(
307-
join(tempDir, 'bench', 'example.bench.js'),
311+
join(tempDir, DEFAULT_BENCHMARK_DIR, 'example.bench.js'),
308312
'utf8',
309313
);
310314

@@ -330,7 +334,7 @@ describe('modestbench init command - integration', () => {
330334
expect(
331335
content,
332336
'to contain',
333-
'benchmark-results/',
337+
`${DEFAULT_OUTPUT_DIR}/`,
334338
'and',
335339
'to contain',
336340
'node_modules/',
@@ -343,7 +347,7 @@ describe('modestbench init command - integration', () => {
343347
const gitignorePath = join(tempDir, '.gitignore');
344348
const content = await readFile(gitignorePath, 'utf8');
345349

346-
expect(content, 'to contain', '.modestbench/');
350+
expect(content, 'to contain', `${DEFAULT_OUTPUT_DIR}/`);
347351
});
348352

349353
it('should append .modestbench/ to existing .gitignore with --yes flag', async () => {
@@ -362,7 +366,7 @@ describe('modestbench init command - integration', () => {
362366
expect(content, 'to contain', '*.log');
363367

364368
// Should contain newly added .modestbench/
365-
expect(content, 'to contain', '.modestbench/');
369+
expect(content, 'to contain', `${DEFAULT_OUTPUT_DIR}/`);
366370
expect(content, 'to contain', '# ModestBench history');
367371
});
368372

@@ -378,16 +382,16 @@ describe('modestbench init command - integration', () => {
378382
const content = await readFile(gitignorePath, 'utf8');
379383

380384
// Should contain newly added .modestbench/
381-
expect(content, 'to contain', '.modestbench/');
385+
expect(content, 'to contain', `${DEFAULT_OUTPUT_DIR}/`);
382386
});
383387

384-
it('should not duplicate .modestbench/ if already present', async () => {
388+
it(`should not duplicate ${DEFAULT_OUTPUT_DIR}/ if already present`, async () => {
385389
const gitignorePath = join(tempDir, '.gitignore');
386390

387391
// Create existing .gitignore with .modestbench/ already in it
388392
await writeFile(
389393
gitignorePath,
390-
'node_modules/\n.modestbench/\n*.log\n',
394+
'node_modules/\n${DEFAULT_OUTPUT_DIR}/\n*.log\n',
391395
'utf8',
392396
);
393397

@@ -397,11 +401,11 @@ describe('modestbench init command - integration', () => {
397401
const content = await readFile(gitignorePath, 'utf8');
398402

399403
// Count occurrences of .modestbench/
400-
const matches = content.match(/\.modestbench\//g);
404+
const matches = content.match(new RegExp(`${DEFAULT_OUTPUT_DIR}/`, 'g'));
401405
expect(matches?.length, 'to equal', 1);
402406
});
403407

404-
it('should format appended .modestbench/ with proper newlines', async () => {
408+
it(`should format appended ${DEFAULT_OUTPUT_DIR}/ with proper newlines`, async () => {
405409
const gitignorePath = join(tempDir, '.gitignore');
406410

407411
// Create existing .gitignore without trailing newline
@@ -416,7 +420,7 @@ describe('modestbench init command - integration', () => {
416420
expect(
417421
content,
418422
'to contain',
419-
'node_modules/\n\n# ModestBench history\n.modestbench/\n',
423+
`node_modules/\n\n# ModestBench history\n${DEFAULT_OUTPUT_DIR}/\n`,
420424
);
421425
});
422426

0 commit comments

Comments
 (0)