11import { cp } from 'node:fs/promises' ;
22// eslint-disable-next-line unicorn/import-style
3- import { join } from 'node:path' ;
3+ import path , { join } from 'node:path' ;
44import { afterAll , beforeAll , expect } from 'vitest' ;
55import { type Report , reportSchema } from '@code-pushup/models' ;
66import { nxTargetProject } from '@code-pushup/test-nx-utils' ;
@@ -13,48 +13,58 @@ import {
1313} from '@code-pushup/test-utils' ;
1414import { executeProcess , readJsonFile } from '@code-pushup/utils' ;
1515
16- describe . todo (
17- 'PLUGIN collect report with typescript-plugin NPM package' ,
18- ( ) => {
19- const envRoot = join ( E2E_ENVIRONMENTS_DIR , nxTargetProject ( ) ) ;
20- const testFileDir = join ( envRoot , TEST_OUTPUT_DIR , 'collect' ) ;
21- const defaultSetupDir = join ( testFileDir , 'default-setup' ) ;
16+ describe ( 'PLUGIN collect report with typescript-plugin NPM package' , ( ) => {
17+ const envRoot = join ( E2E_ENVIRONMENTS_DIR , nxTargetProject ( ) ) ;
18+ const distRoot = join ( envRoot , TEST_OUTPUT_DIR ) ;
2219
23- const fixturesDir = join ( 'e2e' , nxTargetProject ( ) , 'mocks' , 'fixtures' ) ;
20+ const fixturesDir = join (
21+ 'e2e' ,
22+ nxTargetProject ( ) ,
23+ 'mocks' ,
24+ 'fixtures' ,
25+ 'default-setup' ,
26+ ) ;
2427
25- beforeAll ( async ( ) => {
26- await cp ( fixturesDir , testFileDir , { recursive : true } ) ;
27- } ) ;
28+ beforeAll ( async ( ) => {
29+ await cp ( fixturesDir , envRoot , { recursive : true } ) ;
30+ } ) ;
2831
29- afterAll ( async ( ) => {
30- await teardownTestFolder ( testFileDir ) ;
31- } ) ;
32+ afterAll ( async ( ) => {
33+ await teardownTestFolder ( distRoot ) ;
34+ } ) ;
35+
36+ it ( 'should run plugin over CLI and creates report.json' , async ( ) => {
37+ const outputDir = join (
38+ path . relative ( envRoot , distRoot ) ,
39+ 'create-report' ,
40+ '.code-pushup' ,
41+ ) ;
3242
33- it ( 'should run plugin over CLI and creates report.json' , async ( ) => {
34- const { code, stdout } = await executeProcess ( {
35- command : 'npx' ,
36- // verbose exposes audits with perfect scores that are hidden in the default stdout
37- args : [
38- '@code-pushup/cli' ,
39- 'collect' ,
40- `--config=${ join ( TEST_OUTPUT_DIR , 'collect' , 'default-setup' , 'code-pushup.config.ts' ) } ` ,
41- '--no-progress' ,
42- '--verbose' ,
43- ] ,
44- cwd : envRoot ,
45- } ) ;
46-
47- expect ( code ) . toBe ( 0 ) ;
48- const cleanStdout = removeColorCodes ( stdout ) ;
49- expect ( cleanStdout ) . toContain ( '● Largest Contentful Paint' ) ;
50-
51- const report = await readJsonFile (
52- join ( defaultSetupDir , '.code-pushup' , 'report.json' ) ,
53- ) ;
54- expect ( ( ) => reportSchema . parse ( report ) ) . not . toThrow ( ) ;
55- expect (
56- omitVariableReportData ( report as Report , { omitAuditData : true } ) ,
57- ) . toMatchSnapshot ( ) ;
43+ const { code, stdout } = await executeProcess ( {
44+ command : 'npx' ,
45+ // verbose exposes audits with perfect scores that are hidden in the default stdout
46+ args : [
47+ '@code-pushup/cli' ,
48+ 'collect' ,
49+ '--no-progress' ,
50+ '--verbose' ,
51+ `--persist.outputDir=${ outputDir } ` ,
52+ ] ,
53+ cwd : envRoot ,
5854 } ) ;
59- } ,
60- ) ;
55+
56+ expect ( code ) . toBe ( 0 ) ;
57+ const cleanStdout = removeColorCodes ( stdout ) ;
58+ expect ( cleanStdout ) . toMatchFileSnapshot (
59+ '__snapshots__/typescript-plugin-terminal-report.txt' ,
60+ ) ;
61+
62+ expect ( cleanStdout ) . toMatch ( / ● N o I m p l i c i t A n y \s + 1 / ) ;
63+
64+ const report = await readJsonFile ( join ( envRoot , outputDir , 'report.json' ) ) ;
65+ expect ( ( ) => reportSchema . parse ( report ) ) . not . toThrow ( ) ;
66+ expect (
67+ omitVariableReportData ( report as Report , { omitAuditData : true } ) ,
68+ ) . toMatchFileSnapshot ( '__snapshots__/typescript-plugin-json-report.json' ) ;
69+ } ) ;
70+ } ) ;
0 commit comments