Skip to content

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

fix: filter out pwt stacks correctly (#20158)

Max Schmittdf05c00da36f
diff --git a/packages/playwright-core/src/utils/stackTrace.ts b/packages/playwright-core/src/utils/stackTrace.ts
index f8b60663cc..d0a82c61eb 100644
--- a/packages/playwright-core/src/utils/stackTrace.ts
+++ b/packages/playwright-core/src/utils/stackTrace.ts
@@ -30,10 +30,13 @@ export function rewriteErrorMessage<E extends Error>(e: E, newMessage: string):
const CORE_DIR = path.resolve(__dirname, '..', '..');
const CORE_LIB = path.join(CORE_DIR, 'lib');
const CORE_SRC = path.join(CORE_DIR, 'src');
-const TEST_DIR_SRC = path.resolve(CORE_DIR, '..', 'playwright-test');
-const TEST_DIR_LIB = path.resolve(CORE_DIR, '..', '@playwright', 'test');
const COVERAGE_PATH = path.join(CORE_DIR, '..', '..', 'tests', 'config', 'coverage.js');
+const stackIgnoreFilters = [
+ (frame: StackFrame) => frame.file.startsWith(CORE_DIR),
+];
+export const addStackIgnoreFilter = (filter: (frame: StackFrame) => boolean) => stackIgnoreFilters.push(filter);
+
export type StackFrame = {
file: string,
line?: number,
@@ -125,9 +128,7 @@ export function captureStackTrace(rawStack?: string): ParsedStackTrace {
parsedFrames = parsedFrames.filter((f, i) => {
if (process.env.PWDEBUGIMPL)
return true;
- if (f.frame.file.startsWith(TEST_DIR_SRC) || f.frame.file.startsWith(TEST_DIR_LIB))
- return false;
- if (f.frame.file.startsWith(CORE_DIR))
+ if (stackIgnoreFilters.some(filter => filter(f.frame)))
return false;
return true;
});
diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.ts
index 4f892f7365..433deb7d50 100644
--- a/packages/playwright-test/src/index.ts
+++ b/packages/playwright-test/src/index.ts
@@ -18,7 +18,7 @@ import * as fs from 'fs';
import * as path from 'path';
import type { APIRequestContext, BrowserContext, BrowserContextOptions, LaunchOptions, Page, Tracing, Video } from 'playwright-core';
import * as playwrightLibrary from 'playwright-core';
-import { createGuid, debugMode, removeFolders } from 'playwright-core/lib/utils';
+import { createGuid, debugMode, removeFolders, addStackIgnoreFilter } from 'playwright-core/lib/utils';
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, ScreenshotMode, TestInfo, TestType, TraceMode, VideoMode } from '../types/test';
import { store as _baseStore } from './store';
import type { TestInfoImpl } from './testInfo';
@@ -29,6 +29,8 @@ export { addRunnerPlugin as _addRunnerPlugin } from './plugins';
export const _baseTest: TestType<{}, {}> = rootTestType.test;
export const store = _baseStore;
+addStackIgnoreFilter((frame: StackFrame) => frame.file.startsWith(path.dirname(require.resolve('../package.json'))));
+
if ((process as any)['__pw_initiator__']) {
const originalStackTraceLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 200;