From f663e5d6cc105448ab73c32b182fe7bf0dc9396c Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 27 Jul 2022 18:09:55 +0200 Subject: [PATCH] chore: fix tests when repo checkout was not playwright (#15994) --- packages/playwright-test/src/experimentalLoader.ts | 3 --- packages/playwright-test/src/transform.ts | 8 ++++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/playwright-test/src/experimentalLoader.ts b/packages/playwright-test/src/experimentalLoader.ts index c9e8c416fa..67c18f0631 100644 --- a/packages/playwright-test/src/experimentalLoader.ts +++ b/packages/playwright-test/src/experimentalLoader.ts @@ -42,9 +42,6 @@ async function load(moduleUrl: string, context: { format?: string }, defaultLoad if (!moduleUrl.startsWith('file://')) return defaultLoad(moduleUrl, context, defaultLoad); - if (!moduleUrl.startsWith('file://')) - return defaultLoad(moduleUrl, context, defaultLoad); - const filename = url.fileURLToPath(moduleUrl); // Bail for node_modules. if (belongsToNodeModules(filename)) diff --git a/packages/playwright-test/src/transform.ts b/packages/playwright-test/src/transform.ts index 0d67f5c1d9..4d97b8cd14 100644 --- a/packages/playwright-test/src/transform.ts +++ b/packages/playwright-test/src/transform.ts @@ -245,12 +245,16 @@ export function wrapFunctionWithLocation(func: (location: Lo }; } +// This will catch the playwright-test package as well +const kPlaywrightInternalPrefix = path.resolve(__dirname, '../../playwright'); +const kPlaywrightCoveragePrefix = path.resolve(__dirname, '../../../tests/config/coverage.js'); + export function belongsToNodeModules(file: string) { if (file.includes(`${path.sep}node_modules${path.sep}`)) return true; - if (file.includes(`${path.sep}playwright${path.sep}packages${path.sep}playwright`)) + if (file.startsWith(kPlaywrightInternalPrefix)) return true; - if (file.includes(`${path.sep}playwright${path.sep}tests${path.sep}config${path.sep}coverage.js`)) + if (file.startsWith(kPlaywrightCoveragePrefix)) return true; return false; }