Skip to content

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

feat: `onTestPaused` (#38475)

Simon Knott3ad540dc4504
diff --git a/packages/playwright/src/common/ipc.ts b/packages/playwright/src/common/ipc.ts
index ddbfeeb8bd..91a201dbb8 100644
--- a/packages/playwright/src/common/ipc.ts
+++ b/packages/playwright/src/common/ipc.ts
@@ -88,9 +88,14 @@ export type TestInfoErrorImpl = TestInfoError;
export type TestPausedPayload = {
testId: string;
+ stepId: string;
errors: TestInfoErrorImpl[];
};
+export type ResumePayload = {
+ action?: 'continue' | 'abort';
+};
+
export type GetStorageValuePayload = {
fileName: string;
key: string;
diff --git a/packages/playwright/src/isomorphic/teleReceiver.ts b/packages/playwright/src/isomorphic/teleReceiver.ts
index cef009c730..2319d5ba72 100644
--- a/packages/playwright/src/isomorphic/teleReceiver.ts
+++ b/packages/playwright/src/isomorphic/teleReceiver.ts
@@ -132,7 +132,7 @@ export type JsonFullResult = {
};
export type JsonEvent = JsonOnConfigureEvent | JsonOnBlobReportMetadataEvent | JsonOnEndEvent | JsonOnExitEvent | JsonOnProjectEvent | JsonOnBeginEvent | JsonOnTestBeginEvent
- | JsonOnTestEndEvent | JsonOnStepBeginEvent | JsonOnStepEndEvent | JsonOnAttachEvent | JsonOnErrorEvent | JsonOnStdIOEvent;
+ | JsonOnTestEndEvent | JsonOnStepBeginEvent | JsonOnStepEndEvent | JsonOnAttachEvent | JsonOnErrorEvent | JsonOnTestPausedEvent | JsonOnStdIOEvent;
export type JsonOnConfigureEvent = {
method: 'onConfigure';
@@ -166,6 +166,16 @@ export type JsonOnTestBeginEvent = {
};
};
+export type JsonOnTestPausedEvent = {
+ method: 'onTestPaused';
+ params: {
+ testId: string;
+ resultId: string;
+ stepId: string;
+ errors: reporterTypes.TestError[];
+ };
+};
+
export type JsonOnTestEndEvent = {
method: 'onTestEnd';
params: {
@@ -282,6 +292,10 @@ export class TeleReporterReceiver {
this._onTestBegin(params.testId, params.result);
return;
}
+ if (method === 'onTestPaused') {
+ this._onTestPaused(params.testId, params.resultId, params.stepId, params.errors);
+ return;
+ }
if (method === 'onTestEnd') {
this._onTestEnd(params.test, params.result);
return;
@@ -346,6 +360,16 @@ export class TeleReporterReceiver {
this._reporter.onTestBegin?.(test, testResult);
}
+ private _onTestPaused(testId: string, resultId: string, stepId: string, errors: reporterTypes.TestError[]) {
+ const test = this._tests.get(testId)!;
+ const result = test.results.find(r => r._id === resultId)!;
+ const step = result._stepMap.get(stepId)!;
+
+ result.errors.push(...errors);
+ result.error = result.errors[0];
+ void this._reporter.onTestPaused?.(test, result, step);
+ }
+
private _onTestEnd(testEndPayload: JsonTestEnd, payload: JsonTestResultEnd) {
const test = this._tests.get(testEndPayload.testId)!;
test.timeout = testEndPayload.timeout;
@@ -353,8 +377,8 @@ export class TeleReporterReceiver {
const result = test.results.find(r => r._id === payload.id)!;
result.duration = payload.duration;
result.status = payload.status;
- result.errors = payload.errors;
- result.error = result.errors?.[0];
+ result.errors.push(...payload.errors ?? []);
+ result.error = result.errors[0];
// Attachments are only present here from legacy blobs. These override all _onAttach events
if (!!payload.attachments)
result.attachments = this._parseAttachments(payload.attachments);
diff --git a/packages/playwright/src/reporters/blob.ts b/packages/playwright/src/reporters/blob.ts
index cc0312546a..324a19345d 100644
--- a/packages/playwright/src/reporters/blob.ts
+++ b/packages/playwright/src/reporters/blob.ts
@@ -27,7 +27,7 @@ import { resolveOutputFile, CommonReporterOptions } from './base';
import { TeleReporterEmitter } from './teleEmitter';
import type { BlobReporterOptions } from '../../types/test';
-import type { FullConfig, FullResult, TestResult } from '../../types/testReporter';
+import type { FullConfig, FullResult, TestCase, TestResult, TestStep } from '../../types/testReporter';
import type { BlobReportMetadata, JsonAttachment, JsonEvent } from '../isomorphic/teleReceiver';
import type { EventEmitter } from 'events';
@@ -66,6 +66,12 @@ export class BlobReporter extends TeleReporterEmitter {
super.onConfigure(config);
}
+ override async onTestPaused(test: TestCase, result: TestResult, step: TestStep) {
+ // onTestPaused is only relevant for interactive use, not for blob replays.
+ // merge-reports still gets onStepBegin/onStepEnd for pausing, but not the interactive part, so this is a no-op.
+ return { action: undefined };
+ }
+
override async onEnd(result: FullResult): Promise<void> {
await super.onEnd(result);
diff --git a/packages/playwright/src/reporters/internalReporter.ts b/packages/playwright/src/reporters/internalReporter.ts
index 946c16932b..147a837e52 100644
--- a/packages/playwright/src/reporters/internalReporter.ts
+++ b/packages/playwright/src/reporters/internalReporter.ts
@@ -67,6 +67,13 @@ export class InternalReporter implements ReporterV2 {
this._reporter.onStdErr?.(chunk, test, result);
}
+ async onTestPaused(test: TestCase, result: TestResult, step?: TestStep) {
+ this._addSnippetToTestErrors(test, result);
+ if (step)
+ this._addSnippetToStepError(test, step);
+ return await this._reporter.onTestPaused?.(test, result, step) ?? { action: undefined };
+ }
+
onTestEnd(test: TestCase, result: TestResult) {
this._addSnippetToTestErrors(test, result);
this._reporter.onTestEnd?.(test, result);
@@ -124,6 +131,9 @@ export function addLocationAndSnippetToError(config: FullConfig, error: TestErro
if (!location)
return;
+ if (!!error.snippet)
+ return;
+
try {
const tokens = [];
const source = fs.readFileSync(location.file, 'utf8');
diff --git a/packages/playwright/src/reporters/multiplexer.ts b/packages/playwright/src/reporters/multiplexer.ts
index 2a11b93583..ea5daa21a4 100644
--- a/packages/playwright/src/reporters/multiplexer.ts
+++ b/packages/playwright/src/reporters/multiplexer.ts
@@ -54,6 +54,16 @@ export class Multiplexer implements ReporterV2 {
wrap(() => reporter.onStdErr?.(chunk, test, result));
}
+ async onTestPaused(test: TestCase, result: TestResult, step: TestStep) {
+ // only one reporter can handle the pause. first reporter that cares wins.
+ for (const reporter of this._reporters) {
+ const disposition = await wrapAsync(() => reporter.onTestPaused?.(test, result, step));
+ if (disposition?.action)
+ return disposition;
+ }
+ return { action: undefined };
+ }
+
onTestEnd(test: TestCase, result: TestResult) {
for (const reporter of this._reporters)
wrap(() => reporter.onTestEnd?.(test, result));
diff --git a/packages/playwright/src/reporters/reporterV2.ts b/packages/playwright/src/reporters/reporterV2.ts
index 280ef2bfd2..555ba2a6a6 100644
--- a/packages/playwright/src/reporters/reporterV2.ts
+++ b/packages/playwright/src/reporters/reporterV2.ts
@@ -22,6 +22,7 @@ export interface ReporterV2 {
onTestBegin?(test: TestCase, result: TestResult): void;
onStdOut?(chunk: string | Buffer, test?: TestCase, result?: TestResult): void;
onStdErr?(chunk: string | Buffer, test?: TestCase, result?: TestResult): void;
+ onTestPaused?(test: TestCase, result: TestResult, step?: TestStep): Promise<{ action?: 'continue' | 'abort' }>;
onTestEnd?(test: TestCase, result: TestResult): void;
onEnd?(result: FullResult): Promise<{ status?: FullResult['status'] } | undefined | void> | void;
onExit?(): void | Promise<void>;
diff --git a/packages/playwright/src/reporters/teleEmitter.ts b/packages/playwright/src/reporters/teleEmitter.ts
index d191104b70..42c688fb5c 100644
--- a/packages/playwright/src/reporters/teleEmitter.ts
+++ b/packages/playwright/src/reporters/teleEmitter.ts
@@ -35,7 +35,8 @@ export class TeleReporterEmitter implements ReporterV2 {
private _rootDir!: string;
private _emitterOptions: TeleReporterEmitterOptions;
private _resultKnownAttachmentCounts = new Map<string, number>();
- // In case there is blob reporter and UI mode, make sure one does override
+ private _resultKnownErrorCounts = new Map<string, number>();
+ // In case there is blob reporter and UI mode, make sure one doesn't override
// the id assigned by the other.
private readonly _idSymbol = Symbol('id');
@@ -71,6 +72,22 @@ export class TeleReporterEmitter implements ReporterV2 {
});
}
+ async onTestPaused(test: reporterTypes.TestCase, result: reporterTypes.TestResult, step?: reporterTypes.TestStep) {
+ const resultId = (result as any)[this._idSymbol];
+ const stepId = (step as any)[this._idSymbol];
+ this._resultKnownErrorCounts.set(resultId, result.errors.length);
+ this._messageSink({
+ method: 'onTestPaused',
+ params: {
+ testId: test.id,
+ resultId,
+ stepId,
+ errors: result.errors,
+ }
+ });
+ return { action: undefined };
+ }
+
onTestEnd(test: reporterTypes.TestCase, result: reporterTypes.TestResult): void {
const testEnd: teleReceiver.JsonTestEnd = {
testId: test.id,
@@ -87,7 +104,9 @@ export class TeleReporterEmitter implements ReporterV2 {
}
});
- this._resultKnownAttachmentCounts.delete((result as any)[this._idSymbol]);
+ const resultId = (result as any)[this._idSymbol];
+ this._resultKnownAttachmentCounts.delete(resultId);
+ this._resultKnownErrorCounts.delete(resultId);
}
onStepBegin(test: reporterTypes.TestCase, result: reporterTypes.TestResult, step: reporterTypes.TestStep): void {
@@ -244,11 +263,12 @@ export class TeleReporterEmitter implements ReporterV2 {
}
private _serializeResultEnd(result: reporterTypes.TestResult): teleReceiver.JsonTestResultEnd {
+ const id = (result as any)[this._idSymbol];
return {
- id: (result as any)[this._idSymbol],
+ id,
duration: result.duration,
status: result.status,
- errors: result.errors,
+ errors: this._resultKnownErrorCounts.has(id) ? result.errors.slice(this._resultKnownAttachmentCounts.get(id)) : result.errors,
annotations: result.annotations?.length ? this._relativeAnnotationLocations(result.annotations) : undefined,
};
}
diff --git a/packages/playwright/src/runner/dispatcher.ts b/packages/playwright/src/runner/dispatcher.ts
index ec62cc47d9..5e5c9a7b85 100644
--- a/packages/playwright/src/runner/dispatcher.ts
+++ b/packages/playwright/src/runner/dispatcher.ts
@@ -598,11 +598,20 @@ class JobDispatcher {
}
private _onTestPaused(worker: WorkerHost, params: TestPausedPayload) {
+ const data = this._dataByTestId.get(params.testId);
+ if (!data)
+ return;
+
+ const { result, test, steps } = data;
+ const step = steps.get(params.stepId);
+ if (!step)
+ return;
+
const sendMessage = async (message: { request: any }) => {
try {
if (this.jobResult.isDone())
throw new Error('Test has already stopped');
- const response = await worker.sendCustomMessage({ testId: params.testId, request: message.request });
+ const response = await worker.sendCustomMessage({ testId: test.id, request: message.request });
if (response.error)
addLocationAndSnippetToError(this._config.config, response.error);
return response;
@@ -613,8 +622,12 @@ class JobDispatcher {
}
};
- for (const error of params.errors)
- addLocationAndSnippetToError(this._config.config, error);
+ result.errors = params.errors;
+ result.error = result.errors[0];
+
+ void this._reporter.onTestPaused?.(test, result, step).then(params => {
+ worker.sendResume(params);
+ });
this._failureTracker.onTestPaused?.({ ...params, sendMessage });
}
diff --git a/packages/playwright/src/runner/testRunner.ts b/packages/playwright/src/runner/testRunner.ts
index b7749748b5..0fd445df61 100644
--- a/packages/playwright/src/runner/testRunner.ts
+++ b/packages/playwright/src/runner/testRunner.ts
@@ -479,7 +479,9 @@ export async function runAllTestsWithConfig(config: FullConfigInternal): Promise
createLoadTask('in-process', { filterOnly: true, failOnLoadErrors: true }),
...createRunTestsTasks(config),
];
- const status = await runTasks(new TestRun(config, reporter), tasks, config.config.globalTimeout);
+
+ const testRun = new TestRun(config, reporter, { pauseAtEnd: config.configCLIOverrides.debug, pauseOnError: config.configCLIOverrides.debug });
+ const status = await runTasks(testRun, tasks, config.config.globalTimeout);
// Calling process.exit() might truncate large stdout/stderr output.
// See https://github.com/nodejs/node/issues/6456.
diff --git a/packages/playwright/src/runner/workerHost.ts b/packages/playwright/src/runner/workerHost.ts
index 19ebe0c2be..bd8dcc7563 100644
--- a/packages/playwright/src/runner/workerHost.ts
+++ b/packages/playwright/src/runner/workerHost.ts
@@ -24,7 +24,7 @@ import { stdioChunkToParams } from '../common/ipc';
import { artifactsFolderName } from '../isomorphic/folders';
import type { TestGroup } from './testGroups';
-import type { CustomMessageRequestPayload, CustomMessageResponsePayload, RunPayload, SerializedConfig, WorkerInitParams } from '../common/ipc';
+import type { CustomMessageRequestPayload, CustomMessageResponsePayload, RunPayload, SerializedConfig, ResumePayload, WorkerInitParams } from '../common/ipc';
let lastWorkerIndex = 0;
@@ -94,6 +94,10 @@ export class WorkerHost extends ProcessHost {
return await this.sendMessage({ method: 'customMessage', params: payload }) as CustomMessageResponsePayload;
}
+ sendResume(payload: ResumePayload) {
+ this.sendMessageNoReply({ method: 'resume', params: payload });
+ }
+
hash() {
return this._hash;
}
diff --git a/packages/playwright/src/transform/babelHighlightUtils.ts b/packages/playwright/src/transform/babelHighlightUtils.ts
new file mode 100644
index 0000000000..4611233686
--- /dev/null
+++ b/packages/playwright/src/transform/babelHighlightUtils.ts
@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import path from 'path';
+import { traverse, babelParse, T, types as t } from './babelBundle';
+import type { Location } from '../../types/testReporter';
+
+function containsLocation(range: T.SourceLocation, location: Location): boolean {
+ if (location.line < range.start.line || location.line > range.end.line)
+ return false;
+ if (location.line === range.start.line && location.column < range.start.column)
+ return false;
+ if (location.line === range.end.line && location.column > range.end.column)
+ return false;
+ return true;
+}
+
+export function findTestEndLocation(text: string, testStartLocation: Location): Location | undefined {
+ const ast = babelParse(text, path.basename(testStartLocation.file), false);
+ let result: Location | undefined;
+ traverse(ast, {
+ enter(path) {
+ if (t.isCallExpression(path.node) && path.node.loc && containsLocation(path.node.loc, testStartLocation)) {
+ const callNode = path.node;
+ const funcNode = callNode.arguments[callNode.arguments.length - 1];
+ if (callNode.arguments.length >= 2 && t.isFunction(funcNode) && funcNode.body.loc)
+ result = { file: testStartLocation.file, ...funcNode.body.loc.end };
+ }
+ }
+ });
+ return result;
+}
diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.ts
index 7889018f0a..083b14c6eb 100644
--- a/packages/playwright/src/worker/testInfo.ts
+++ b/packages/playwright/src/worker/testInfo.ts
@@ -24,6 +24,7 @@ import { addSuffixToFilePath, filteredStackTrace, getContainedPath, normalizeAnd
import { TestTracing } from './testTracing';
import { testInfoError } from './util';
import { wrapFunctionWithLocation } from '../transform/transform';
+import { findTestEndLocation } from '../transform/babelHighlightUtils';
import type { RunnableDescription } from './timeoutManager';
import type { FullProject, TestInfo, TestStatus, TestStepInfo, TestAnnotation } from '../../types/test';
@@ -69,7 +70,7 @@ type TestInfoCallbacks = {
onStepBegin?: (payload: ipc.StepBeginPayload) => void;
onStepEnd?: (payload: ipc.StepEndPayload) => void;
onAttach?: (payload: ipc.AttachmentPayload) => void;
- onTestPaused?: (payload: ipc.TestPausedPayload) => void;
+ onTestPaused?: (payload: ipc.TestPausedPayload) => Promise<ipc.ResumePayload>;
onGetStorageValue?: (payload: ipc.GetStorageValuePayload) => Promise<any>;
onSetStorageValue?: (payload: ipc.SetStorageValuePayload) => void;
};
@@ -464,12 +465,35 @@ export class TestInfoImpl implements TestInfo {
async _didFinishTestFunction() {
const shouldPause = (this._workerParams.pauseAtEnd && !this._isFailure()) || (this._workerParams.pauseOnError && this._isFailure());
if (shouldPause) {
- this._callbacks.onTestPaused?.({ testId: this.testId, errors: this._isFailure() ? this.errors : [] });
- await this._interruptedPromise;
+ const location = (this._isFailure() ? this._errorLocation() : await this._testEndLocation()) ?? { file: this.file, line: this.line, column: this.column };
+ const step = this._addStep({ category: 'hook', title: 'Paused', location });
+ const result = await Promise.race([
+ this._callbacks.onTestPaused!({ testId: this.testId, stepId: step.stepId, errors: this._isFailure() ? this.errors : [] }),
+ this._interruptedPromise.then(() => 'interrupted' as const),
+ ]);
+ step.complete({});
+ if (result !== 'interrupted') {
+ if (result.action === 'abort')
+ this._interrupt();
+ if (result.action === undefined)
+ await this._interruptedPromise;
+ }
}
await this._onDidFinishTestFunctionCallback?.();
}
+ private _errorLocation(): Location | undefined {
+ if (this.error?.stack)
+ return filteredStackTrace(this.error.stack.split('\n'))[0];
+ }
+
+ private async _testEndLocation(): Promise<Location | undefined> {
+ try {
+ const source = await fs.promises.readFile(this.file, 'utf-8');
+ return findTestEndLocation(source, { file: this.file, line: this.line, column: this.column });
+ } catch {}
+ }
+
// ------------ TestInfo methods ------------
async attach(name: string, options: { path?: string, body?: string | Buffer, contentType?: string } = {}) {
diff --git a/packages/playwright/src/worker/workerMain.ts b/packages/playwright/src/worker/workerMain.ts
index d19c4076dc..90f3d55ca3 100644
--- a/packages/playwright/src/worker/workerMain.ts
+++ b/packages/playwright/src/worker/workerMain.ts
@@ -65,6 +65,7 @@ export class WorkerMain extends ProcessRunner {
// These suites still need afterAll hooks to be executed for the proper cleanup.
// Contains dynamic annotations originated by modifiers with a callback, e.g. `test.skip(() => true)`.
private _activeSuites = new Map<Suite, TestAnnotation[]>();
+ private _resumePromise?: ManualPromise<ipc.ResumePayload>;
constructor(params: ipc.WorkerInitParams) {
super();
@@ -278,12 +279,20 @@ export class WorkerMain extends ProcessRunner {
}
}
+ resume(payload: ipc.ResumePayload) {
+ this._resumePromise?.resolve(payload);
+ }
+
private async _runTest(test: TestCase, retry: number, nextTest: TestCase | undefined) {
const testInfo = new TestInfoImpl(this._config, this._project, this._params, test, retry, {
onStepBegin: payload => this.dispatchEvent('stepBegin', payload),
onStepEnd: payload => this.dispatchEvent('stepEnd', payload),
onAttach: payload => this.dispatchEvent('attach', payload),
- onTestPaused: payload => this.dispatchEvent('testPaused', payload),
+ onTestPaused: payload => {
+ this._resumePromise = new ManualPromise();
+ this.dispatchEvent('testPaused', payload);
+ return this._resumePromise;
+ },
onGetStorageValue: payload => this.sendRequest('getStorageValue', payload),
onSetStorageValue: payload => this.sendMessageNoReply('setStorageValue', payload),
});
diff --git a/tests/playwright-test/pause-at-end.spec.ts b/tests/playwright-test/pause-at-end.spec.ts
new file mode 100644
index 0000000000..f590b84c7f
--- /dev/null
+++ b/tests/playwright-test/pause-at-end.spec.ts
@@ -0,0 +1,142 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { TestCase, TestResult, TestStep } from 'packages/playwright-test/reporter';
+import { ReporterV2 } from 'packages/playwright/src/reporters/reporterV2';
+import { test, expect } from './playwright-test-fixtures';
+
+class LocationReporter implements ReporterV2 {
+ private _foundErrors = 0;
+ version() {
+ return 'v2' as const;
+ }
+ onStepBegin(test: TestCase, result: TestResult, step: TestStep): void {
+ if (step.title === 'Paused') {
+ console.log(`%%onStepBegin: ${step.titlePath().join(' > ')} at :${step.location?.line}:${step.location?.column}`);
+ this._printErrors(result);
+ }
+ }
+ async onTestPaused(test: TestCase, result: TestResult, step?: TestStep) {
+ console.log(`%%onTestPaused`);
+ this._printErrors(result);
+ return { action: process.env.ACTION as 'continue' | 'abort' };
+ }
+ onStepEnd(test: TestCase, result: TestResult, step: TestStep): void {
+ if (step.title === 'Paused') {
+ console.log(`%%onStepEnd: ${step.titlePath().join(' > ')}`);
+ this._printErrors(result);
+ }
+ }
+ onTestEnd(test: TestCase, result: TestResult): void {
+ console.log('%%onTestEnd');
+ this._printErrors(result);
+ }
+ onStdOut(chunk: string | Buffer) {
+ console.log(chunk);
+ }
+ private _printErrors(result: TestResult) {
+ for (const [index, error] of result.errors.entries()) {
+ if (index >= this._foundErrors)
+ console.log(`%%result.errors[${index}] at :${error.location?.line}:${error.location?.column}`);
+ }
+ this._foundErrors = result.errors.length;
+ }
+}
+
+test('--debug should pause at end', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'location-reporter.js': `export default ${LocationReporter}`,
+ 'playwright.config.js': `
+ module.exports = { reporter: './location-reporter.js' };
+ `,
+ 'a.test.js': `
+ import { test, expect } from '@playwright/test';
+ test('pass', () => {
+ });
+ test.afterEach(() => {
+ console.log('%%teardown');
+ });
+ `
+ }, { debug: true }, { ACTION: 'continue' });
+ expect(result.outputLines).toEqual([
+ 'onStepBegin: After Hooks > Paused at :4:7',
+ 'onTestPaused',
+ 'onStepEnd: After Hooks > Paused',
+ 'teardown',
+ 'onTestEnd',
+ ]);
+});
+
+test('--debug should pause at end with setup project', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'location-reporter.js': `export default ${LocationReporter}`,
+ 'playwright.config.js': `
+ module.exports = {
+ reporter: './location-reporter.js',
+ projects: [
+ { name: 'setup', testMatch: /setup\\.test\\.js/ },
+ { name: 'main', dependencies: ['setup'] }
+ ]
+ };
+ `,
+ 'setup.test.js': `
+ import { test } from '@playwright/test';
+ test('setup', () => {
+ });
+ `,
+ 'a.test.js': `
+ import { test, expect } from '@playwright/test';
+ test('pass', () => {
+ console.log('main test started');
+ });
+ `
+ }, { debug: true }, { ACTION: 'continue' });
+ expect(result.outputLines).toContain('onStepBegin: After Hooks > Paused at :5:7');
+});
+
+test('--debug should pause on error', async ({ runInlineTest, mergeReports }) => {
+ const result = await runInlineTest({
+ 'location-reporter.js': `export default ${LocationReporter}`,
+ 'playwright.config.js': `
+ module.exports = { reporter: [['blob'], ['./location-reporter.js']] };
+ `,
+ 'a.test.js': `
+ import { test, expect } from '@playwright/test';
+ test('pass', () => {
+ expect.soft(1).toBe(2);
+ expect(2).toBe(3);
+ console.log('%%after error');
+ });
+ `
+ }, { debug: true }, { ACTION: 'abort' });
+ expect(result.outputLines).toEqual([
+ 'onStepBegin: After Hooks > Paused at :4:24',
+ 'onTestPaused',
+ 'result.errors[0] at :4:24',
+ 'result.errors[1] at :5:19',
+ 'onStepEnd: After Hooks > Paused',
+ 'onTestEnd',
+ ]);
+
+ const merged = await mergeReports('blob-report', undefined, { additionalArgs: ['--reporter', 'location-reporter.js'] });
+ expect(merged.outputLines, 'merge reporter doesnt get onTestPaused').toEqual([
+ 'onStepBegin: After Hooks > Paused at :4:24',
+ 'onStepEnd: After Hooks > Paused',
+ 'onTestEnd',
+ 'result.errors[0] at :4:24',
+ 'result.errors[1] at :5:19',
+ ]);
+});
diff --git a/tests/playwright-test/timeout.spec.ts b/tests/playwright-test/timeout.spec.ts
index 9d6001078d..6726b677dd 100644
--- a/tests/playwright-test/timeout.spec.ts
+++ b/tests/playwright-test/timeout.spec.ts
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { ReporterV2 } from 'packages/playwright/src/reporters/reporterV2';
import { test, expect } from './playwright-test-fixtures';
test('should run fixture teardown on timeout', async ({ runInlineTest }) => {
@@ -143,8 +144,25 @@ test('should respect test.slow', async ({ runInlineTest }) => {
expect(result.output).toContain('Test timeout of 1000ms exceeded.');
});
+// terminal reporters dont yet implement onTestPaused, so we default to continuing for these tests
+class TestPauseSkipReporter implements ReporterV2 {
+ version() {
+ return 'v2' as const;
+ }
+
+ async onTestPaused() {
+ return { action: 'continue' as const };
+ }
+}
+
test('should ignore test.setTimeout when debugging', async ({ runInlineTest }) => {
const result = await runInlineTest({
+ 'skip-pause.js': `export default ${TestPauseSkipReporter}`,
+ 'playwright.config.ts': `
+ export default {
+ reporter: [['list'], ['./skip-pause.js']]
+ };
+ `,
'a.spec.ts': `
import { test as base, expect } from '@playwright/test';
const test = base.extend({
@@ -168,9 +186,11 @@ test('should ignore globalTimeout when debugging', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/34911' },
}, async ({ runInlineTest }) => {
const result = await runInlineTest({
+ 'skip-pause.js': `export default ${TestPauseSkipReporter}`,
'playwright.config.ts': `
export default {
globalTimeout: 100,
+ reporter: [['list'], ['./skip-pause.js']]
};
`,
'a.spec.ts': `