Skip to content

Commit

Permalink
fix: fix skipped/total tests counters when there are retried skipped …
Browse files Browse the repository at this point in the history
…tests (#511)

* fix: fix skipped tests counter when there are retries
  • Loading branch information
shadowusr authored Oct 4, 2023
1 parent b1d06fb commit feeee1c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
39 changes: 25 additions & 14 deletions lib/tests-tree-builder/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export interface StaticTestsTreeBuilderOptions extends BaseTestsTreeBuilderOptio
export class StaticTestsTreeBuilder extends BaseTestsTreeBuilder {
protected _stats: FinalStats;
protected _skips: SkipItem[];
protected _failedBrowserIds: { [key: string]: boolean };
protected _passedBrowserIds: { [key: string]: boolean };
protected _failedTestIds: { [key: string]: boolean };
protected _passedTestIds: { [key: string]: boolean };
protected _skippedTestIds: { [key: string]: boolean };

constructor(options: StaticTestsTreeBuilderOptions) {
super(options);
Expand All @@ -47,8 +48,9 @@ export class StaticTestsTreeBuilder extends BaseTestsTreeBuilder {
perBrowser: {}
};
this._skips = [];
this._failedBrowserIds = {};
this._passedBrowserIds = {};
this._failedTestIds = {};
this._passedTestIds = {};
this._skippedTestIds = {};
}

build(rows: RawSuitesRow[] = []): { tree: Tree; stats: FinalStats; skips: SkipItem[]; browsers: BrowserItem[] } {
Expand All @@ -71,7 +73,7 @@ export class StaticTestsTreeBuilder extends BaseTestsTreeBuilder {
addBrowserVersion(browsers, testResult);

this.addTestResult(testResult, formattedResult);
this._calcStats(testResult, {testId, browserId, browserName});
this._calcStats(testResult, {testId, browserName});
}

this.sortTree();
Expand All @@ -88,7 +90,8 @@ export class StaticTestsTreeBuilder extends BaseTestsTreeBuilder {
this._tree.browsers.byId[browserId].resultIds.push(testResultId);
}

protected _calcStats(testResult: ParsedSuitesRow, {testId, browserId, browserName}: { testId: string; browserId: string; browserName: string }): void {
protected _calcStats(testResult: ParsedSuitesRow, {testId, browserName}: { testId: string; browserName: string }): void {
const testIdWithBrowser = this._buildId(testId, browserName);
const {status} = testResult;
const {browserVersion} = testResult.metaInfo;
const version = browserVersion || BrowserVersions.UNKNOWN;
Expand All @@ -104,13 +107,13 @@ export class StaticTestsTreeBuilder extends BaseTestsTreeBuilder {
switch (status) {
case TestStatus.FAIL:
case TestStatus.ERROR: {
if (this._failedBrowserIds[browserId]) {
if (this._failedTestIds[testIdWithBrowser]) {
this._stats.retries++;
this._stats.perBrowser[browserName][version].retries++;
return;
}

this._failedBrowserIds[browserId] = true;
this._failedTestIds[testIdWithBrowser] = true;
this._stats.failed++;
this._stats.total++;
this._stats.perBrowser[browserName][version].failed++;
Expand All @@ -119,14 +122,14 @@ export class StaticTestsTreeBuilder extends BaseTestsTreeBuilder {
}

case TestStatus.SUCCESS: {
if (this._passedBrowserIds[browserId]) {
if (this._passedTestIds[testIdWithBrowser]) {
this._stats.retries++;
this._stats.perBrowser[browserName][version].retries++;
return;
}

if (this._failedBrowserIds[browserId]) {
delete this._failedBrowserIds[browserId];
if (this._failedTestIds[testIdWithBrowser]) {
delete this._failedTestIds[testIdWithBrowser];
this._stats.failed--;
this._stats.passed++;
this._stats.retries++;
Expand All @@ -137,7 +140,7 @@ export class StaticTestsTreeBuilder extends BaseTestsTreeBuilder {
return;
}

this._passedBrowserIds[browserId] = true;
this._passedTestIds[testIdWithBrowser] = true;
this._stats.passed++;
this._stats.total++;
this._stats.perBrowser[browserName][version].passed++;
Expand All @@ -147,6 +150,14 @@ export class StaticTestsTreeBuilder extends BaseTestsTreeBuilder {
}

case TestStatus.SKIPPED: {
if (this._skippedTestIds[testIdWithBrowser]) {
this._stats.retries++;
this._stats.perBrowser[browserName][version].retries++;
return;
}

this._skippedTestIds[testIdWithBrowser] = true;

this._skips.push({
browser: browserName,
suite: testId,
Expand All @@ -156,8 +167,8 @@ export class StaticTestsTreeBuilder extends BaseTestsTreeBuilder {
this._stats.skipped++;
this._stats.perBrowser[browserName][version].skipped++;

if (this._failedBrowserIds[browserId]) {
delete this._failedBrowserIds[browserId];
if (this._failedTestIds[testIdWithBrowser]) {
delete this._failedTestIds[testIdWithBrowser];
this._stats.failed--;
this._stats.perBrowser[browserName][version].failed--;
return;
Expand Down
8 changes: 1 addition & 7 deletions test/func/fixtures/playwright/tests/success-describe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import {test, expect} from '@playwright/test';
import {test} from '@playwright/test';

test.describe('success describe', () => {
test('successfully passed test', async ({page, baseURL}) => {
await page.goto(baseURL as string);
});

// test('test with screenshot', async ({page, baseURL}) => {
// await page.goto(baseURL as string);
//
// await expect(page.locator('header')).toHaveScreenshot('header.png');
// });
});

0 comments on commit feeee1c

Please sign in to comment.