1- import { cp } from 'node:fs/promises' ;
21import path from 'node:path' ;
3- import { simpleGit } from 'simple-git' ;
42import { afterAll , afterEach , beforeAll } from 'vitest' ;
53import { type Report , reportSchema } from '@code-pushup/models' ;
64import { omitVariableReportData } from '@code-pushup/test-fixtures' ;
75import { nxTargetProject } from '@code-pushup/test-nx-utils' ;
86import {
97 E2E_ENVIRONMENTS_DIR ,
108 TEST_OUTPUT_DIR ,
11- initGitRepo ,
12- restoreNxIgnoredFiles ,
139 teardownTestFolder ,
1410} from '@code-pushup/test-utils' ;
11+ import {
12+ type TestEnvironmentWithGit ,
13+ setupTestEnvironment ,
14+ } from '@code-pushup/test-utils' ;
1515import { executeProcess , readJsonFile } from '@code-pushup/utils' ;
1616
1717describe ( 'PLUGIN collect report with coverage-plugin NPM package' , ( ) => {
1818 const envRoot = path . join ( E2E_ENVIRONMENTS_DIR , nxTargetProject ( ) ) ;
1919 const testFileDir = path . join ( envRoot , TEST_OUTPUT_DIR , 'collect' ) ;
2020
21- const basicDir = path . join ( testFileDir , 'basic-setup' ) ;
22- const existingDir = path . join ( testFileDir , 'existing-report' ) ;
23-
24- const fixtureDir = path . join ( 'e2e' , nxTargetProject ( ) , 'mocks' , 'fixtures' ) ;
21+ let basicEnv : TestEnvironmentWithGit ;
22+ let existingEnv : TestEnvironmentWithGit ;
2523
2624 beforeAll ( async ( ) => {
27- await cp ( fixtureDir , testFileDir , { recursive : true } ) ;
28- await restoreNxIgnoredFiles ( testFileDir ) ;
29- await initGitRepo ( simpleGit , { baseDir : basicDir } ) ;
30- await initGitRepo ( simpleGit , { baseDir : existingDir } ) ;
25+ basicEnv = await setupTestEnvironment (
26+ [ '..' , 'mocks' , 'fixtures' , 'basic-setup' ] ,
27+ {
28+ callerUrl : import . meta. url ,
29+ git : true ,
30+ testId : 'plugin-coverage-basic' ,
31+ } ,
32+ ) ;
33+ existingEnv = await setupTestEnvironment (
34+ [ '..' , 'mocks' , 'fixtures' , 'existing-report' ] ,
35+ {
36+ callerUrl : import . meta. url ,
37+ git : true ,
38+ testId : 'plugin-coverage-existing' ,
39+ } ,
40+ ) ;
3141 } ) ;
3242
3343 afterAll ( async ( ) => {
34- await teardownTestFolder ( basicDir ) ;
35- await teardownTestFolder ( existingDir ) ;
44+ await basicEnv . cleanup ( ) ;
45+ await existingEnv . cleanup ( ) ;
3646 } ) ;
3747
3848 afterEach ( async ( ) => {
39- await teardownTestFolder ( path . join ( basicDir , '.code-pushup' ) ) ;
40- await teardownTestFolder ( path . join ( existingDir , '.code-pushup' ) ) ;
49+ await teardownTestFolder ( path . join ( basicEnv . baseDir , '.code-pushup' ) ) ;
50+ await teardownTestFolder ( path . join ( existingEnv . baseDir , '.code-pushup' ) ) ;
4151 } ) ;
4252
4353 it ( 'should run Code coverage plugin which runs tests and creates report.json' , async ( ) => {
4454 const { code } = await executeProcess ( {
4555 command : 'npx' ,
4656 args : [ 'code-pushup' , 'collect' ] ,
47- cwd : basicDir ,
57+ cwd : basicEnv . baseDir ,
4858 } ) ;
4959
5060 expect ( code ) . toBe ( 0 ) ;
5161
5262 const report = await readJsonFile < Report > (
53- path . join ( basicDir , '.code-pushup' , 'report.json' ) ,
63+ path . join ( basicEnv . baseDir , '.code-pushup' , 'report.json' ) ,
5464 ) ;
5565
5666 expect ( ( ) => reportSchema . parse ( report ) ) . not . toThrow ( ) ;
@@ -61,13 +71,13 @@ describe('PLUGIN collect report with coverage-plugin NPM package', () => {
6171 const { code } = await executeProcess ( {
6272 command : 'npx' ,
6373 args : [ '@code-pushup/cli' , 'collect' ] ,
64- cwd : existingDir ,
74+ cwd : existingEnv . baseDir ,
6575 } ) ;
6676
6777 expect ( code ) . toBe ( 0 ) ;
6878
6979 const report = await readJsonFile < Report > (
70- path . join ( existingDir , '.code-pushup' , 'report.json' ) ,
80+ path . join ( existingEnv . baseDir , '.code-pushup' , 'report.json' ) ,
7181 ) ;
7282
7383 expect ( ( ) => reportSchema . parse ( report ) ) . not . toThrow ( ) ;
0 commit comments