Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: provide expected failure metadata in junit reports #19775

Merged
merged 3 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dist
*.DS_Store
.cache
junit.xml
test-results
/repros
/sandbox
.verdaccio-cache
Expand Down
12 changes: 11 additions & 1 deletion code/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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). */
Expand Down
15 changes: 10 additions & 5 deletions scripts/task.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* 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 { outputFile, readFile, pathExists } from 'fs-extra';
import { join, resolve } from 'path';
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';
Expand Down Expand Up @@ -278,11 +279,15 @@ async function runTask(task: Task, details: TemplateDetails, optionValues: Passe

return controller;
} catch (err) {
if (junitFilename) await writeJunitXml(getTaskKey(task), details.key, startTime, 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 && !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);
Expand Down
4 changes: 1 addition & 3 deletions scripts/tasks/e2e-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down