Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: enable ts-esm support by default (#12658)

Pavel Feldman4d3d0e2bda4b
diff --git a/packages/playwright-test/src/cli.ts b/packages/playwright-test/src/cli.ts
index cc82e135e9..7f790c45b2 100644
--- a/packages/playwright-test/src/cli.ts
+++ b/packages/playwright-test/src/cli.ts
@@ -238,9 +238,9 @@ async function launchDockerContainer(): Promise<() => Promise<void>> {
function restartWithExperimentalTsEsm(configFile: string | null): boolean {
if (!configFile)
return false;
- if (!process.env.PW_EXPERIMENTAL_TS_ESM)
+ if (process.env.PW_DISABLE_TS_ESM)
return false;
- if (process.env.PW_EXPERIMENTAL_TS_ESM_ON)
+ if (process.env.PW_TS_ESM_ON)
return false;
if (!configFile.endsWith('.ts'))
return false;
@@ -251,7 +251,7 @@ function restartWithExperimentalTsEsm(configFile: string | null): boolean {
env: {
...process.env,
NODE_OPTIONS,
- PW_EXPERIMENTAL_TS_ESM_ON: '1',
+ PW_TS_ESM_ON: '1',
}
});
diff --git a/packages/playwright-test/src/transform.ts b/packages/playwright-test/src/transform.ts
index e95b3fe995..83cb9e8e77 100644
--- a/packages/playwright-test/src/transform.ts
+++ b/packages/playwright-test/src/transform.ts
@@ -54,10 +54,10 @@ sourceMapSupport.install({
}
});
-function calculateCachePath(content: string, filePath: string): string {
+function calculateCachePath(content: string, filePath: string, isModule: boolean): string {
const hash = crypto.createHash('sha1')
.update(process.env.PW_TEST_SOURCE_TRANSFORM || '')
- .update(process.env.PW_EXPERIMENTAL_TS_ESM ? 'esm' : 'no_esm')
+ .update(isModule ? 'esm' : 'no_esm')
.update(content)
.update(filePath)
.update(String(version))
@@ -134,7 +134,7 @@ export function transformHook(code: string, filename: string, isModule = false):
if (!isTypeScript && !hasPreprocessor)
return code;
- const cachePath = calculateCachePath(code, filename);
+ const cachePath = calculateCachePath(code, filename, isModule);
const codePath = cachePath + '.js';
const sourceMapPath = cachePath + '.map';
sourceMaps.set(filename, sourceMapPath);
diff --git a/tests/playwright-test/loader.spec.ts b/tests/playwright-test/loader.spec.ts
index a2ffe5233b..1208ae1baa 100644
--- a/tests/playwright-test/loader.spec.ts
+++ b/tests/playwright-test/loader.spec.ts
@@ -260,9 +260,7 @@ test('should import esm from ts when package.json has type module in experimenta
'b.ts': `
export const foo: string = 'foo';
`
- }, {}, {
- PW_EXPERIMENTAL_TS_ESM: true
- });
+ }, {});
expect(result.exitCode).toBe(0);
});
@@ -278,9 +276,7 @@ test('should propagate subprocess exit code in experimental mode @esm', async ({
expect(1).toBe(2);
});
`,
- }, {}, {
- PW_EXPERIMENTAL_TS_ESM: true
- });
+ }, {});
expect(result.exitCode).toBe(1);
});
diff --git a/tests/playwright-test/resolver.spec.ts b/tests/playwright-test/resolver.spec.ts
index 61a66a9d3e..d592314546 100644
--- a/tests/playwright-test/resolver.spec.ts
+++ b/tests/playwright-test/resolver.spec.ts
@@ -195,9 +195,7 @@ test('should respect path resolver in experimental mode @esm', async ({ runInlin
'foo/bar/util/b.ts': `
export const foo: string = 'foo';
`,
- }, {}, {
- PW_EXPERIMENTAL_TS_ESM: true
- });
+ }, {});
expect(result.exitCode).toBe(0);
});