From 4fdc8317a05307b900dc91f349ec0d656d47850d Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Tue, 8 Nov 2022 11:49:59 +0100 Subject: [PATCH 1/3] provide expected failure metadata in junit reports --- .gitignore | 1 + code/playwright.config.ts | 12 +++++++++++- scripts/tasks/e2e-tests.ts | 4 +--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index fd7ec6ed6ee8..41baa60da98e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ dist *.DS_Store .cache junit.xml +test-results /repros /sandbox .verdaccio-cache diff --git a/code/playwright.config.ts b/code/playwright.config.ts index 65bd48e564e7..71ca6340d87d 100644 --- a/code/playwright.config.ts +++ b/code/playwright.config.ts @@ -30,7 +30,17 @@ const config: PlaywrightTestConfig = { /* Opt out of parallel tests on CI. */ workers: process.env.CI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: 'html', + reporter: process.env.PLAYWRIGHT_JUNIT_OUTPUT_NAME + ? [ + [ + 'junit', + { + embedAnnotationsAsProperties: true, + outputFile: process.env.PLAYWRIGHT_JUNIT_OUTPUT_NAME, + }, + ], + ] + : 'html', /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ diff --git a/scripts/tasks/e2e-tests.ts b/scripts/tasks/e2e-tests.ts index 8834737ba942..6aff99855a1b 100644 --- a/scripts/tasks/e2e-tests.ts +++ b/scripts/tasks/e2e-tests.ts @@ -10,10 +10,8 @@ export const e2eTests: Task = { return false; }, async run({ codeDir, junitFilename, template }, { dryRun, debug }) { - const reporter = process.env.CI ? 'junit' : 'html'; - await exec( - `yarn playwright test --reporter=${reporter}`, + `yarn playwright test`, { env: { STORYBOOK_URL: `http://localhost:${PORT}`, From 28e8c4ed1d1e6c61d2272046f74f1c125ec537ff Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Tue, 8 Nov 2022 11:53:27 +0100 Subject: [PATCH 2/3] tasks: skip writing junit no failure if it has already been reported --- scripts/task.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/task.ts b/scripts/task.ts index 01cc2e48a8ce..183f9bfd48d6 100644 --- a/scripts/task.ts +++ b/scripts/task.ts @@ -1,5 +1,5 @@ /* eslint-disable no-await-in-loop */ -import { AbortController } from 'node-abort-controller'; +import type { AbortController } from 'node-abort-controller'; import { getJunitXml } from 'junit-xml'; import { outputFile, existsSync, readFile } from 'fs-extra'; import { join, resolve } from 'path'; @@ -7,7 +7,8 @@ import { prompt } from 'prompts'; import boxen from 'boxen'; import { dedent } from 'ts-dedent'; -import { createOptions, getCommand, getOptionsOrPrompt, OptionValues } from './utils/options'; +import type { OptionValues } from './utils/options'; +import { createOptions, getCommand, getOptionsOrPrompt } from './utils/options'; import { install } from './tasks/install'; import { compile } from './tasks/compile'; import { check } from './tasks/check'; @@ -278,7 +279,10 @@ async function runTask(task: Task, details: TemplateDetails, optionValues: Passe return controller; } catch (err) { - if (junitFilename) await writeJunitXml(getTaskKey(task), details.key, startTime, err); + // 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 && !existsSync(junitFilename)) { + await writeJunitXml(getTaskKey(task), details.key, startTime, err); + } throw err; } finally { From 79cfb853b70785314241a28813dff6323c449415 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Tue, 8 Nov 2022 18:28:27 +0100 Subject: [PATCH 3/3] task: turn file checks into async --- scripts/task.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/task.ts b/scripts/task.ts index 183f9bfd48d6..cf91142c1fef 100644 --- a/scripts/task.ts +++ b/scripts/task.ts @@ -1,7 +1,7 @@ /* eslint-disable no-await-in-loop */ import type { AbortController } from 'node-abort-controller'; import { getJunitXml } from 'junit-xml'; -import { outputFile, existsSync, readFile } from 'fs-extra'; +import { outputFile, readFile, pathExists } from 'fs-extra'; import { join, resolve } from 'path'; import { prompt } from 'prompts'; import boxen from 'boxen'; @@ -279,14 +279,15 @@ async function runTask(task: Task, details: TemplateDetails, optionValues: Passe return controller; } catch (err) { + 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 && !existsSync(junitFilename)) { + if (junitFilename && !hasJunitFile) { await writeJunitXml(getTaskKey(task), details.key, startTime, err); } throw err; } finally { - if (existsSync(junitFilename)) { + if (await pathExists(junitFilename)) { const junitXml = await (await readFile(junitFilename)).toString(); const prefixedXml = junitXml.replace(/classname="(.*)"/g, `classname="${details.key} $1"`); await outputFile(junitFilename, prefixedXml);