From 423c281b4392351b7ff3df10c5d6ac22f7c0a355 Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 25 Aug 2024 18:22:56 +0800 Subject: [PATCH] test(e2e): update const enum test case (#3281) --- e2e/cases/typescript/index.test.ts | 19 +++++-------------- e2e/cases/typescript/src/foo.ts | 7 +++++++ e2e/cases/typescript/src/index.ts | 12 ++++++++++-- website/docs/en/guide/basic/typescript.mdx | 2 ++ website/docs/zh/guide/basic/typescript.mdx | 2 ++ 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/e2e/cases/typescript/index.test.ts b/e2e/cases/typescript/index.test.ts index 1772299d3c..f3907221e4 100644 --- a/e2e/cases/typescript/index.test.ts +++ b/e2e/cases/typescript/index.test.ts @@ -1,20 +1,11 @@ import { build } from '@e2e/helper'; import { expect, test } from '@playwright/test'; -// TODO not supported yet -test.skip('should compile const enum correctly', async () => { - const rsbuild = await build({ +test('should compile const enum correctly', async ({ page }) => { + await build({ cwd: __dirname, - rsbuildConfig: { - output: { - polyfill: 'off', - }, - }, + page, }); - const files = await rsbuild.unwrapOutputJSON(); - - const content = - files[Object.keys(files).find((file) => /index\.\w+\.js/.test(file))!]; - - expect(content.includes('console.log("fish is :",0)')).toBeTruthy(); + expect(await page.evaluate(() => window.test)).toBe('Fish 0, Cat 1'); + expect(await page.evaluate(() => window.test2)).toBe('Fish 0, Cat 1'); }); diff --git a/e2e/cases/typescript/src/foo.ts b/e2e/cases/typescript/src/foo.ts index 6c7c4afd93..375a3e947c 100644 --- a/e2e/cases/typescript/src/foo.ts +++ b/e2e/cases/typescript/src/foo.ts @@ -1,3 +1,10 @@ export enum Animals { Fish = 0, + Cat = 1, +} + +// biome-ignore lint/suspicious/noConstEnum: for testing +export const enum Animals2 { + Fish = 0, + Cat = 1, } diff --git a/e2e/cases/typescript/src/index.ts b/e2e/cases/typescript/src/index.ts index 2f7f94b1fe..578a81d151 100644 --- a/e2e/cases/typescript/src/index.ts +++ b/e2e/cases/typescript/src/index.ts @@ -1,3 +1,11 @@ -import { Animals } from './foo'; +import { Animals, Animals2 } from './foo'; -console.log('fish is :', Animals.Fish); +declare global { + interface Window { + test: string; + test2: string; + } +} + +window.test = `Fish ${Animals.Fish}, Cat ${Animals.Cat}`; +window.test2 = `Fish ${Animals2.Fish}, Cat ${Animals2.Cat}`; diff --git a/website/docs/en/guide/basic/typescript.mdx b/website/docs/en/guide/basic/typescript.mdx index 6d9d13d20c..5950bf893b 100644 --- a/website/docs/en/guide/basic/typescript.mdx +++ b/website/docs/en/guide/basic/typescript.mdx @@ -28,6 +28,8 @@ export { SomeType } from './types'; export type { SomeType } from './types'; ``` +> See [SWC - Migrating from tsc](https://swc.rs/docs/migrating-from-tsc) for more details about the differences between SWC and tsc. + ## Type Checking When transpiling TypeScript code using tools like SWC and Babel, type checking is not performed. diff --git a/website/docs/zh/guide/basic/typescript.mdx b/website/docs/zh/guide/basic/typescript.mdx index 2cc065e4e1..e210341813 100644 --- a/website/docs/zh/guide/basic/typescript.mdx +++ b/website/docs/zh/guide/basic/typescript.mdx @@ -28,6 +28,8 @@ export { SomeType } from './types'; export type { SomeType } from './types'; ``` +> 参考 [SWC - Migrating from tsc](https://swc.rs/docs/migrating-from-tsc) 了解更多 SWC 和 tsc 的差异。 + ## 类型检查 在进行 TypeScript 转译时,SWC 和 Babel 等工具不会执行类型检查。