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(loader): experimentalLoader with node@18 (#21106)
Nowell Strite000583e0483d
diff --git a/packages/playwright-test/src/experimentalLoader.ts b/packages/playwright-test/src/experimentalLoader.tsindex f10daec192..3f7244a335 100644--- a/packages/playwright-test/src/experimentalLoader.ts+++ b/packages/playwright-test/src/experimentalLoader.ts@@ -29,8 +29,9 @@ async function resolve(specifier: string, context: { parentURL?: string }, defauspecifier = url.pathToFileURL(resolved).toString();}const result = await defaultResolve(specifier, context, defaultResolve);- if (result?.url)+ if (result?.url && result.url.startsWith('file://'))currentFileDepsCollector()?.add(url.fileURLToPath(result.url));+return result;}diff --git a/tests/playwright-test/loader.spec.ts b/tests/playwright-test/loader.spec.tsindex 3ced335b8d..0c04e3988c 100644--- a/tests/playwright-test/loader.spec.ts+++ b/tests/playwright-test/loader.spec.ts@@ -612,3 +612,32 @@ test('should import export assignment from ts', async ({ runInlineTest }) => {expect(result.passed).toBe(1);expect(result.exitCode).toBe(0);});++test('should support node imports', async ({ runInlineTest, nodeVersion }) => {+ // We only support experimental esm mode on Node 16++ test.skip(nodeVersion.major < 16);+ const result = await runInlineTest({+ 'playwright.config.ts': 'export default {}',+ 'package.json': JSON.stringify({+ type: 'module'+ }),+ 'test.json': 'test data',+ 'utils.mjs': `+ import fs from "node:fs/promises";++ export async function utilityModuleThatImportsNodeModule() {+ return await fs.readFile('test.json', 'utf8');+ }+ `,+ 'a.test.ts': `+ import { test, expect } from '@playwright/test';+ import { utilityModuleThatImportsNodeModule } from './utils.mjs';++ test('pass', async () => {+ expect(await utilityModuleThatImportsNodeModule()).toBe('test data');+ });+ `+ });+ expect(result.passed).toBe(1);+ expect(result.exitCode).toBe(0);+});