Skip to content

Commit c92f9b0

Browse files
serhalpndhoule
authored andcommitted
test(e2e): actually log child proc output on failure
1 parent 49f8ce8 commit c92f9b0

File tree

1 file changed

+64
-11
lines changed

1 file changed

+64
-11
lines changed

e2e/install.e2e.ts

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,37 +202,59 @@ const installTests: [packageManager: string, config: InstallTest][] = [
202202
],
203203
]
204204

205-
describe.each(installTests)('%s → installs the cli and runs commands without errors', (_, config) => {
205+
describe.each(installTests)('%s → installs the cli and runs commands without errors', (packageManager, config) => {
206206
// TODO: Figure out why this flow is failing on Windows.
207207
const npxOnWindows = platform() === 'win32' && 'run' in config
208208

209209
itWithMockNpmRegistry.skipIf(npxOnWindows)('runs the commands without errors', async ({ registry }) => {
210210
// Install
211211

212212
const cwd = registry.cwd
213-
await execa(...config.install, {
213+
const installResult = await execa(...config.install, {
214214
cwd,
215215
env: { npm_config_registry: registry.address },
216-
stdio: debug.enabled ? 'inherit' : 'ignore',
216+
all: true,
217+
reject: false,
217218
})
219+
if (installResult.exitCode !== 0) {
220+
throw new Error(
221+
`Install failed for ${packageManager}\nExit code: ${installResult.exitCode.toString()}\n\n${
222+
installResult.all || ''
223+
}`,
224+
)
225+
}
218226

219227
expect(
220228
existsSync(path.join(cwd, config.lockfile)),
221229
`Generated lock file ${config.lockfile} does not exist in ${cwd}`,
222230
).toBe(true)
223231

224232
// Regression test: ensure we don't trigger known `npm ci` bugs: https://github.com/npm/cli/issues/7622.
225-
await execa(...config.cleanInstall, {
233+
const cleanInstallResult = await execa(...config.cleanInstall, {
226234
cwd,
227235
env: { npm_config_registry: registry.address },
228-
stdio: debug.enabled ? 'inherit' : 'ignore',
236+
all: true,
237+
reject: false,
229238
})
239+
if (cleanInstallResult.exitCode !== 0) {
240+
throw new Error(
241+
`Clean install failed for ${packageManager}\nExit code: ${cleanInstallResult.exitCode.toString()}\n\n${
242+
cleanInstallResult.all || ''
243+
}`,
244+
)
245+
}
230246

231247
const binary = path.resolve(path.join(cwd, `./node_modules/.bin/netlify${platform() === 'win32' ? '.cmd' : ''}`))
232248

233249
// Help
234250

235-
const helpOutput = (await execa(binary, ['help'], { cwd })).stdout
251+
const helpResult = await execa(binary, ['help'], { cwd, all: true, reject: false })
252+
if (helpResult.exitCode !== 0) {
253+
throw new Error(
254+
`Help command failed: ${binary} help\nExit code: ${helpResult.exitCode.toString()}\n\n${helpResult.all || ''}`,
255+
)
256+
}
257+
const helpOutput = helpResult.stdout
236258

237259
expect(helpOutput.trim(), `Help command does not start with '⬥ Netlify CLI'\\n\\nVERSION: ${helpOutput}`).toMatch(
238260
/^ Netlify CLI\n\nVERSION/,
@@ -247,7 +269,15 @@ describe.each(installTests)('%s → installs the cli and runs commands without e
247269

248270
// Unlink
249271

250-
const unlinkOutput = (await execa(binary, ['unlink'], { cwd })).stdout
272+
const unlinkResult = await execa(binary, ['unlink'], { cwd, all: true, reject: false })
273+
if (unlinkResult.exitCode !== 0) {
274+
throw new Error(
275+
`Unlink command failed: ${binary} unlink\nExit code: ${unlinkResult.exitCode.toString()}\n\n${
276+
unlinkResult.all || ''
277+
}`,
278+
)
279+
}
280+
const unlinkOutput = unlinkResult.stdout
251281
expect(unlinkOutput, `Unlink command includes command context':\n\n${unlinkOutput}`).toContain(
252282
`Run netlify link to link it`,
253283
)
@@ -271,7 +301,7 @@ const runTests: [packageManager: string, config: RunTest][] = [
271301
],
272302
]
273303

274-
describe.each(runTests)('%s → runs cli commands without errors', (_, config) => {
304+
describe.each(runTests)('%s → runs cli commands without errors', (packageManager, config) => {
275305
// TODO: Figure out why this flow is failing on Windows.
276306
const npxOnWindows = platform() === 'win32' && 'run' in config
277307

@@ -283,11 +313,26 @@ describe.each(runTests)('%s → runs cli commands without errors', (_, config) =
283313

284314
// Install
285315

286-
await execa(cmd, [...args], { env })
316+
const installResult = await execa(cmd, [...args], { env, all: true, reject: false })
317+
if (installResult.exitCode !== 0) {
318+
throw new Error(
319+
`Install failed for ${packageManager}\nExit code: ${installResult.exitCode.toString()}\n\n${
320+
installResult.all || ''
321+
}`,
322+
)
323+
}
287324

288325
// Help
289326

290-
const helpOutput = (await execa(cmd, [...args, 'help'], { env })).stdout
327+
const helpResult = await execa(cmd, [...args, 'help'], { env, all: true, reject: false })
328+
if (helpResult.exitCode !== 0) {
329+
throw new Error(
330+
`Help command failed: ${cmd} ${args.join(' ')} help\nExit code: ${helpResult.exitCode.toString()}\n\n${
331+
helpResult.all || ''
332+
}`,
333+
)
334+
}
335+
const helpOutput = helpResult.stdout
291336

292337
expect(helpOutput.trim(), `Help command does not start with '⬥ Netlify CLI'\\n\\nVERSION: ${helpOutput}`).toMatch(
293338
/^ Netlify CLI\n\nVERSION/,
@@ -302,7 +347,15 @@ describe.each(runTests)('%s → runs cli commands without errors', (_, config) =
302347

303348
// Unlink
304349

305-
const unlinkOutput = (await execa(cmd, [...args, 'unlink'], { env })).stdout
350+
const unlinkResult = await execa(cmd, [...args, 'unlink'], { env, all: true, reject: false })
351+
if (unlinkResult.exitCode !== 0) {
352+
throw new Error(
353+
`Unlink command failed: ${cmd} ${args.join(' ')} unlink\nExit code: ${unlinkResult.exitCode.toString()}\n\n${
354+
unlinkResult.all || ''
355+
}`,
356+
)
357+
}
358+
const unlinkOutput = unlinkResult.stdout
306359
expect(unlinkOutput, `Unlink command includes command context':\n\n${unlinkOutput}`).toContain(
307360
`Run ${cmd} netlify link to link it`,
308361
)

0 commit comments

Comments
 (0)