test: improve debugability of installation tests (#17277)

Put more details into the error message. This way it is immediately seen
on the bots.
This commit is contained in:
Dmitry Gozman 2022-09-13 14:43:11 -07:00 committed by GitHub
parent 705bc28e92
commit 68072a5d5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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}.`);
return stdio;
if (!error.length)
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) => {