Skip to content

Commit b4a14f3

Browse files
committed
fix: fix engine and reporter problems
1 parent fee5ced commit b4a14f3

15 files changed

Lines changed: 639 additions & 159 deletions

File tree

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@
175175
}
176176
},
177177
"lint-staged": {
178-
"package.json": [
179-
"npm pkg fix"
180-
],
181178
"*.{ts,cts,js,cjs,yml,json5}": [
182179
"eslint --fix",
183180
"prettier --write",

src/cli/commands/init.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,39 +43,39 @@ const PROJECT_TEMPLATES = {
4343
advanced: {
4444
configOptions: {
4545
iterations: 1000,
46-
outputDir: './benchmark-results',
47-
pattern: 'benchmarks/**/*.bench.{js,ts}',
46+
outputDir: '.modestbench',
47+
pattern: 'bench/**/*.bench.{js,ts}',
4848
reporters: ['human', 'json'],
4949
time: 10000,
5050
warmup: 50,
5151
},
5252
description: 'Feature-rich setup with multiple reporters and configuration',
53-
directories: ['benchmarks', 'benchmark-results'],
53+
directories: ['bench', '.modestbench'],
5454
name: 'Advanced Project',
5555
},
5656
basic: {
5757
configOptions: {
5858
iterations: 100,
59-
pattern: 'benchmarks/**/*.bench.{js,ts}',
59+
pattern: 'bench/**/*.bench.{js,ts}',
6060
reporters: ['human'],
6161
time: 5000,
6262
},
6363
description: 'Simple benchmark setup for small projects',
64-
directories: ['benchmarks'],
64+
directories: ['bench'],
6565
name: 'Basic Project',
6666
},
6767
library: {
6868
configOptions: {
6969
bail: false,
7070
iterations: 5000,
71-
outputDir: './benchmark-results',
72-
pattern: 'benchmarks/**/*.bench.{js,ts}',
71+
outputDir: '.modestbench',
72+
pattern: 'bench/**/*.bench.{js,ts}',
7373
reporters: ['human', 'json'],
7474
time: 15000,
7575
warmup: 100,
7676
},
7777
description: 'Optimized for library performance testing',
78-
directories: ['benchmarks', 'benchmarks/suites', 'benchmark-results'],
78+
directories: ['bench', 'bench/suites', '.modestbench'],
7979
name: 'Library Project',
8080
},
8181
} as const;
@@ -316,7 +316,7 @@ export const handleInitCommand = async (
316316
console.log(' 1. Run example benchmarks: modestbench run');
317317
} else {
318318
console.log(
319-
' 1. Create your first benchmark file in the benchmarks/ directory',
319+
' 1. Create your first benchmark file in the bench/ directory',
320320
);
321321
}
322322
console.log(' 2. Customize configuration in your config file');
@@ -385,7 +385,7 @@ modestbench run
385385
386386
Run specific benchmarks:
387387
\`\`\`bash
388-
modestbench run "benchmarks/array-*.bench.js"
388+
modestbench run "bench/array-*.bench.js"
389389
\`\`\`
390390
391391
View benchmark history:
@@ -399,7 +399,7 @@ See \`modestbench.config.*\` for benchmark configuration options.
399399
400400
## Writing Benchmarks
401401
402-
Create new benchmark files in the \`benchmarks/\` directory. See the examples for the expected format.
402+
Create new benchmark files in the \`bench/\` directory. See the examples for the expected format.
403403
`;
404404

405405
try {
@@ -549,7 +549,7 @@ const createDirectories = async (
549549
* Create example benchmark files
550550
*/
551551
const createExampleBenchmarks = async (cwd: string): Promise<void> => {
552-
const benchmarksDir = resolve(cwd, 'benchmarks');
552+
const benchmarksDir = resolve(cwd, 'bench');
553553

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

src/cli/commands/run.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,8 @@ export const handleRunCommand = async (
7171
context: CliContext,
7272
options: RunOptions,
7373
): Promise<number> => {
74-
// Check if JSON reporter is being used (need quiet output for clean JSON)
75-
// Only force quiet mode if json is used AND no output directory is specified
76-
// (i.e., outputting to stdout where we need clean JSON)
77-
const isUsingJsonReporter = options.reporters?.includes('json') ?? false;
78-
const shouldBeQuiet =
79-
options.quiet || (isUsingJsonReporter && !options.outputDir);
8074
const verbose = options.verbose ?? false;
81-
// CLI messages on stderr should only be suppressed by explicit --quiet, not JSON-forced quiet
82-
const showCliMessages = verbose && !options.quiet;
75+
let shouldBeQuiet = options.quiet ?? false; // Will be updated after config loads
8376

8477
try {
8578
// Validate --output-file usage
@@ -95,11 +88,17 @@ export const handleRunCommand = async (
9588
}
9689

9790
// Step 1: Load and merge configuration
98-
if (showCliMessages) {
99-
console.error('Loading configuration...');
100-
}
10191
const config = await loadConfiguration(context, options);
10292

93+
// Check if JSON reporter is being used (need quiet output for clean JSON)
94+
// Only force quiet mode if json is used AND no output directory is specified
95+
// (i.e., outputting to stdout where we need clean JSON)
96+
const isUsingJsonReporter = config.reporters?.includes('json') ?? false;
97+
const hasOutputDir = !!(options.outputDir || config.outputDir);
98+
shouldBeQuiet = options.quiet || (isUsingJsonReporter && !hasOutputDir);
99+
// CLI messages on stderr should only be suppressed by explicit --quiet, not JSON-forced quiet
100+
const showCliMessages = verbose && !options.quiet;
101+
103102
// Step 2: Configure reporters
104103
if (showCliMessages) {
105104
console.error('Setting up reporters...');
@@ -109,7 +108,7 @@ export const handleRunCommand = async (
109108
config,
110109
verbose,
111110
showCliMessages,
112-
options.quiet ?? false,
111+
shouldBeQuiet,
113112
options.outputDir,
114113
options.outputFile,
115114
options.progress,
@@ -377,11 +376,13 @@ const setupReporters = (
377376
// Dedupe requested reporters
378377
const requestedReporters = [...new Set(config.reporters || ['human'])];
379378

380-
// Only use file output if --output was explicitly provided
381-
// Use the explicit output dir if provided, otherwise check config
379+
// Use output directory from CLI flag, config file, or undefined
380+
// CLI flag takes precedence over config file
382381
const outputDir = explicitOutputDir
383382
? resolve(explicitOutputDir)
384-
: undefined;
383+
: config.outputDir
384+
? resolve(config.outputDir)
385+
: undefined;
385386

386387
// Built-in reporter names for error messages
387388
const builtInReporters = ['human', 'json', 'csv', 'simple'];

src/core/engine.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ export abstract class ModestBenchEngine implements BenchmarkEngine {
652652
benchmarkDef.suites,
653653
)) {
654654
// Use shared filtering logic
655-
const { anyTaskMatches, suiteMatches } =
655+
const { anyTaskMatches, suiteMatches, tasksToRun } =
656656
this.getFilteredTasksForSuite(
657657
suiteData,
658658
fileTags,
@@ -665,6 +665,15 @@ export abstract class ModestBenchEngine implements BenchmarkEngine {
665665
continue;
666666
}
667667

668+
// Emit suite init with task names for pre-calculation
669+
const taskNames = tasksToRun.map(([name]) => name);
670+
await this.callReporters(
671+
reporters,
672+
'onSuiteInit',
673+
suiteName,
674+
taskNames,
675+
);
676+
668677
await this.callReporters(reporters, 'onSuiteStart', suiteName);
669678
const suiteResult = await this.executeBenchmarkSuite(
670679
suiteName,
@@ -768,6 +777,12 @@ export abstract class ModestBenchEngine implements BenchmarkEngine {
768777
}
769778
}
770779

780+
// Merge suite-level config with global config
781+
// Suite-level config takes precedence over global config
782+
const mergedConfig = suiteData.config
783+
? { ...config, ...suiteData.config }
784+
: config;
785+
771786
try {
772787
// Process each task that passed filtering
773788
for (const [taskName, taskData] of tasksToRun) {
@@ -776,13 +791,14 @@ export abstract class ModestBenchEngine implements BenchmarkEngine {
776791
// Mark task as in-progress (shows as 0.5 progress for current task)
777792
const currentState = this.progressManager.getState();
778793
this.progressManager.update({
794+
currentTask: taskName,
779795
tasksCompleted: currentState.tasksCompleted + 0.5,
780796
});
781797

782798
const taskResult = await this.executeBenchmarkTask(
783799
taskName,
784800
taskData,
785-
config,
801+
mergedConfig,
786802
reporters,
787803
signal,
788804
);

0 commit comments

Comments
 (0)