@@ -70,6 +70,10 @@ const itWithMockNpmRegistry = it.extend<{ registry: { address: string; cwd: stri
70
70
access : '$all' ,
71
71
publish : '$all' ,
72
72
} ,
73
+ netlify : {
74
+ access : '$all' ,
75
+ publish : '$all' ,
76
+ } ,
73
77
'**' : {
74
78
access : '$all' ,
75
79
publish : 'noone' ,
@@ -116,6 +120,20 @@ const itWithMockNpmRegistry = it.extend<{ registry: { address: string; cwd: stri
116
120
cwd : publishWorkspace ,
117
121
stdio : debug . enabled ? 'inherit' : 'ignore' ,
118
122
} )
123
+
124
+ // TODO: Figure out why calling this script is failing on Windows.
125
+ if ( platform ( ) !== 'win32' ) {
126
+ // Publishing `netlify` package
127
+ await execa . node ( path . resolve ( projectRoot , 'scripts/netlifyPackage.js' ) , {
128
+ cwd : publishWorkspace ,
129
+ stdio : debug . enabled ? 'inherit' : 'ignore' ,
130
+ } )
131
+ await execa ( 'npm' , [ 'publish' , `--registry=${ registryURL . toString ( ) } ` , '--tag=testing' ] , {
132
+ cwd : publishWorkspace ,
133
+ stdio : debug . enabled ? 'inherit' : 'ignore' ,
134
+ } )
135
+ }
136
+
119
137
await fs . rm ( publishWorkspace , { force : true , recursive : true } )
120
138
121
139
const testWorkspace = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , tempdirPrefix ) )
@@ -135,53 +153,91 @@ const itWithMockNpmRegistry = it.extend<{ registry: { address: string; cwd: stri
135
153
} ,
136
154
} )
137
155
138
- const tests : [ packageManager : string , config : { install : [ cmd : string , args : string [ ] ] ; lockfile : string } ] [ ] = [
156
+ type Test = { packageName : string }
157
+ type InstallTest = Test & { install : [ cmd : string , args : string [ ] ] ; lockfile : string }
158
+ type RunTest = Test & { run : [ cmd : string , args : string [ ] ] }
159
+
160
+ const tests : [ packageManager : string , config : InstallTest | RunTest ] [ ] = [
139
161
[
140
162
'npm' ,
141
163
{
164
+ packageName : 'netlify-cli' ,
142
165
install : [ 'npm' , [ 'install' , 'netlify-cli@testing' ] ] ,
143
166
lockfile : 'package-lock.json' ,
144
167
} ,
145
168
] ,
146
169
[
147
170
'pnpm' ,
148
171
{
172
+ packageName : 'netlify-cli' ,
149
173
install : [ 'pnpm' , [ 'add' , 'netlify-cli@testing' ] ] ,
150
174
lockfile : 'pnpm-lock.yaml' ,
151
175
} ,
152
176
] ,
153
177
[
154
178
'yarn' ,
155
179
{
180
+ packageName : 'netlify-cli' ,
156
181
install : [ 'yarn' , [ 'add' , 'netlify-cli@testing' ] ] ,
157
182
lockfile : 'yarn.lock' ,
158
183
} ,
159
184
] ,
185
+ [
186
+ 'npx' ,
187
+ {
188
+ packageName : 'netlify' ,
189
+ run : [ 'npx' , [ '-y' , 'netlify@testing' ] ] ,
190
+ } ,
191
+ ] ,
160
192
]
161
193
162
194
describe . each ( tests ) ( '%s → installs the cli and runs the help command without error' , ( _ , config ) => {
163
- itWithMockNpmRegistry ( 'installs the cli and runs the help command without error' , async ( { registry } ) => {
164
- const cwd = registry . cwd
165
- await execa ( ...config . install , {
166
- cwd,
167
- env : { npm_config_registry : registry . address } ,
168
- stdio : debug . enabled ? 'inherit' : 'ignore' ,
169
- } )
195
+ // TODO: Figure out why this flow is failing on Windows.
196
+ const npxOnWindows = platform ( ) === 'win32' && 'run' in config
170
197
171
- expect (
172
- existsSync ( path . join ( cwd , config . lockfile ) ) ,
173
- `Generated lock file ${ config . lockfile } does not exist in ${ cwd } ` ,
174
- ) . toBe ( true )
198
+ itWithMockNpmRegistry . skipIf ( npxOnWindows ) (
199
+ 'installs the cli and runs the help command without error' ,
200
+ async ( { registry } ) => {
201
+ const cwd = registry . cwd
175
202
176
- const binary = path . resolve ( path . join ( cwd , `./node_modules/.bin/netlify${ platform ( ) === 'win32' ? '.cmd' : '' } ` ) )
177
- const { stdout } = await execa ( binary , [ 'help' ] , { cwd } )
203
+ let stdout : string
178
204
179
- expect ( stdout . trim ( ) , `Help command does not start with '⬥ Netlify CLI'\\n\\nVERSION: ${ stdout } ` ) . toMatch (
180
- / ^ ⬥ N e t l i f y C L I \n \n V E R S I O N / ,
181
- )
182
- expect ( stdout , `Help command does not include 'netlify-cli/${ pkg . version } ':\n\n${ stdout } ` ) . toContain (
183
- `netlify-cli/${ pkg . version } ` ,
184
- )
185
- expect ( stdout , `Help command does not include '$ netlify [COMMAND]':\n\n${ stdout } ` ) . toMatch ( '$ netlify [COMMAND]' )
186
- } )
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
+ } )
230
+
231
+ stdout = result . stdout
232
+ }
233
+
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
+ )
187
243
} )
0 commit comments