88 materializeTree ,
99} from '@code-pushup/test-nx-utils' ;
1010import { teardownTestFolder } from '@code-pushup/test-setup' ;
11- import { removeColorCodes } from '@code-pushup/test-utils' ;
12- import { executeProcess } from '@code-pushup/utils' ;
11+ import { osAgnosticPath , removeColorCodes } from '@code-pushup/test-utils' ;
12+ import { executeProcess , readJsonFile } from '@code-pushup/utils' ;
1313
1414function relativePathToCwd ( testDir : string ) : string {
1515 return relative ( join ( process . cwd ( ) , testDir ) , process . cwd ( ) ) ;
@@ -27,7 +27,7 @@ async function addTargetToWorkspace(
2727 targets : {
2828 ...projectCfg . targets ,
2929 [ 'code-pushup' ] : {
30- executor : '@code-pushup/nx-plugin:autorun ' ,
30+ executor : '@code-pushup/nx-plugin:cli ' ,
3131 } ,
3232 } ,
3333 } ) ;
@@ -37,19 +37,27 @@ async function addTargetToWorkspace(
3737 plugins : [
3838 {
3939 // @TODO replace with inline plugin
40- fileImports : `import {customPlugin} from "${ join (
41- relativePathToCwd ( cwd ) ,
42- pathRelativeToPackage ,
43- 'dist/testing/test-utils' ,
40+ fileImports : `import {customPlugin} from "${ osAgnosticPath (
41+ join (
42+ relativePathToCwd ( cwd ) ,
43+ pathRelativeToPackage ,
44+ 'dist/testing/test-utils' ,
45+ ) ,
4446 ) } ";`,
4547 codeStrings : 'customPlugin()' ,
4648 } ,
4749 ] ,
50+ upload : {
51+ server : 'https://dummy-server.dev' ,
52+ organization : 'dummy-organization' ,
53+ apiKey : 'dummy-api-key' ,
54+ project : 'dummy-project' ,
55+ } ,
4856 } ) ;
4957 await materializeTree ( tree , cwd ) ;
5058}
5159
52- describe ( 'executor autorun ' , ( ) => {
60+ describe ( 'executor command ' , ( ) => {
5361 let tree : Tree ;
5462 const project = 'my-lib' ;
5563 const baseDir = 'tmp/e2e/nx-plugin-e2e/__test__/executor/cli' ;
@@ -62,10 +70,9 @@ describe('executor autorun', () => {
6270 await teardownTestFolder ( baseDir ) ;
6371 } ) ;
6472
65- it ( 'should execute autorun executor ' , async ( ) => {
66- const cwd = join ( baseDir , 'execute-dynamic-executor ' ) ;
73+ it ( 'should execute no specific command by default ' , async ( ) => {
74+ const cwd = join ( baseDir , 'execute-default-command ' ) ;
6775 await addTargetToWorkspace ( tree , { cwd, project } ) ;
68-
6976 const { stdout, code } = await executeProcess ( {
7077 command : 'npx' ,
7178 args : [ 'nx' , 'run' , `${ project } :code-pushup` , '--dryRun' ] ,
@@ -74,6 +81,72 @@ describe('executor autorun', () => {
7481
7582 expect ( code ) . toBe ( 0 ) ;
7683 const cleanStdout = removeColorCodes ( stdout ) ;
77- expect ( cleanStdout ) . toContain ( 'nx run my-lib:code-pushup --dryRun' ) ;
84+ expect ( cleanStdout ) . toContain ( 'nx run my-lib:code-pushup' ) ;
85+ } ) ;
86+
87+ it ( 'should execute print-config executor' , async ( ) => {
88+ const cwd = join ( baseDir , 'execute-print-config-command' ) ;
89+ await addTargetToWorkspace ( tree , { cwd, project } ) ;
90+
91+ const { stdout, code } = await executeProcess ( {
92+ command : 'npx' ,
93+ args : [ 'nx' , 'run' , `${ project } :code-pushup` , 'print-config' ] ,
94+ cwd,
95+ } ) ;
96+
97+ expect ( code ) . toBe ( 0 ) ;
98+ const cleanStdout = removeColorCodes ( stdout ) ;
99+ expect ( cleanStdout ) . toContain ( 'nx run my-lib:code-pushup print-config' ) ;
100+
101+ await expect ( ( ) =>
102+ readJsonFile ( join ( cwd , '.code-pushup' , project , 'report.json' ) ) ,
103+ ) . rejects . toThrow ( '' ) ;
104+ } ) ;
105+
106+ it ( 'should execute collect executor and add report to sub folder named by project' , async ( ) => {
107+ const cwd = join ( baseDir , 'execute-collect-command' ) ;
108+ await addTargetToWorkspace ( tree , { cwd, project } ) ;
109+
110+ const { stdout, code } = await executeProcess ( {
111+ command : 'nx' ,
112+ args : [ 'run' , `${ project } :code-pushup` , 'collect' ] ,
113+ cwd,
114+ } ) ;
115+
116+ expect ( code ) . toBe ( 0 ) ;
117+ const cleanStdout = removeColorCodes ( stdout ) ;
118+ expect ( cleanStdout ) . toContain ( 'nx run my-lib:code-pushup collect' ) ;
119+
120+ const report = await readJsonFile (
121+ join ( cwd , '.code-pushup' , project , 'report.json' ) ,
122+ ) ;
123+ expect ( report ) . toStrictEqual (
124+ expect . objectContaining ( {
125+ plugins : [
126+ expect . objectContaining ( {
127+ slug : 'good-feels' ,
128+ audits : [
129+ expect . objectContaining ( {
130+ displayValue : '✅ Perfect! 👌' ,
131+ slug : 'always-perfect' ,
132+ } ) ,
133+ ] ,
134+ } ) ,
135+ ] ,
136+ } ) ,
137+ ) ;
138+ } ) ;
139+
140+ it ( 'should execute upload executor to throw if no report is present' , async ( ) => {
141+ const cwd = join ( baseDir , 'execute-upload-command' ) ;
142+ await addTargetToWorkspace ( tree , { cwd, project } ) ;
143+
144+ await expect (
145+ executeProcess ( {
146+ command : 'npx' ,
147+ args : [ 'nx' , 'run' , `${ project } :code-pushup` , 'upload' ] ,
148+ cwd,
149+ } ) ,
150+ ) . rejects . toThrow ( / r e p o r t .j s o n / ) ;
78151 } ) ;
79152} ) ;
0 commit comments