From 4d3d0e2bda4b19cde37c842bba6c5cc91eb7766d Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 10 Mar 2022 14:48:33 -0800 Subject: [PATCH] chore: enable ts-esm support by default (#12658) --- packages/playwright-test/src/cli.ts | 6 +++--- packages/playwright-test/src/transform.ts | 6 +++--- tests/playwright-test/loader.spec.ts | 8 ++------ tests/playwright-test/resolver.spec.ts | 4 +--- 4 files changed, 9 insertions(+), 15 deletions(-) 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> { 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); });