Skip to content

Commit c8c3700

Browse files
authored
test(esm): fix import attribute tests (#30798)
Pre Node.js `18.20.0`: - `assert` is supported Post Node.js `18.20.0` - `assert` and `with` is supported. Before #30482 we kept `asserts` in the JS code, Node.js was interpreting them. The `with` keyword was not supported, this was what the PR was fixing. After #30482 Babel is converting `assert` (deprecated) into `with` (successor) since we use the `deprecatedAssertSyntax` option. This means, that the minimum Node.js version we support in order to use import attributes is now `18.20.0` where they added the `with` support. This follows our principle of supporting only the latest minor release for Node.js versions. See here for the 18.20 changelog: > #### Added support for import attributes > > Support has been added for import attributes, to replace the old import > assertions syntax. This will aid migration by making the new syntax available > across all currently supported Node.js release lines. > > This adds the `with` keyword which should be used in place of the previous > `assert` keyword, which will be removed in a future semver-major Node.js > release. > > For example, > > ```console > import "foo" assert { ... } > ``` > > should be replaced with > > ```console > import "foo" with { ... } > ``` Fixes #30482 - the tests were a noop before, since they were tree-shaked by Babel.
1 parent b06c1df commit c8c3700

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tests/playwright-test/esm.spec.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ test('should support import assertions', async ({ runInlineTest }) => {
3939
const result = await runInlineTest({
4040
'playwright.config.ts': `
4141
import packageJSON from './package.json' assert { type: 'json' };
42+
console.log('imported value: ' + packageJSON.foo);
4243
export default { };
4344
`,
44-
'package.json': JSON.stringify({ type: 'module' }),
45+
'package.json': JSON.stringify({ type: 'module', foo: 'bar' }),
4546
'a.esm.test.ts': `
4647
import { test, expect } from '@playwright/test';
4748
@@ -53,23 +54,28 @@ test('should support import assertions', async ({ runInlineTest }) => {
5354

5455
expect(result.exitCode).toBe(0);
5556
expect(result.passed).toBe(1);
57+
expect(result.stdout).toContain('imported value: bar');
5658
});
5759

5860
test('should support import attributes', async ({ runInlineTest }) => {
5961
const result = await runInlineTest({
6062
'playwright.config.ts': `
6163
import packageJSON from './package.json' with { type: 'json' };
64+
console.log('imported value (config): ' + packageJSON.foo);
6265
export default { };
6366
`,
64-
'package.json': JSON.stringify({ type: 'module' }),
67+
'package.json': JSON.stringify({ type: 'module', foo: 'bar' }),
6568
'a.test.ts': `
66-
import config from './config.json' with { type: 'json' };
69+
import config from './package.json' with { type: 'json' };
70+
console.log('imported value (test): ' + config.foo);
6771
import { test, expect } from '@playwright/test';
6872
test('pass', async () => {});
6973
`
7074
});
7175
expect(result.exitCode).toBe(0);
7276
expect(result.passed).toBe(1);
77+
expect(result.stdout).toContain('imported value (config): bar');
78+
expect(result.stdout).toContain('imported value (test): bar');
7379
});
7480

7581
test('should import esm from ts when package.json has type module in experimental mode', async ({ runInlineTest }) => {

0 commit comments

Comments
 (0)