1
1
import { describe , it , expect , beforeAll } from 'vitest' ;
2
2
import { cli } from '@quality-metrics/cli' ;
3
3
import { execSync } from 'child_process' ;
4
+ import { join } from 'path' ;
5
+
6
+ const configFile = ( ext : 'ts' | 'js' | 'mjs' ) =>
7
+ join ( process . cwd ( ) , `examples/cli-e2e/mocks/config.mock.${ ext } ` ) ;
4
8
5
9
describe ( 'cli' , ( ) => {
6
10
beforeAll ( ( ) => {
@@ -9,35 +13,23 @@ describe('cli', () => {
9
13
} ) ;
10
14
11
15
it ( 'should load .js config file' , async ( ) => {
12
- await expect (
13
- cli ( './examples/cli-e2e/mocks/config.mock.js' ) ,
14
- ) . resolves . toEqual ( {
15
- plugins : [
16
- { name : 'eslint' , version : '8.46.0' } ,
17
- { name : 'lighthouse' , defaultConfig : expect . any ( Object ) } ,
18
- ] ,
19
- } ) ;
16
+ const argv = await cli ( [ '--configPath' , configFile ( 'js' ) , '--verbose' ] )
17
+ . argv ;
18
+ expect ( argv . plugins [ 0 ] . meta . slug ) . toEqual ( 'eslint' ) ;
19
+ expect ( argv . plugins [ 1 ] . meta . slug ) . toEqual ( 'lighthouse' ) ;
20
20
} ) ;
21
21
22
22
it ( 'should load .mjs config file' , async ( ) => {
23
- await expect (
24
- cli ( './examples/cli-e2e/mocks/config.mock.mjs' ) ,
25
- ) . resolves . toEqual ( {
26
- plugins : [
27
- { name : 'eslint' , version : '8.46.0' } ,
28
- { name : 'lighthouse' , defaultConfig : expect . any ( Object ) } ,
29
- ] ,
30
- } ) ;
23
+ const argv = await cli ( [ '--configPath' , configFile ( 'mjs' ) , '--verbose' ] )
24
+ . argv ;
25
+ expect ( argv . plugins [ 0 ] . meta . slug ) . toEqual ( 'eslint' ) ;
26
+ expect ( argv . plugins [ 1 ] . meta . slug ) . toEqual ( 'lighthouse' ) ;
31
27
} ) ;
32
28
33
29
it ( 'should load .ts config file' , async ( ) => {
34
- await expect (
35
- cli ( './examples/cli-e2e/mocks/config.mock.ts' ) ,
36
- ) . resolves . toEqual ( {
37
- plugins : [
38
- { name : 'eslint' , version : '8.46.0' } ,
39
- { name : 'lighthouse' , defaultConfig : expect . any ( Object ) } ,
40
- ] ,
41
- } ) ;
30
+ const argv = await cli ( [ '--configPath' , configFile ( 'ts' ) , '--verbose' ] )
31
+ . argv ;
32
+ expect ( argv . plugins [ 0 ] . meta . slug ) . toEqual ( 'eslint' ) ;
33
+ expect ( argv . plugins [ 1 ] . meta . slug ) . toEqual ( 'lighthouse' ) ;
42
34
} ) ;
43
35
} ) ;
0 commit comments