Skip to content

Commit

Permalink
fix: playwright reporter (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
devpow112 authored Jan 4, 2024
1 parent 36b7219 commit bd989c4
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/reporters/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,28 @@ import { writeFile } from 'fs/promises';
const { cyan, red, yellow } = colors;

const getProject = (config, test) => {
const [, projectName] = test.titlePath();
const { projects } = config;
const [, projectName] = test.titlePath();

return projects.find(({ name }) => name === projectName);
};

const convertEndStateSummary = (state) => {
if (!['passed', 'failed'].includes(state)) {
return 'failed';
}

return state;
};

const convertEndStateDetails = (state) => {
if (!['passed', 'failed', 'skipped'].includes(state)) {
return 'failed';
}

return state;
};

const makeTestName = (test) => {
const [, projectName, , ...titles] = test.titlePath();
const titlePaths = projectName ? [projectName, ...titles] : titles;
Expand Down Expand Up @@ -60,18 +76,19 @@ export default class Reporter {
}

onTestEnd(test, result) {
const { startTime, retry, status, duration } = result;
const { id, location: { file } } = test;
const values = this._tests.get(id) ?? {};

values.name = makeTestName(test);
values.started = values.started ?? result.startTime;
values.started = values.started ?? startTime;
values.location = values.location ?? makeLocation(file);
values.retries = result.retry;
values.status = result.status;
values.duration = result.duration;
values.retries = retry;
values.status = convertEndStateDetails(status);
values.duration = duration;
values.totalDuration = values.totalDuration === undefined ?
result.duration :
values.totalDuration + result.duration;
duration :
values.totalDuration + duration;

if (values.browser === undefined) {
const { use: { defaultBrowserType } } = getProject(this._config, test);
Expand All @@ -83,9 +100,11 @@ export default class Reporter {
}

onEnd(result) {
this._report.summary.started = result.startTime;
this._report.summary.totalDuration = Math.round(result.duration);
this._report.summary.status = result.status;
const { startTime, duration, status } = result;

this._report.summary.started = startTime;
this._report.summary.totalDuration = Math.round(duration);
this._report.summary.status = convertEndStateSummary(status);

let countPassed = 0;
let countFailed = 0;
Expand Down

0 comments on commit bd989c4

Please sign in to comment.