1
1
"use strict" ;
2
2
const { existsSync } = require ( "fs" ) ;
3
3
const { resolve } = require ( "path" ) ;
4
- const { run, readFile } = require ( "../../../../utils/test-utils" ) ;
4
+ const { run, readFile, isWindows } = require ( "../../../../utils/test-utils" ) ;
5
5
6
6
describe ( "function configuration" , ( ) => {
7
7
it ( "should throw when env is not supplied" , async ( ) => {
@@ -17,7 +17,7 @@ describe("function configuration", () => {
17
17
18
18
expect ( exitCode ) . toBe ( 0 ) ;
19
19
expect ( stderr ) . toBeFalsy ( ) ;
20
- expect ( stdout ) . toBeTruthy ( ) ;
20
+ expect ( stdout ) . toContain ( "isProd: true" ) ;
21
21
// Should generate the appropriate files
22
22
expect ( existsSync ( resolve ( __dirname , "./dist/prod.js" ) ) ) . toBeTruthy ( ) ;
23
23
} ) ;
@@ -27,7 +27,7 @@ describe("function configuration", () => {
27
27
28
28
expect ( exitCode ) . toBe ( 0 ) ;
29
29
expect ( stderr ) . toBeFalsy ( ) ;
30
- expect ( stdout ) . toBeTruthy ( ) ;
30
+ expect ( stdout ) . toContain ( "isDev: true" ) ;
31
31
// Should generate the appropriate files
32
32
expect ( existsSync ( resolve ( __dirname , "./dist/dev.js" ) ) ) . toBeTruthy ( ) ;
33
33
} ) ;
@@ -44,7 +44,8 @@ describe("function configuration", () => {
44
44
45
45
expect ( exitCode ) . toBe ( 0 ) ;
46
46
expect ( stderr ) . toBeFalsy ( ) ;
47
- expect ( stdout ) . toBeTruthy ( ) ;
47
+ expect ( stdout ) . toContain ( "environment: 'production'" ) ;
48
+ expect ( stdout ) . toContain ( "app: { title: 'Luffy' }" ) ;
48
49
// Should generate the appropriate files
49
50
expect ( existsSync ( resolve ( __dirname , "./dist/Luffy.js" ) ) ) . toBeTruthy ( ) ;
50
51
} ) ;
@@ -61,7 +62,7 @@ describe("function configuration", () => {
61
62
62
63
expect ( exitCode ) . toBe ( 0 ) ;
63
64
expect ( stderr ) . toBeFalsy ( ) ;
64
- expect ( stdout ) . toBeTruthy ( ) ;
65
+ expect ( stdout ) . toContain ( "environment: 'production'" ) ;
65
66
// Should generate the appropriate files
66
67
expect ( existsSync ( resolve ( __dirname , "./dist/Atsumu.js" ) ) ) . toBeTruthy ( ) ;
67
68
} ) ;
@@ -78,7 +79,8 @@ describe("function configuration", () => {
78
79
79
80
expect ( exitCode ) . toBe ( 0 ) ;
80
81
expect ( stderr ) . toBeFalsy ( ) ;
81
- expect ( stdout ) . toBeTruthy ( ) ;
82
+ expect ( stdout ) . toContain ( "environment: 'multipleq'" ) ;
83
+ expect ( stdout ) . toContain ( "file: 'name=is=Eren'" ) ;
82
84
// Should generate the appropriate files
83
85
expect ( existsSync ( resolve ( __dirname , "./dist/name=is=Eren.js" ) ) ) . toBeTruthy ( ) ;
84
86
} ) ;
@@ -95,7 +97,8 @@ describe("function configuration", () => {
95
97
96
98
expect ( exitCode ) . toBe ( 0 ) ;
97
99
expect ( stderr ) . toBeFalsy ( ) ;
98
- expect ( stdout ) . toBeTruthy ( ) ;
100
+ expect ( stdout ) . toContain ( "environment: 'dot'" ) ;
101
+ expect ( stdout ) . toContain ( "'name.': 'Hisoka'" ) ;
99
102
// Should generate the appropriate files
100
103
expect ( existsSync ( resolve ( __dirname , "./dist/Hisoka.js" ) ) ) . toBeTruthy ( ) ;
101
104
} ) ;
@@ -112,7 +115,8 @@ describe("function configuration", () => {
112
115
113
116
expect ( exitCode ) . toBe ( 0 ) ;
114
117
expect ( stderr ) . toBeFalsy ( ) ;
115
- expect ( stdout ) . toBeTruthy ( ) ;
118
+ expect ( stdout ) . toContain ( "environment: 'dot'" ) ;
119
+ expect ( stdout ) . toContain ( "'name.': true" ) ;
116
120
// Should generate the appropriate files
117
121
expect ( existsSync ( resolve ( __dirname , "./dist/true.js" ) ) ) . toBeTruthy ( ) ;
118
122
} ) ;
@@ -122,7 +126,7 @@ describe("function configuration", () => {
122
126
123
127
expect ( exitCode ) . toBe ( 0 ) ;
124
128
expect ( stderr ) . toBeFalsy ( ) ;
125
- expect ( stdout ) . toBeTruthy ( ) ;
129
+ expect ( stdout ) . toContain ( `foo: "''"` ) ;
126
130
// Should generate the appropriate files
127
131
expect ( existsSync ( resolve ( __dirname , "./dist/empty-string.js" ) ) ) . toBeTruthy ( ) ;
128
132
} ) ;
@@ -132,7 +136,7 @@ describe("function configuration", () => {
132
136
133
137
expect ( exitCode ) . toBe ( 0 ) ;
134
138
expect ( stderr ) . toBeFalsy ( ) ;
135
- expect ( stdout ) . toBeTruthy ( ) ;
139
+ expect ( stdout ) . toContain ( `foo: "bar=''"` ) ;
136
140
// Should generate the appropriate files
137
141
expect ( existsSync ( resolve ( __dirname , "./dist/new-empty-string.js" ) ) ) . toBeTruthy ( ) ;
138
142
} ) ;
@@ -142,11 +146,59 @@ describe("function configuration", () => {
142
146
143
147
expect ( exitCode ) . toBe ( 0 ) ;
144
148
expect ( stderr ) . toBeFalsy ( ) ;
145
- expect ( stdout ) . toBeTruthy ( ) ;
149
+ // should log foo: undefined
150
+ expect ( stdout ) . toContain ( "foo: undefined" ) ;
151
+ } ) ;
152
+
153
+ it ( 'Supports env variable with "foo=undefined" at the end' , async ( ) => {
154
+ const { exitCode, stderr, stdout } = await run ( __dirname , [ "--env" , `foo=undefined` ] ) ;
155
+
156
+ expect ( exitCode ) . toBe ( 0 ) ;
157
+ expect ( stderr ) . toBeFalsy ( ) ;
158
+ // should log foo: 'undefined'
159
+ expect ( stdout ) . toContain ( "foo: 'undefined'" ) ;
146
160
// Should generate the appropriate files
147
- expect ( existsSync ( resolve ( __dirname , "./dist/equal-at-the-end .js" ) ) ) . toBeTruthy ( ) ;
161
+ expect ( existsSync ( resolve ( __dirname , "./dist/undefined-foo .js" ) ) ) . toBeTruthy ( ) ;
148
162
} ) ;
149
163
164
+ // macOS/Linux specific syntax
165
+ if ( ! isWindows ) {
166
+ it ( "Supports empty string in shell environment" , async ( ) => {
167
+ const { exitCode, stderr, stdout } = await run ( __dirname , [ "--env" , "foo=\\'\\'" ] , {
168
+ shell : true ,
169
+ } ) ;
170
+
171
+ expect ( exitCode ) . toBe ( 0 ) ;
172
+ expect ( stderr ) . toBeFalsy ( ) ;
173
+ expect ( stdout ) . toContain ( `foo: "''"` ) ;
174
+ // Should generate the appropriate files
175
+ expect ( existsSync ( resolve ( __dirname , "./dist/empty-string.js" ) ) ) . toBeTruthy ( ) ;
176
+ } ) ;
177
+ it ( "should set the variable to undefined if empty string is not escaped in shell environment" , async ( ) => {
178
+ const { exitCode, stderr, stdout } = await run ( __dirname , [ "--env" , "foo=''" ] , {
179
+ shell : true ,
180
+ } ) ;
181
+
182
+ expect ( exitCode ) . toBe ( 0 ) ;
183
+ expect ( stderr ) . toBeFalsy ( ) ;
184
+ expect ( stdout ) . toContain ( `foo: undefined` ) ;
185
+ } ) ;
186
+ it ( 'Supports env variable with "=$NON_EXISTENT_VAR" at the end' , async ( ) => {
187
+ const { exitCode, stderr, stdout } = await run (
188
+ __dirname ,
189
+ [ "--env" , `foo=$NON_EXISTENT_VAR` ] ,
190
+ {
191
+ shell : true ,
192
+ } ,
193
+ ) ;
194
+
195
+ expect ( exitCode ) . toBe ( 0 ) ;
196
+ expect ( stderr ) . toBeFalsy ( ) ;
197
+ // should log foo: undefined
198
+ expect ( stdout ) . toContain ( "foo: undefined" ) ;
199
+ } ) ;
200
+ }
201
+
150
202
it ( "is able to understand multiple env flags" , async ( ) => {
151
203
const { exitCode, stderr, stdout } = await run ( __dirname , [
152
204
"--env" ,
@@ -159,7 +211,8 @@ describe("function configuration", () => {
159
211
160
212
expect ( exitCode ) . toBe ( 0 ) ;
161
213
expect ( stderr ) . toBeFalsy ( ) ;
162
- expect ( stdout ) . toBeTruthy ( ) ;
214
+ expect ( stdout ) . toContain ( "verboseStats: true" ) ;
215
+ expect ( stdout ) . toContain ( "envMessage: true" ) ;
163
216
// check that the verbose env is respected
164
217
expect ( stdout ) . toContain ( "LOG from webpack" ) ;
165
218
@@ -189,7 +242,7 @@ describe("function configuration", () => {
189
242
190
243
expect ( exitCode ) . toBe ( 0 ) ;
191
244
expect ( stderr ) . toBeFalsy ( ) ;
192
- expect ( stdout ) . toBeTruthy ( ) ;
245
+ expect ( stdout ) . toContain ( "'name.': 'baz'" ) ;
193
246
// Should generate the appropriate files
194
247
expect ( existsSync ( resolve ( __dirname , "./dist/baz.js" ) ) ) . toBeTruthy ( ) ;
195
248
} ) ;
0 commit comments