Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: differentiate test.skip and step.skip (#35002)

Pavel Feldman85c64050936f
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({