From feeee1cd3a6904b0f5e57a0cfe2476754d20e598 Mon Sep 17 00:00:00 2001 From: shadowusr <58862284+shadowusr@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:25:30 +0300 Subject: [PATCH] fix: fix skipped/total tests counters when there are retried skipped tests (#511) * fix: fix skipped tests counter when there are retries --- lib/tests-tree-builder/static.ts | 39 ++++++++++++------- .../playwright/tests/success-describe.spec.ts | 8 +--- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/tests-tree-builder/static.ts b/lib/tests-tree-builder/static.ts index f8ccbf816..9987834b3 100644 --- a/lib/tests-tree-builder/static.ts +++ b/lib/tests-tree-builder/static.ts @@ -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); @@ -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[] } { @@ -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(); @@ -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; @@ -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++; @@ -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++; @@ -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++; @@ -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, @@ -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; diff --git a/test/func/fixtures/playwright/tests/success-describe.spec.ts b/test/func/fixtures/playwright/tests/success-describe.spec.ts index 5a38ae2a3..d9d3e9ae5 100644 --- a/test/func/fixtures/playwright/tests/success-describe.spec.ts +++ b/test/func/fixtures/playwright/tests/success-describe.spec.ts @@ -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'); - // }); });