Skip to content

Commit

Permalink
test(e2e): update const enum test case (#3281)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Aug 25, 2024
1 parent f92daa4 commit 423c281
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
19 changes: 5 additions & 14 deletions e2e/cases/typescript/index.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
7 changes: 7 additions & 0 deletions e2e/cases/typescript/src/foo.ts
Original file line number Diff line number Diff line change
@@ -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,
}
12 changes: 10 additions & 2 deletions e2e/cases/typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -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}`;
2 changes: 2 additions & 0 deletions website/docs/en/guide/basic/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/zh/guide/basic/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 等工具不会执行类型检查。
Expand Down

0 comments on commit 423c281

Please sign in to comment.