8
8
materializeTree ,
9
9
} from '@code-pushup/test-nx-utils' ;
10
10
import { 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' ;
13
13
14
14
function relativePathToCwd ( testDir : string ) : string {
15
15
return relative ( join ( process . cwd ( ) , testDir ) , process . cwd ( ) ) ;
@@ -27,7 +27,7 @@ async function addTargetToWorkspace(
27
27
targets : {
28
28
...projectCfg . targets ,
29
29
[ 'code-pushup' ] : {
30
- executor : '@code-pushup/nx-plugin:autorun ' ,
30
+ executor : '@code-pushup/nx-plugin:cli ' ,
31
31
} ,
32
32
} ,
33
33
} ) ;
@@ -37,19 +37,27 @@ async function addTargetToWorkspace(
37
37
plugins : [
38
38
{
39
39
// @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
+ ) ,
44
46
) } ";`,
45
47
codeStrings : 'customPlugin()' ,
46
48
} ,
47
49
] ,
50
+ upload : {
51
+ server : 'https://dummy-server.dev' ,
52
+ organization : 'dummy-organization' ,
53
+ apiKey : 'dummy-api-key' ,
54
+ project : 'dummy-project' ,
55
+ } ,
48
56
} ) ;
49
57
await materializeTree ( tree , cwd ) ;
50
58
}
51
59
52
- describe ( 'executor autorun ' , ( ) => {
60
+ describe ( 'executor command ' , ( ) => {
53
61
let tree : Tree ;
54
62
const project = 'my-lib' ;
55
63
const baseDir = 'tmp/e2e/nx-plugin-e2e/__test__/executor/cli' ;
@@ -62,10 +70,9 @@ describe('executor autorun', () => {
62
70
await teardownTestFolder ( baseDir ) ;
63
71
} ) ;
64
72
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 ' ) ;
67
75
await addTargetToWorkspace ( tree , { cwd, project } ) ;
68
-
69
76
const { stdout, code } = await executeProcess ( {
70
77
command : 'npx' ,
71
78
args : [ 'nx' , 'run' , `${ project } :code-pushup` , '--dryRun' ] ,
@@ -74,6 +81,72 @@ describe('executor autorun', () => {
74
81
75
82
expect ( code ) . toBe ( 0 ) ;
76
83
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 / ) ;
78
151
} ) ;
79
152
} ) ;
0 commit comments