unit tests - help diagnose test failure reason for web tests (#155967)

This commit is contained in:
Benjamin Pasero 2022-07-22 18:50:34 +02:00 committed by GitHub
parent 0c4187895d
commit 86e7410278
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -150,6 +150,8 @@ async function runTestsInBrowser(testModules, browserType) {
const failingModuleIds = [];
const failingTests = [];
emitter.on('fail', (test, err) => {
failingTests.push({ title: test.fullTitle, message: err.message });
if (err.stack) {
const regex = /(vs\/.*\.test)\.js/;
for (const line of String(err.stack).split('\n')) {
@ -160,9 +162,6 @@ async function runTestsInBrowser(testModules, browserType) {
}
}
}
// We could not determine the module id
failingTests.push(test.fullTitle);
});
try {
@ -176,11 +175,14 @@ async function runTestsInBrowser(testModules, browserType) {
}
await browser.close();
if (failingModuleIds.length > 0) {
return `to DEBUG, open ${browserType.toUpperCase()} and navigate to ${target.href}?${failingModuleIds.map(module => `m=${module}`).join('&')}`;
}
if (failingTests.length > 0) {
return `The followings tests are failing:\n - ${failingTests.join('\n - ')}`;
let res = `The followings tests are failing:\n - ${failingTests.map(({ title, message }) => `${title} (reason: ${message})`).join('\n - ')}`;
if (failingModuleIds.length > 0) {
res += `\n\nTo DEBUG, open ${browserType.toUpperCase()} and navigate to ${target.href}?${failingModuleIds.map(module => `m=${module}`).join('&')}`;
}
return `${res}\n`;
}
}