From c83ba0c8d47407033f1b0cfb3c9b109c52a30494 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 19 Sep 2024 16:10:22 +0200 Subject: [PATCH 1/2] chore: enable @babel/plugin-syntax-import-attributes all the time --- .../bundles/babel/src/babelBundleImpl.ts | 3 +-- tests/playwright-test/babel.spec.ts | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/playwright/bundles/babel/src/babelBundleImpl.ts b/packages/playwright/bundles/babel/src/babelBundleImpl.ts index 82610247f1b08..81e617ef27448 100644 --- a/packages/playwright/bundles/babel/src/babelBundleImpl.ts +++ b/packages/playwright/bundles/babel/src/babelBundleImpl.ts @@ -45,6 +45,7 @@ function babelTransformOptions(isTypeScript: boolean, isModule: boolean, plugins [require('@babel/plugin-syntax-async-generators')], [require('@babel/plugin-syntax-object-rest-spread')], [require('@babel/plugin-transform-export-namespace-from')], + [require('@babel/plugin-syntax-import-attributes'), { deprecatedAssertSyntax: true }], [ // From https://github.com/G-Rath/babel-plugin-replace-ts-export-assignment/blob/8dfdca32c8aa428574b0cae341444fc5822f2dc6/src/index.ts ( @@ -86,8 +87,6 @@ function babelTransformOptions(isTypeScript: boolean, isModule: boolean, plugins } }) ]); - } else { - plugins.push([require('@babel/plugin-syntax-import-attributes'), { deprecatedAssertSyntax: true }]); } return { diff --git a/tests/playwright-test/babel.spec.ts b/tests/playwright-test/babel.spec.ts index 724a2a98ad04c..eae3d62e65c0f 100644 --- a/tests/playwright-test/babel.spec.ts +++ b/tests/playwright-test/babel.spec.ts @@ -150,3 +150,30 @@ test('should not transform external', async ({ runInlineTest }) => { expect(result.exitCode).toBe(1); expect(result.output).toMatch(/(Cannot use import statement outside a module|require\(\) of ES Module .* not supported.)/); }); + +test('should support import assertions', { + annotation: { + type: 'issue', + description: 'https://github.com/microsoft/playwright/issues/32659' + } +}, async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'playwright.config.ts': ` + import packageJSON from './package.json' assert { type: 'json' }; + console.log('imported value: ' + packageJSON.foo); + export default { }; + `, + 'package.json': JSON.stringify({ foo: 'bar' }), + 'a.esm.test.ts': ` + import { test, expect } from '@playwright/test'; + + test('check project name', ({}, testInfo) => { + expect(1).toBe(1); + }); + ` + }); + + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(1); + expect(result.stdout).toContain('imported value: bar'); +}); \ No newline at end of file From 0dccf1665882708087d9b91823b805ee579d04fd Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 19 Sep 2024 16:28:16 +0200 Subject: [PATCH 2/2] review feedback --- tests/playwright-test/babel.spec.ts | 32 +++++++++++++++-------------- tests/playwright-test/esm.spec.ts | 22 -------------------- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/tests/playwright-test/babel.spec.ts b/tests/playwright-test/babel.spec.ts index eae3d62e65c0f..517d813bc84be 100644 --- a/tests/playwright-test/babel.spec.ts +++ b/tests/playwright-test/babel.spec.ts @@ -151,29 +151,31 @@ test('should not transform external', async ({ runInlineTest }) => { expect(result.output).toMatch(/(Cannot use import statement outside a module|require\(\) of ES Module .* not supported.)/); }); -test('should support import assertions', { - annotation: { - type: 'issue', - description: 'https://github.com/microsoft/playwright/issues/32659' - } -}, async ({ runInlineTest }) => { - const result = await runInlineTest({ - 'playwright.config.ts': ` +for (const type of ['module', undefined]) { + test(`should support import assertions with type=${type} in the package.json`, { + annotation: { + type: 'issue', + description: 'https://github.com/microsoft/playwright/issues/32659' + } + }, async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'playwright.config.ts': ` import packageJSON from './package.json' assert { type: 'json' }; console.log('imported value: ' + packageJSON.foo); export default { }; `, - 'package.json': JSON.stringify({ foo: 'bar' }), - 'a.esm.test.ts': ` + 'package.json': JSON.stringify({ foo: 'bar', type }), + 'a.test.ts': ` import { test, expect } from '@playwright/test'; test('check project name', ({}, testInfo) => { expect(1).toBe(1); }); ` - }); + }); - expect(result.exitCode).toBe(0); - expect(result.passed).toBe(1); - expect(result.stdout).toContain('imported value: bar'); -}); \ No newline at end of file + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(1); + expect(result.stdout).toContain('imported value: bar'); + }); +} diff --git a/tests/playwright-test/esm.spec.ts b/tests/playwright-test/esm.spec.ts index 1aa89000e545c..ce75fca76716f 100644 --- a/tests/playwright-test/esm.spec.ts +++ b/tests/playwright-test/esm.spec.ts @@ -35,28 +35,6 @@ test('should load nested as esm when package.json has type module', async ({ run expect(result.passed).toBe(1); }); -test('should support import assertions', async ({ runInlineTest }) => { - const result = await runInlineTest({ - 'playwright.config.ts': ` - import packageJSON from './package.json' assert { type: 'json' }; - console.log('imported value: ' + packageJSON.foo); - export default { }; - `, - 'package.json': JSON.stringify({ type: 'module', foo: 'bar' }), - 'a.esm.test.ts': ` - import { test, expect } from '@playwright/test'; - - test('check project name', ({}, testInfo) => { - expect(1).toBe(1); - }); - ` - }); - - expect(result.exitCode).toBe(0); - expect(result.passed).toBe(1); - expect(result.stdout).toContain('imported value: bar'); -}); - test('should support import attributes', async ({ runInlineTest }) => { const result = await runInlineTest({ 'playwright.config.ts': `