Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable @babel/plugin-syntax-import-attributes all the time #32713

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/playwright/bundles/babel/src/babelBundleImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down Expand Up @@ -86,8 +87,6 @@ function babelTransformOptions(isTypeScript: boolean, isModule: boolean, plugins
}
})
]);
} else {
plugins.push([require('@babel/plugin-syntax-import-attributes'), { deprecatedAssertSyntax: true }]);
}

return {
Expand Down
29 changes: 29 additions & 0 deletions tests/playwright-test/babel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,32 @@ 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.)/);
});

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', 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');
});
}
22 changes: 0 additions & 22 deletions tests/playwright-test/esm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': `
Expand Down