Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix: support import assertions (#20009)
Andrey Lushnikov92375f63338c
diff --git a/packages/playwright-test/ThirdPartyNotices.txt b/packages/playwright-test/ThirdPartyNotices.txtindex 862f476d8c..c1c142e809 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/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-async-generators)- @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-dynamic-import)- @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-export-namespace-from)+- @babel/[email protected] (https://github.com/babel/babel)- @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-json-strings)- @babel/[email protected] (https://github.com/babel/babel)- @babel/[email protected] (https://github.com/babel/babel)@@ -1338,6 +1339,33 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=========================================END OF @babel/[email protected] AND INFORMATION+%% @babel/[email protected] 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/[email protected] AND INFORMATION+%% @babel/[email protected] NOTICES AND INFORMATION BEGIN HERE=========================================MIT License@@ -3841,6 +3869,6 @@ END OF [email protected] AND INFORMATIONSUMMARY BEGIN HERE=========================================-Total Packages: 131+Total Packages: 132=========================================END OF SUMMARY\ No newline at end of filediff --git a/packages/playwright-test/bundles/babel/package-lock.json b/packages/playwright-test/bundles/babel/package-lock.jsonindex cbaac67438..773a81f140 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.jsonindex 0db275007a..3a1f02051c 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.tsindex 23213d7c4e..c2f303de01 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, isModuleif (!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.tsindex ef199297f9..a0fa8bebdd 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 ({ runexpect(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);