From 980103689368ebb184e3365e33fc8a5e55c6a886 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Mon, 12 Oct 2026 09:17:03 -0700 Subject: [PATCH 1/2] test: pin module semantics of transpiled code --- tests/playwright-test/babel.spec.ts | 79 +++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/tests/playwright-test/babel.spec.ts b/tests/playwright-test/babel.spec.ts index 5843ab7384f7f..a7cdbb7ddea5c 100644 --- a/tests/playwright-test/babel.spec.ts +++ b/tests/playwright-test/babel.spec.ts @@ -215,3 +215,82 @@ for (const type of ['module', undefined]) { expect(result.stdout).toContain('imported value: bar'); }); } + +test('should allow overwriting exports of a transpiled module', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'util.ts': ` + export function greet() { return 'real'; } + `, + 'greeter.ts': ` + import { greet } from './util'; + export function run() { return greet(); } + `, + 'example.spec.ts': ` + import { test, expect } from '@playwright/test'; + import * as util from './util'; + import { run } from './greeter'; + + test('works', () => { + (util as any).greet = () => 'stub'; + expect(run()).toBe('stub'); + }); + `, + }); + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(1); +}); + +test('should read undefined from an uninitialized import in a cycle', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.ts': ` + import './b'; + export const value = 'a'; + `, + 'b.ts': ` + import { value } from './a'; + export const valueSeenByB = value; + `, + 'example.spec.ts': ` + import { test, expect } from '@playwright/test'; + import { value } from './a'; + import { valueSeenByB } from './b'; + + test('works', () => { + expect(value).toBe('a'); + expect(valueSeenByB).toBe(undefined); + }); + `, + }); + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(1); +}); + +test('should parse generic arrow functions in tsx', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'example.spec.tsx': ` + import { test, expect } from '@playwright/test'; + + const identity = (value: T) => value; + + test('works', () => { + expect(identity('value')).toBe('value'); + }); + `, + }); + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(1); +}); + +test('should reject import.meta in commonjs', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'example.spec.ts': ` + import { test, expect } from '@playwright/test'; + + test('works', () => { + expect(import.meta.dirname).toBeTruthy(); + }); + `, + }); + expect(result.exitCode).toBe(1); + expect(result.output).toContain(`SyntaxError: Cannot use 'import.meta' outside a module`); +}); From e7b2529108802a0997265bf90f58ddb424e6ac20 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Mon, 12 Oct 2026 10:35:30 -0700 Subject: [PATCH 2/2] test: accept the async loader error for import.meta in commonjs --- tests/playwright-test/babel.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/playwright-test/babel.spec.ts b/tests/playwright-test/babel.spec.ts index a7cdbb7ddea5c..e454c8410d7a9 100644 --- a/tests/playwright-test/babel.spec.ts +++ b/tests/playwright-test/babel.spec.ts @@ -292,5 +292,5 @@ test('should reject import.meta in commonjs', async ({ runInlineTest }) => { `, }); expect(result.exitCode).toBe(1); - expect(result.output).toContain(`SyntaxError: Cannot use 'import.meta' outside a module`); + expect(result.output).toMatch(/(SyntaxError: Cannot use 'import.meta' outside a module)|(ReferenceError: require is not defined in ES module scope)/); });