Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(test): pass file:// URL to the ESM resolver in the sync loader (#41138)
Dmitry Gozman78c9dfd4c724
diff --git a/.github/workflows/tests_primary.yml b/.github/workflows/tests_primary.ymlindex 74097c4fb7..142cab8343 100644--- a/.github/workflows/tests_primary.yml+++ b/.github/workflows/tests_primary.yml@@ -73,33 +73,33 @@ jobs:fail-fast: falsematrix:os: [ubuntu-latest, macos-latest]- node-version: [20]+ node-version: [22]shardIndex: [1, 2]shardTotal: [2]shardWeights: ['58:42']include:- os: windows-latest- node-version: 20+ node-version: 22shardIndex: 1shardTotal: 3shardWeights: '44:33:23'- os: windows-latest- node-version: 20+ node-version: 22shardIndex: 2shardTotal: 3shardWeights: '44:33:23'- os: windows-latest- node-version: 20+ node-version: 22shardIndex: 3shardTotal: 3shardWeights: '44:33:23'- os: ubuntu-latest- node-version: 22+ node-version: 20shardIndex: 1shardTotal: 2shardWeights: '58:42'- os: ubuntu-latest- node-version: 22+ node-version: 20shardIndex: 2shardTotal: 2shardWeights: '58:42'diff --git a/packages/playwright/src/transform/esmLoaderSync.ts b/packages/playwright/src/transform/esmLoaderSync.tsindex 13457a7979..18c9c93af8 100644--- a/packages/playwright/src/transform/esmLoaderSync.ts+++ b/packages/playwright/src/transform/esmLoaderSync.ts@@ -21,15 +21,19 @@ import { currentFileDepsCollector } from './compilationCache';import { resolveHook, shouldTransform, transformHook } from './transform';import { fileIsModule } from '../util';-export function resolve(specifier: string, context: { parentURL?: string }, nextResolve: Function) {+export function resolve(specifier: string, context: { parentURL?: string, conditions?: string[] }, nextResolve: Function) {if (context.parentURL && context.parentURL.startsWith('file://')) {const filename = url.fileURLToPath(context.parentURL);const resolved = resolveHook(filename, specifier);- // Pass the resolved absolute path (not a file:// URL) to nextResolve: unlike the- // ESM-only asynchronous loader, these hooks also serve require(), whose default- // resolver rejects file:// specifiers but accepts absolute paths for both kinds.- if (resolved !== undefined)- specifier = resolved;+ if (resolved !== undefined) {+ // These hooks serve both require() and import. The two default resolvers disagree on+ // what an already-resolved specifier should look like:+ // - require()'s resolver wants an absolute path and rejects file:// specifiers;+ // - the ESM resolver wants a file:// URL and, on Windows, mistakes an absolute path's+ // drive letter for a URL scheme ("Received protocol 'c:'").+ // The `import` condition is present only for ESM resolution, so use it to pick the form.+ specifier = context.conditions?.includes('import') ? url.pathToFileURL(resolved).toString() : resolved;+ }}const result = nextResolve(specifier, context);if (result?.url && result.url.startsWith('file://'))