1- import { cp , readFile , writeFile } from 'node:fs/promises' ;
1+ import { cp } from 'node:fs/promises' ;
22import { join } from 'node:path' ;
3- import { afterEach , beforeAll } from 'vitest' ;
3+ import { beforeAll } from 'vitest' ;
44import type { ReportsDiff } from '@code-pushup/models' ;
55import { teardownTestFolder } from '@code-pushup/test-setup' ;
66import { executeProcess , readJsonFile , readTextFile } from '@code-pushup/utils' ;
@@ -11,45 +11,20 @@ describe('CLI compare', () => {
1111 'cli-e2e' ,
1212 'mocks' ,
1313 'fixtures' ,
14- 'dummy-setup ' ,
14+ 'existing-reports ' ,
1515 ) ;
1616
1717 const envRoot = join ( 'tmp' , 'e2e' , 'cli-e2e' ) ;
18- const testFileDir = join ( envRoot , 'compare' ) ;
19- const dummyDir = join ( testFileDir , 'dummy-setup ' ) ;
20- const dummyOutputDir = join ( dummyDir , '.code-pushup' ) ;
18+ const testFileDir = join ( envRoot , '__test__' , ' compare') ;
19+ const existingDir = join ( testFileDir , 'existing-reports ' ) ;
20+ const existingOutputDir = join ( existingDir , '.code-pushup' ) ;
2121
2222 beforeAll ( async ( ) => {
23- await cp ( fixtureDummyDir , dummyDir , { recursive : true } ) ;
23+ await cp ( fixtureDummyDir , existingDir , { recursive : true } ) ;
2424 } ) ;
2525
2626 afterAll ( async ( ) => {
27- await teardownTestFolder ( dummyDir ) ;
28- } ) ;
29-
30- beforeEach ( async ( ) => {
31- // create report before
32- await executeProcess ( {
33- command : 'npx' ,
34- args : [ '@code-pushup/cli' , 'collect' , '--persist.filename=source-report' ] ,
35- cwd : dummyDir ,
36- } ) ;
37-
38- // adding items to create a report diff
39- const itemsFile = join ( dummyDir , 'src' , 'items.json' ) ;
40- const items = JSON . parse ( ( await readFile ( itemsFile ) ) . toString ( ) ) ;
41- await writeFile ( itemsFile , JSON . stringify ( [ ...items , 4 , 5 , 6 , 7 ] , null , 2 ) ) ;
42-
43- await executeProcess ( {
44- command : 'npx' ,
45- args : [ '@code-pushup/cli' , 'collect' , '--persist.filename=target-report' ] ,
46- cwd : dummyDir ,
47- } ) ;
48- } , 20_000 ) ;
49-
50- // create report after
51- afterEach ( async ( ) => {
52- await teardownTestFolder ( dummyOutputDir ) ;
27+ await teardownTestFolder ( existingDir ) ;
5328 } ) ;
5429
5530 it ( 'should compare report.json files and create report-diff.json and report-diff.md' , async ( ) => {
@@ -61,11 +36,11 @@ describe('CLI compare', () => {
6136 `--before=${ join ( '.code-pushup' , 'source-report.json' ) } ` ,
6237 `--after=${ join ( '.code-pushup' , 'target-report.json' ) } ` ,
6338 ] ,
64- cwd : dummyDir ,
39+ cwd : existingDir ,
6540 } ) ;
6641
6742 const reportsDiff = await readJsonFile < ReportsDiff > (
68- join ( dummyOutputDir , 'report-diff.json' ) ,
43+ join ( existingOutputDir , 'report-diff.json' ) ,
6944 ) ;
7045 expect ( reportsDiff ) . toMatchSnapshot ( {
7146 commits : expect . any ( Object ) ,
@@ -75,7 +50,7 @@ describe('CLI compare', () => {
7550 } ) ;
7651
7752 const reportsDiffMd = await readTextFile (
78- join ( dummyOutputDir , 'report-diff.md' ) ,
53+ join ( existingOutputDir , 'report-diff.md' ) ,
7954 ) ;
8055 // commits are variable, replace SHAs with placeholders
8156 const sanitizedMd = reportsDiffMd . replace ( / [ \d a - f ] { 40 } / g, '`<commit-sha>`' ) ;
0 commit comments