Skip to content

Commit

Permalink
Merge pull request #19786 from storybookjs/chore/improve-error-feedback
Browse files Browse the repository at this point in the history
Maintenance: improve error feedback when tasks fail in CI
  • Loading branch information
yannbf authored Nov 9, 2022
2 parents 6e927f3 + e796e2f commit 49d26da
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scripts/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,18 @@ async function writeJunitXml(
taskKey: TaskKey,
templateKey: TemplateKey,
startTime: Date,
err?: Error
err?: Error,
systemError?: boolean
) {
let errorData = {};
if (err) {
// we want to distinguish whether the error comes from the tests we are running or from arbitrary code
errorData = systemError ? { errors: [{ message: err.stack }] } : { errors: [err] };
}

const name = `${taskKey} - ${templateKey}`;
const time = (Date.now() - +startTime) / 1000;
const testCase = { name, assertions: 1, time, ...(err && { errors: [err] }) };
const testCase = { name, assertions: 1, time, ...errorData };
const suite = { name, timestamp: startTime, time, testCases: [testCase] };
const junitXml = getJunitXml({ time, name, suites: [suite] });
const path = getJunitFilename(taskKey);
Expand Down Expand Up @@ -282,7 +289,7 @@ async function runTask(task: Task, details: TemplateDetails, optionValues: Passe
const hasJunitFile = await pathExists(junitFilename);
// If there's a non-test related error (junit report has not been reported already), we report the general failure in a junit report
if (junitFilename && !hasJunitFile) {
await writeJunitXml(getTaskKey(task), details.key, startTime, err);
await writeJunitXml(getTaskKey(task), details.key, startTime, err, true);
}

throw err;
Expand Down

0 comments on commit 49d26da

Please sign in to comment.