diff --git a/packages/playwright-test/ThirdPartyNotices.txt b/packages/playwright-test/ThirdPartyNotices.txt index 862f476d8c1da..c1c142e809ef6 100644 --- a/packages/playwright-test/ThirdPartyNotices.txt +++ b/packages/playwright-test/ThirdPartyNotices.txt @@ -42,6 +42,7 @@ This project incorporates components from the projects listed below. The origina - @babel/plugin-syntax-async-generators@7.8.4 (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-async-generators) - @babel/plugin-syntax-dynamic-import@7.8.3 (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-dynamic-import) - @babel/plugin-syntax-export-namespace-from@7.8.3 (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-export-namespace-from) +- @babel/plugin-syntax-import-assertions@7.20.0 (https://github.com/babel/babel) - @babel/plugin-syntax-json-strings@7.8.3 (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-json-strings) - @babel/plugin-syntax-jsx@7.18.6 (https://github.com/babel/babel) - @babel/plugin-syntax-logical-assignment-operators@7.10.4 (https://github.com/babel/babel) @@ -1338,6 +1339,33 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ========================================= END OF @babel/plugin-syntax-export-namespace-from@7.8.3 AND INFORMATION +%% @babel/plugin-syntax-import-assertions@7.20.0 NOTICES AND INFORMATION BEGIN HERE +========================================= +MIT License + +Copyright (c) 2014-present Sebastian McKenzie and other contributors + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +========================================= +END OF @babel/plugin-syntax-import-assertions@7.20.0 AND INFORMATION + %% @babel/plugin-syntax-json-strings@7.8.3 NOTICES AND INFORMATION BEGIN HERE ========================================= MIT License @@ -3841,6 +3869,6 @@ END OF update-browserslist-db@1.0.10 AND INFORMATION SUMMARY BEGIN HERE ========================================= -Total Packages: 131 +Total Packages: 132 ========================================= END OF SUMMARY \ No newline at end of file diff --git a/packages/playwright-test/bundles/babel/package-lock.json b/packages/playwright-test/bundles/babel/package-lock.json index cbaac67438cc7..773a81f140653 100644 --- a/packages/playwright-test/bundles/babel/package-lock.json +++ b/packages/playwright-test/bundles/babel/package-lock.json @@ -22,6 +22,7 @@ "@babel/plugin-proposal-private-methods": "^7.18.6", "@babel/plugin-proposal-private-property-in-object": "^7.18.6", "@babel/plugin-syntax-async-generators": "^7.8.4", + "@babel/plugin-syntax-import-assertions": "^7.20.0", "@babel/plugin-syntax-json-strings": "^7.8.3", "@babel/plugin-syntax-object-rest-spread": "^7.8.3", "@babel/plugin-syntax-optional-catch-binding": "^7.8.3", @@ -540,6 +541,20 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-syntax-import-assertions": { + "version": "7.20.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.20.0.tgz", + "integrity": "sha512-IUh1vakzNoWalR8ch/areW7qFopR2AEw03JlG7BbrDqmQ4X3q9uuipQwSGrUn7oGiemKjtSLDhNtQHzMHr1JdQ==", + "dependencies": { + "@babel/helper-plugin-utils": "^7.19.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/plugin-syntax-json-strings": { "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.8.3.tgz", @@ -1467,6 +1482,14 @@ "@babel/helper-plugin-utils": "^7.8.3" } }, + "@babel/plugin-syntax-import-assertions": { + "version": "7.20.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.20.0.tgz", + "integrity": "sha512-IUh1vakzNoWalR8ch/areW7qFopR2AEw03JlG7BbrDqmQ4X3q9uuipQwSGrUn7oGiemKjtSLDhNtQHzMHr1JdQ==", + "requires": { + "@babel/helper-plugin-utils": "^7.19.0" + } + }, "@babel/plugin-syntax-json-strings": { "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.8.3.tgz", diff --git a/packages/playwright-test/bundles/babel/package.json b/packages/playwright-test/bundles/babel/package.json index 0db275007a61d..3a1f02051cd6f 100644 --- a/packages/playwright-test/bundles/babel/package.json +++ b/packages/playwright-test/bundles/babel/package.json @@ -23,6 +23,7 @@ "@babel/plugin-proposal-private-methods": "^7.18.6", "@babel/plugin-proposal-private-property-in-object": "^7.18.6", "@babel/plugin-syntax-async-generators": "^7.8.4", + "@babel/plugin-syntax-import-assertions": "^7.20.0", "@babel/plugin-syntax-json-strings": "^7.8.3", "@babel/plugin-syntax-object-rest-spread": "^7.8.3", "@babel/plugin-syntax-optional-catch-binding": "^7.8.3", diff --git a/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts b/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts index 23213d7c4e843..c2f303de01e42 100644 --- a/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts +++ b/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts @@ -66,6 +66,8 @@ export function babelTransform(filename: string, isTypeScript: boolean, isModule if (!isModule) { plugins.push([require('@babel/plugin-transform-modules-commonjs')]); plugins.push([require('@babel/plugin-proposal-dynamic-import')]); + } else { + plugins.push([require('@babel/plugin-syntax-import-assertions')]); } plugins.unshift(additionalPlugin); diff --git a/tests/playwright-test/esm.spec.ts b/tests/playwright-test/esm.spec.ts index ef199297f9eb6..a0fa8bebdd550 100644 --- a/tests/playwright-test/esm.spec.ts +++ b/tests/playwright-test/esm.spec.ts @@ -36,6 +36,28 @@ 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, nodeVersion }) => { + // We only support experimental esm mode on Node 16+ + test.skip(nodeVersion.major < 16); + const result = await runInlineTest({ + 'playwright.config.ts': ` + import packageJSON from './package.json' assert { type: 'json' }; + export default { }; + `, + 'package.json': JSON.stringify({ type: 'module' }), + 'a.esm.test.ts': ` + const { test } = pwt; + + test('check project name', ({}, testInfo) => { + expect(1).toBe(1); + }); + ` + }); + + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(1); +}); + test('should import esm from ts when package.json has type module in experimental mode', async ({ runInlineTest, nodeVersion }) => { // We only support experimental esm mode on Node 16+ test.skip(nodeVersion.major < 16);