From 7a0fbd042d10a251d73e8f4624fd95518af7c080 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Mon, 3 Mar 2025 15:27:56 -0800 Subject: [PATCH] cherry-pick(#35002): chore: differentiate test.skip and step.skip --- packages/playwright/src/worker/testInfo.ts | 13 ++++++++----- packages/playwright/src/worker/workerMain.ts | 6 +++--- tests/playwright-test/test-step.spec.ts | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.ts index 72bb9fb025..ba0fb789ea 100644 --- a/packages/playwright/src/worker/testInfo.ts +++ b/packages/playwright/src/worker/testInfo.ts @@ -220,7 +220,7 @@ export class TestInfoImpl implements TestInfo { this._timeoutManager.slow(); } else if (type === 'skip' || type === 'fixme') { this.expectedStatus = 'skipped'; - throw new SkipError('Test is skipped: ' + (description || '')); + throw new TestSkipError('Test is skipped: ' + (description || '')); } else if (type === 'fail') { if (this.expectedStatus !== 'skipped') this.expectedStatus = 'failed'; @@ -363,7 +363,7 @@ export class TestInfoImpl implements TestInfo { try { await cb(); } catch (e) { - if (this._allowSkips && (e instanceof SkipError)) { + if (this._allowSkips && (e instanceof TestSkipError)) { if (this.status === 'passed') this.status = 'skipped'; } else { @@ -523,7 +523,7 @@ export class TestStepInfoImpl implements TestStepInfo { try { return await body(this); } catch (e) { - if (e instanceof SkipError) + if (e instanceof StepSkipError) return undefined as T; throw e; } @@ -544,11 +544,14 @@ export class TestStepInfoImpl implements TestStepInfo { return; const description = args[1] as (string|undefined); this.annotations.push({ type: 'skip', description }); - throw new SkipError(description); + throw new StepSkipError(description); } } -export class SkipError extends Error { +export class TestSkipError extends Error { +} + +export class StepSkipError extends Error { } const stepSymbol = Symbol('step'); diff --git a/packages/playwright/src/worker/workerMain.ts b/packages/playwright/src/worker/workerMain.ts index 126d3c8052..9b61c4b0b0 100644 --- a/packages/playwright/src/worker/workerMain.ts +++ b/packages/playwright/src/worker/workerMain.ts @@ -22,7 +22,7 @@ import { setCurrentTestInfo, setIsWorkerProcess } from '../common/globals'; import { stdioChunkToParams } from '../common/ipc'; import { debugTest, relativeFilePath } from '../util'; import { FixtureRunner } from './fixtureRunner'; -import { SkipError, TestInfoImpl } from './testInfo'; +import { TestSkipError, TestInfoImpl } from './testInfo'; import { testInfoError } from './util'; import { inheritFixtureNames } from '../common/fixtures'; import { PoolBuilder } from '../common/poolBuilder'; @@ -558,7 +558,7 @@ export class WorkerMain extends ProcessRunner { } catch (error) { firstError = firstError ?? error; // Skip in beforeAll/modifier prevents others from running. - if (type === 'beforeAll' && (error instanceof SkipError)) + if (type === 'beforeAll' && (error instanceof TestSkipError)) break; if (type === 'beforeAll' && !this._skipRemainingTestsInSuite) { // This will inform dispatcher that we should not run more tests from this group @@ -596,7 +596,7 @@ export class WorkerMain extends ProcessRunner { } catch (error) { firstError = firstError ?? error; // Skip in modifier prevents others from running. - if (error instanceof SkipError) + if (error instanceof TestSkipError) break; } } diff --git a/tests/playwright-test/test-step.spec.ts b/tests/playwright-test/test-step.spec.ts index bd6ad61261..5ac57a6bce 100644 --- a/tests/playwright-test/test-step.spec.ts +++ b/tests/playwright-test/test-step.spec.ts @@ -1628,6 +1628,25 @@ hook |After Hooks `); }); +test('should differentiate test.skip and step.skip', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'reporter.ts': stepIndentReporter, + 'playwright.config.ts': `module.exports = { reporter: './reporter' };`, + 'a.test.ts': ` + import { test, expect } from '@playwright/test'; + test('test', async ({ }) => { + await test.step('outer step', async () => { + await test.info().skip(); + }); + }); + ` + }, { reporter: '' }); + + expect(result.exitCode).toBe(0); + expect(result.report.stats.expected).toBe(0); + expect(result.report.stats.unexpected).toBe(0); + expect(result.report.stats.skipped).toBe(1); +}); test('show api calls inside expects', async ({ runInlineTest }) => { const result = await runInlineTest({