1- import {
2- copyFile ,
3- mkdir ,
4- readFile ,
5- rename ,
6- rm ,
7- writeFile ,
8- } from 'node:fs/promises' ;
1+ import { cp , readFile , rename } from 'node:fs/promises' ;
92import { dirname , join } from 'node:path' ;
103import { fileURLToPath } from 'node:url' ;
114import {
@@ -14,6 +7,7 @@ import {
147 type SimpleGit ,
158 simpleGit ,
169} from 'simple-git' ;
10+ import { afterEach } from 'vitest' ;
1711import {
1812 type Comment ,
1913 type GitRefs ,
@@ -22,41 +16,42 @@ import {
2216 type RunResult ,
2317 runInCI ,
2418} from '@code-pushup/ci' ;
25- import { initGitRepo } from '@code-pushup/test-utils' ;
19+ import { nxTargetProject } from '@code-pushup/test-nx-utils' ;
20+ import { teardownTestFolder } from '@code-pushup/test-setup' ;
21+ import {
22+ E2E_ENVIRONMENTS_DIR ,
23+ TEST_OUTPUT_DIR ,
24+ TEST_SNAPSHOTS_DIR ,
25+ initGitRepo ,
26+ } from '@code-pushup/test-utils' ;
2627
2728describe ( 'CI package' , ( ) => {
2829 const fixturesDir = join (
2930 fileURLToPath ( dirname ( import . meta. url ) ) ,
3031 '..' ,
3132 'mocks' ,
3233 'fixtures' ,
34+ 'ci-test-repo' ,
3335 ) ;
34- const workDir = join (
36+ const ciSetupRepoDir = join (
3537 process . cwd ( ) ,
36- 'tmp' ,
37- 'e2e' ,
38- 'ci-e2e' ,
39- '__test__' ,
38+ E2E_ENVIRONMENTS_DIR ,
39+ nxTargetProject ( ) ,
40+ TEST_OUTPUT_DIR ,
4041 'ci-test-repo' ,
4142 ) ;
42- const outputDir = join ( workDir , '.code-pushup' ) ;
43+ const outputDir = join ( ciSetupRepoDir , '.code-pushup' ) ;
4344
4445 const options = {
45- directory : workDir ,
46+ directory : ciSetupRepoDir ,
4647 } satisfies Options ;
4748
4849 let git : SimpleGit ;
4950
5051 beforeEach ( async ( ) => {
51- await rm ( workDir , { recursive : true , force : true } ) ;
52- await mkdir ( workDir , { recursive : true } ) ;
53- await copyFile (
54- join ( fixturesDir , 'code-pushup.config.ts' ) ,
55- join ( workDir , 'code-pushup.config.ts' ) ,
56- ) ;
57- await writeFile ( join ( workDir , 'index.js' ) , 'console.log("Hello, world!")' ) ;
52+ await cp ( fixturesDir , ciSetupRepoDir , { recursive : true } ) ;
5853
59- git = await initGitRepo ( simpleGit , { baseDir : workDir } ) ;
54+ git = await initGitRepo ( simpleGit , { baseDir : ciSetupRepoDir } ) ;
6055
6156 vi . spyOn ( git , 'fetch' ) . mockResolvedValue ( { } as FetchResult ) ;
6257 vi . spyOn ( git , 'diffSummary' ) . mockResolvedValue ( {
@@ -69,8 +64,12 @@ describe('CI package', () => {
6964 await git . commit ( 'Initial commit' ) ;
7065 } ) ;
7166
67+ afterEach ( async ( ) => {
68+ await teardownTestFolder ( ciSetupRepoDir ) ;
69+ } ) ;
70+
7271 afterAll ( async ( ) => {
73- await rm ( workDir , { recursive : true , force : true } ) ;
72+ await teardownTestFolder ( ciSetupRepoDir ) ;
7473 } ) ;
7574
7675 describe ( 'push event' , ( ) => {
@@ -138,7 +137,10 @@ describe('CI package', () => {
138137 beforeEach ( async ( ) => {
139138 await git . checkoutLocalBranch ( 'feature-1' ) ;
140139
141- await rename ( join ( workDir , 'index.js' ) , join ( workDir , 'index.ts' ) ) ;
140+ await rename (
141+ join ( ciSetupRepoDir , 'index.js' ) ,
142+ join ( ciSetupRepoDir , 'index.ts' ) ,
143+ ) ;
142144
143145 await git . add ( 'index.ts' ) ;
144146 await git . commit ( 'Convert JS file to TS' ) ;
@@ -177,7 +179,7 @@ describe('CI package', () => {
177179 const md = await mdPromise ;
178180 await expect (
179181 md . replace ( / [ \d a - f ] { 40 } / g, '`<commit-sha>`' ) ,
180- ) . toMatchFileSnapshot ( '__snapshots__/ report-diff.md') ;
182+ ) . toMatchFileSnapshot ( join ( TEST_SNAPSHOTS_DIR , ' report-diff.md') ) ;
181183 } ) ;
182184 } ) ;
183185} ) ;
0 commit comments