@@ -18,6 +18,8 @@ describe('CLI Config Tests', () => {
18
18
projDir = r . name ;
19
19
console . log ( `Project dir: ${ projDir } ` ) ;
20
20
process . chdir ( projDir ) ;
21
+
22
+ fs . writeFileSync ( 'package.json' , JSON . stringify ( { name : 'my app' , version : '1.0.0' } ) ) ;
21
23
} ) ;
22
24
23
25
afterEach ( ( ) => {
@@ -26,7 +28,6 @@ describe('CLI Config Tests', () => {
26
28
} ) ;
27
29
28
30
it ( 'invalid default config' , async ( ) => {
29
- fs . writeFileSync ( 'package.json' , JSON . stringify ( { name : 'my app' , version : '1.0.0' } ) ) ;
30
31
fs . writeFileSync ( 'zenstack.config.json' , JSON . stringify ( { abc : 'def' } ) ) ;
31
32
32
33
const program = createProgram ( ) ;
@@ -36,7 +37,6 @@ describe('CLI Config Tests', () => {
36
37
} ) ;
37
38
38
39
it ( 'valid default config empty' , async ( ) => {
39
- fs . writeFileSync ( 'package.json' , JSON . stringify ( { name : 'my app' , version : '1.0.0' } ) ) ;
40
40
fs . writeFileSync ( 'zenstack.config.json' , JSON . stringify ( { } ) ) ;
41
41
42
42
const program = createProgram ( ) ;
@@ -50,7 +50,6 @@ describe('CLI Config Tests', () => {
50
50
} ) ;
51
51
52
52
it ( 'valid default config non-empty' , async ( ) => {
53
- fs . writeFileSync ( 'package.json' , JSON . stringify ( { name : 'my app' , version : '1.0.0' } ) ) ;
54
53
fs . writeFileSync (
55
54
'zenstack.config.json' ,
56
55
JSON . stringify ( { guardFieldName : 'myGuardField' , transactionFieldName : 'myTransactionField' } )
@@ -66,16 +65,24 @@ describe('CLI Config Tests', () => {
66
65
expect ( config . transactionFieldName ) . toBe ( 'myTransactionField' ) ;
67
66
} ) ;
68
67
69
- it ( 'config not found' , async ( ) => {
70
- fs . writeFileSync ( 'package.json' , JSON . stringify ( { name : 'my app' , version : '1.0.0' } ) ) ;
68
+ it ( 'custom config file does not exist' , async ( ) => {
71
69
const program = createProgram ( ) ;
70
+ const configFile = `my.config.json` ;
72
71
await expect (
73
- program . parseAsync ( [ 'init' , '--tag' , 'latest' , '--config' , 'my.config.json' ] , { from : 'user' } )
74
- ) . rejects . toBeInstanceOf ( CliError ) ;
72
+ program . parseAsync ( [ 'init' , '--tag' , 'latest' , '--config' , configFile ] , { from : 'user' } )
73
+ ) . rejects . toThrow ( / C o n f i g f i l e c o u l d n o t b e f o u n d / i) ;
74
+ } ) ;
75
+
76
+ it ( 'custom config file is not json' , async ( ) => {
77
+ const program = createProgram ( ) ;
78
+ const configFile = `my.config.json` ;
79
+ fs . writeFileSync ( configFile , ` 😬 😬 😬` ) ;
80
+ await expect (
81
+ program . parseAsync ( [ 'init' , '--tag' , 'latest' , '--config' , configFile ] , { from : 'user' } )
82
+ ) . rejects . toThrow ( / C o n f i g i s n o t a v a l i d J S O N f i l e / i) ;
75
83
} ) ;
76
84
77
85
it ( 'valid custom config file' , async ( ) => {
78
- fs . writeFileSync ( 'package.json' , JSON . stringify ( { name : 'my app' , version : '1.0.0' } ) ) ;
79
86
fs . writeFileSync ( 'my.config.json' , JSON . stringify ( { guardFieldName : 'myGuardField' } ) ) ;
80
87
const program = createProgram ( ) ;
81
88
await program . parseAsync ( [ 'init' , '--tag' , 'latest' , '--config' , 'my.config.json' ] , { from : 'user' } ) ;
@@ -88,11 +95,10 @@ describe('CLI Config Tests', () => {
88
95
} ) ;
89
96
90
97
it ( 'invalid custom config file' , async ( ) => {
91
- fs . writeFileSync ( 'package.json' , JSON . stringify ( { name : 'my app' , version : '1.0.0' } ) ) ;
92
98
fs . writeFileSync ( 'my.config.json' , JSON . stringify ( { abc : 'def' } ) ) ;
93
99
const program = createProgram ( ) ;
94
100
await expect (
95
101
program . parseAsync ( [ 'init' , '--tag' , 'latest' , '--config' , 'my.config.json' ] , { from : 'user' } )
96
- ) . rejects . toBeInstanceOf ( CliError ) ;
102
+ ) . rejects . toThrow ( / C o n f i g f i l e m y . c o n f i g . j s o n i s n o t v a l i d / i ) ;
97
103
} ) ;
98
104
} ) ;
0 commit comments