Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: improve debugability of installation tests (#17277)

Dmitry Gozman68072a5d5c21
diff --git a/tests/installation/npmTest.ts b/tests/installation/npmTest.ts
index 7e086c1071..17db9b7481 100644
--- a/tests/installation/npmTest.ts
+++ b/tests/installation/npmTest.ts
@@ -139,27 +139,30 @@ export const test = _test.extend<{
});
});
- const stdio = `${result.stdout}\n${result.stderr}`;
-
- await testInfo.attach(`${[cmd, ...args].join(' ')}`, { body: `COMMAND: ${[cmd, ...args].join(' ')}\n\nEXIT CODE: ${result.code}\n\n====== STDIO + STDERR ======\n\n${stdio}` });
+ const command = [cmd, ...args].join(' ');
+ const stdio = result.stdout + result.stderr;
+ await testInfo.attach(command, { body: `COMMAND: ${command}\n\nEXIT CODE: ${result.code}\n\n====== STDOUT + STDERR ======\n\n${stdio}` });
// This means something is really off with spawn
if (result.error)
throw result.error;
- // User expects command to fail
- if (options.expectToExitWithError) {
- if (result.code === 0) {
- const message = options.message ? ` Message: ${options.message}` : '';
- throw new Error(`Expected the command to exit with an error, but exited cleanly.${message}`);
- }
- } else if (result.code !== 0) {
- const message = options.message ? ` Message: ${options.message}` : '';
- throw new Error(`Expected the command to exit cleanly (0 status code), but exited with ${result.code}.${message}`);
- }
+ const error: string[] = [];
+ if (options.expectToExitWithError && result.code === 0)
+ error.push(`Expected the command to exit with an error, but exited cleanly.`);
+ else if (!options.expectToExitWithError && result.code !== 0)
+ error.push(`Expected the command to exit cleanly (0 status code), but exited with ${result.code}.`);
+
+ if (!error.length)
+ return stdio;
- return stdio;
+ if (options.message)
+ error.push(`Message: ${options.message}`);
+ error.push(`Command: ${command}`);
+ error.push(`EXIT CODE: ${result.code}`);
+ error.push(`====== STDIO ======\n${stdio}`);
+ throw new Error(error.join('\n'));
});
},
tsc: async ({ exec }, use) => {