@@ -157,7 +157,7 @@ type Test = { packageName: string }
157
157
type InstallTest = Test & { install : [ cmd : string , args : string [ ] ] ; lockfile : string }
158
158
type RunTest = Test & { run : [ cmd : string , args : string [ ] ] }
159
159
160
- const tests : [ packageManager : string , config : InstallTest | RunTest ] [ ] = [
160
+ const installTests : [ packageManager : string , config : InstallTest ] [ ] = [
161
161
[
162
162
'npm' ,
163
163
{
@@ -182,62 +182,104 @@ const tests: [packageManager: string, config: InstallTest | RunTest][] = [
182
182
lockfile : 'yarn.lock' ,
183
183
} ,
184
184
] ,
185
+ ]
186
+
187
+ describe . each ( installTests ) ( '%s → installs the cli and runs commands without errors' , ( _ , config ) => {
188
+ // TODO: Figure out why this flow is failing on Windows.
189
+ const npxOnWindows = platform ( ) === 'win32' && 'run' in config
190
+
191
+ itWithMockNpmRegistry . skipIf ( npxOnWindows ) ( 'runs the commands without errors' , async ( { registry } ) => {
192
+ // Install
193
+
194
+ const cwd = registry . cwd
195
+ await execa ( ...config . install , {
196
+ cwd,
197
+ env : { npm_config_registry : registry . address } ,
198
+ stdio : debug . enabled ? 'inherit' : 'ignore' ,
199
+ } )
200
+
201
+ expect (
202
+ existsSync ( path . join ( cwd , config . lockfile ) ) ,
203
+ `Generated lock file ${ config . lockfile } does not exist in ${ cwd } ` ,
204
+ ) . toBe ( true )
205
+
206
+ const binary = path . resolve ( path . join ( cwd , `./node_modules/.bin/netlify${ platform ( ) === 'win32' ? '.cmd' : '' } ` ) )
207
+
208
+ // Help
209
+
210
+ const helpOutput = ( await execa ( binary , [ 'help' ] , { cwd } ) ) . stdout
211
+
212
+ expect ( helpOutput . trim ( ) , `Help command does not start with '⬥ Netlify CLI'\\n\\nVERSION: ${ helpOutput } ` ) . toMatch (
213
+ / ^ ⬥ N e t l i f y C L I \n \n V E R S I O N / ,
214
+ )
215
+ expect (
216
+ helpOutput ,
217
+ `Help command does not include '${ config . packageName } /${ pkg . version } ':\n\n${ helpOutput } ` ,
218
+ ) . toContain ( `${ config . packageName } /${ pkg . version } ` )
219
+ expect ( helpOutput , `Help command does not include '$ netlify [COMMAND]':\n\n${ helpOutput } ` ) . toMatch (
220
+ '$ netlify [COMMAND]' ,
221
+ )
222
+
223
+ // Unlink
224
+
225
+ const unlinkOutput = ( await execa ( binary , [ 'unlink' ] , { cwd } ) ) . stdout
226
+ expect ( unlinkOutput , `Unlink command includes command context':\n\n${ unlinkOutput } ` ) . toContain (
227
+ `Run netlify link to link it` ,
228
+ )
229
+ } )
230
+ } )
231
+
232
+ const runTests : [ packageManager : string , config : RunTest ] [ ] = [
185
233
[
186
234
'npx' ,
187
235
{
188
236
packageName : 'netlify' ,
189
237
run : [ 'npx' , [ '-y' , 'netlify@testing' ] ] ,
190
238
} ,
191
239
] ,
240
+ [
241
+ 'pnpx' ,
242
+ {
243
+ packageName : 'netlify' ,
244
+ run : [ 'pnpx' , [ 'netlify@testing' ] ] ,
245
+ } ,
246
+ ] ,
192
247
]
193
248
194
- describe . each ( tests ) ( '%s → installs the cli and runs the help command without error ' , ( _ , config ) => {
249
+ describe . each ( runTests ) ( '%s → runs cli commands without errors ' , ( _ , config ) => {
195
250
// TODO: Figure out why this flow is failing on Windows.
196
251
const npxOnWindows = platform ( ) === 'win32' && 'run' in config
197
252
198
- itWithMockNpmRegistry . skipIf ( npxOnWindows ) (
199
- 'installs the cli and runs the help command without error' ,
200
- async ( { registry } ) => {
201
- const cwd = registry . cwd
202
-
203
- let stdout : string
204
-
205
- if ( 'install' in config ) {
206
- await execa ( ...config . install , {
207
- cwd,
208
- env : { npm_config_registry : registry . address } ,
209
- stdio : debug . enabled ? 'inherit' : 'ignore' ,
210
- } )
211
-
212
- expect (
213
- existsSync ( path . join ( cwd , config . lockfile ) ) ,
214
- `Generated lock file ${ config . lockfile } does not exist in ${ cwd } ` ,
215
- ) . toBe ( true )
216
-
217
- const binary = path . resolve (
218
- path . join ( cwd , `./node_modules/.bin/netlify${ platform ( ) === 'win32' ? '.cmd' : '' } ` ) ,
219
- )
220
- const result = await execa ( binary , [ 'help' ] , { cwd } )
221
-
222
- stdout = result . stdout
223
- } else {
224
- const [ cmd , args ] = config . run
225
- const result = await execa ( cmd , args , {
226
- env : {
227
- npm_config_registry : registry . address ,
228
- } ,
229
- } )
253
+ itWithMockNpmRegistry . skipIf ( npxOnWindows ) ( 'runs commands without errors' , async ( { registry } ) => {
254
+ const [ cmd , args ] = config . run
255
+ const env = {
256
+ npm_config_registry : registry . address ,
257
+ }
230
258
231
- stdout = result . stdout
232
- }
259
+ // Install
233
260
234
- expect ( stdout . trim ( ) , `Help command does not start with '⬥ Netlify CLI'\\n\\nVERSION: ${ stdout } ` ) . toMatch (
235
- / ^ ⬥ N e t l i f y C L I \n \n V E R S I O N / ,
236
- )
237
- expect ( stdout , `Help command does not include '${ config . packageName } /${ pkg . version } ':\n\n${ stdout } ` ) . toContain (
238
- `${ config . packageName } /${ pkg . version } ` ,
239
- )
240
- expect ( stdout , `Help command does not include '$ netlify [COMMAND]':\n\n${ stdout } ` ) . toMatch ( '$ netlify [COMMAND]' )
241
- } ,
242
- )
261
+ await execa ( cmd , [ ...args ] , { env } )
262
+
263
+ // Help
264
+
265
+ const helpOutput = ( await execa ( cmd , [ ...args , 'help' ] , { env } ) ) . stdout
266
+
267
+ expect ( helpOutput . trim ( ) , `Help command does not start with '⬥ Netlify CLI'\\n\\nVERSION: ${ helpOutput } ` ) . toMatch (
268
+ / ^ ⬥ N e t l i f y C L I \n \n V E R S I O N / ,
269
+ )
270
+ expect (
271
+ helpOutput ,
272
+ `Help command does not include '${ config . packageName } /${ pkg . version } ':\n\n${ helpOutput } ` ,
273
+ ) . toContain ( `${ config . packageName } /${ pkg . version } ` )
274
+ expect ( helpOutput , `Help command does not include '$ netlify [COMMAND]':\n\n${ helpOutput } ` ) . toMatch (
275
+ '$ netlify [COMMAND]' ,
276
+ )
277
+
278
+ // Unlink
279
+
280
+ const unlinkOutput = ( await execa ( cmd , [ ...args , 'unlink' ] , { env } ) ) . stdout
281
+ expect ( unlinkOutput , `Unlink command includes command context':\n\n${ unlinkOutput } ` ) . toContain (
282
+ `Run ${ cmd } netlify link to link it` ,
283
+ )
284
+ } )
243
285
} )
0 commit comments