11import { expect } from 'bupkis' ;
2- import { mkdir , mkdtemp , rm , writeFile } from 'node:fs/promises' ;
2+ import { mkdir , mkdtemp , rm } from 'node:fs/promises' ;
33import { tmpdir } from 'node:os' ;
44import { join } from 'node:path' ;
55import { afterEach , beforeEach , describe , it } from 'node:test' ;
66
77import { runCommand } from '../util.js' ;
8+ import { fixtures } from './fixture-paths.js' ;
89
910/**
1011 * Integration tests for baseline management commands
1112 */
1213
1314describe ( '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