From 11414a72cd8598bae3500a80b68a77440070c2c6 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 9 Nov 2022 09:27:06 +0100 Subject: [PATCH 1/4] improve junit feedback for abritary code errors --- scripts/task.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/task.ts b/scripts/task.ts index cb8d9412e6e6..b40697dac358 100644 --- a/scripts/task.ts +++ b/scripts/task.ts @@ -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 ? { systemErr: [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); @@ -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; From b477e759745fdd929c562b8a98fa3ca2b7afdb9e Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 9 Nov 2022 10:27:03 +0100 Subject: [PATCH 2/4] force an error for test purposes --- scripts/tasks/build.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/tasks/build.ts b/scripts/tasks/build.ts index 8f6acedc2322..18c27e7c5784 100644 --- a/scripts/tasks/build.ts +++ b/scripts/tasks/build.ts @@ -9,6 +9,7 @@ export const build: Task = { return pathExists(builtSandboxDir); }, async run({ sandboxDir }, { dryRun, debug }) { + throw new Error('Problems!'); return exec(`yarn build-storybook --quiet`, { cwd: sandboxDir }, { dryRun, debug }); }, }; From 947b0c349f5890c1d3d42384d1c8f8ee73c24664 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 9 Nov 2022 10:58:11 +0100 Subject: [PATCH 3/4] switch from systemError to just error with a stack --- scripts/task.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/task.ts b/scripts/task.ts index b40697dac358..b65b7372e926 100644 --- a/scripts/task.ts +++ b/scripts/task.ts @@ -183,7 +183,7 @@ async function writeJunitXml( let errorData = {}; if (err) { // we want to distinguish whether the error comes from the tests we are running or from arbitrary code - errorData = systemError ? { systemErr: [err.stack] } : { errors: [err] }; + errorData = systemError ? { errors: [{ message: err.stack }] } : { errors: [err] }; } const name = `${taskKey} - ${templateKey}`; From e796e2f59abaa5da57487adf05f68238ac54a91e Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 9 Nov 2022 11:13:51 +0100 Subject: [PATCH 4/4] remove artificial error --- scripts/tasks/build.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/tasks/build.ts b/scripts/tasks/build.ts index 18c27e7c5784..8f6acedc2322 100644 --- a/scripts/tasks/build.ts +++ b/scripts/tasks/build.ts @@ -9,7 +9,6 @@ export const build: Task = { return pathExists(builtSandboxDir); }, async run({ sandboxDir }, { dryRun, debug }) { - throw new Error('Problems!'); return exec(`yarn build-storybook --quiet`, { cwd: sandboxDir }, { dryRun, debug }); }, };