Skip to content

Commit

Permalink
Merge pull request #19775 from storybookjs/chore/add-e2e-test-metadata
Browse files Browse the repository at this point in the history
Maintenance: provide expected failure metadata in junit reports
  • Loading branch information
yannbf authored Nov 8, 2022
2 parents 226f9a4 + 79cfb85 commit 6a9ecf0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
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

0 comments on commit 6a9ecf0

Please sign in to comment.