1
1
import { join } from 'path' ;
2
2
import { expect } from 'vitest' ;
3
- import {
4
- CliArgsObject ,
5
- executeProcess ,
6
- objectToCliArgs ,
7
- } from '@code-pushup/utils' ;
3
+ import { CliArgsObject } from '@code-pushup/utils' ;
4
+ import { configFile , execCli , extensions } from '../mocks/utils' ;
8
5
9
- const extensions = [ 'js' , 'mjs' , 'ts' ] as const ;
10
- type Extension = ( typeof extensions ) [ number ] ;
11
-
12
- const configFile = ( ext : Extension ) =>
13
- join ( process . cwd ( ) , `e2e/cli-e2e/mocks/code-pushup.config.${ ext } ` ) ;
14
-
15
- const execCli = ( argObj : Partial < CliArgsObject > ) =>
16
- executeProcess ( {
17
- command : 'npx' ,
18
- args : [
19
- './dist/packages/cli' ,
20
- 'print-config' ,
21
- ...objectToCliArgs ( {
22
- verbose : true ,
23
- ...argObj ,
24
- } ) ,
25
- ] ,
26
- } ) ;
6
+ const execCliPrintConfig = ( argObj : Partial < CliArgsObject > ) =>
7
+ execCli ( 'print-config' , argObj ) ;
27
8
28
9
describe ( 'print-config' , ( ) => {
29
10
it . each ( extensions ) ( 'should load .%s config file' , async ext => {
30
- const { code, stderr, stdout } = await execCli ( { config : configFile ( ext ) } ) ;
11
+ const { code, stderr, stdout } = await execCliPrintConfig ( {
12
+ config : configFile ( ext ) ,
13
+ } ) ;
31
14
expect ( code ) . toBe ( 0 ) ;
32
15
expect ( stderr ) . toBe ( '' ) ;
33
16
const args = JSON . parse ( stdout ) ;
34
17
expect ( args ) . toEqual ( {
35
- progress : true ,
18
+ progress : false ,
36
19
verbose : true ,
37
20
config : expect . stringContaining ( `code-pushup.config.${ ext } ` ) ,
38
21
upload : {
@@ -51,14 +34,14 @@ describe('print-config', () => {
51
34
} ) ;
52
35
53
36
it ( 'should load .ts config file and merge cli arguments' , async ( ) => {
54
- const { code, stderr, stdout } = await execCli ( {
55
- config : configFile ( 'ts' ) ,
37
+ const { code, stderr, stdout } = await execCliPrintConfig ( {
38
+ 'persist.filename' : 'my-report' ,
56
39
} ) ;
57
40
expect ( code ) . toBe ( 0 ) ;
58
41
expect ( stderr ) . toBe ( '' ) ;
59
42
const args = JSON . parse ( stdout ) ;
60
43
expect ( args ) . toEqual ( {
61
- progress : true ,
44
+ progress : false ,
62
45
verbose : true ,
63
46
config : expect . stringContaining ( `code-pushup.config.ts` ) ,
64
47
upload : {
@@ -69,16 +52,15 @@ describe('print-config', () => {
69
52
} ,
70
53
persist : {
71
54
outputDir : join ( 'tmp' , 'ts' ) ,
72
- filename : 'report' ,
55
+ filename : 'my- report' ,
73
56
} ,
74
57
plugins : expect . any ( Array ) ,
75
58
categories : expect . any ( Array ) ,
76
59
} ) ;
77
60
} ) ;
78
61
79
62
it ( 'should parse persist.format from arguments' , async ( ) => {
80
- const { code, stderr, stdout } = await execCli ( {
81
- config : configFile ( 'ts' ) ,
63
+ const { code, stderr, stdout } = await execCliPrintConfig ( {
82
64
'persist.format' : [ 'md' , 'json' , 'stdout' ] ,
83
65
} ) ;
84
66
expect ( code ) . toBe ( 0 ) ;
0 commit comments