Skip to content

Commit

Permalink
Merge pull request baidu#9579 from nwind/chore-swc-jest
Browse files Browse the repository at this point in the history
chore: jest 使用 @swc/jest 编译,提升性能
  • Loading branch information
hsm-lv authored Feb 18, 2024
2 parents 6644273 + 85beb23 commit 50a66ef
Show file tree
Hide file tree
Showing 22 changed files with 214 additions and 312 deletions.
23 changes: 23 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"runtime": "classic"
}
},
"keepClassNames": true,
"externalHelpers": true,
"loose": false
},
"sourceMaps": true,
"minify": false
}
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ npm test --workspaces

# 测试某个用例
# <spec-name>为用例名称,比如inputImage
npm test --workspace amis <spec-name>
npm test --workspace amis -- -t <spec-name>

# 运行某个单测文件
./node_modules/.bin/jest packages/amis/__tests__/renderers/Form/buttonToolBar.test.tsx

# 运行某个单测文件里的某个例子
./node_modules/.bin/jest packages/amis/__tests__/renderers/Form/buttonToolBar.test.tsx -t 'Renderer:button-toolbar'

# 查看测试用例覆盖率
npm run coverage
Expand All @@ -73,7 +79,7 @@ npm run update-snapshot

# 更新单个 snapshot
# <spec-name>为用例名称,比如inputImage
npm run update-snapshot --workspace amis <spec-name>
npm run update-snapshot --workspace amis -- -t <spec-name>
```

### 发布版本
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"@babel/types": "^7.22.5",
"@fortawesome/fontawesome-free": "^6.1.1",
"@rollup/plugin-replace": "^5.0.1",
"@swc/core": "^1.3.107",
"@swc/helpers": "^0.5.3",
"@swc/jest": "^0.2.34",
"@types/express": "^4.17.14",
"@types/jest": "^28.1.0",
"@types/js-yaml": "^4.0.5",
Expand Down Expand Up @@ -117,7 +120,9 @@
"tsx",
"js"
],
"preset": "ts-jest",
"transform": {
"^.+\\.(t|j)sx?$": "@swc/jest"
},
"setupFiles": [
"jest-canvas-mock"
],
Expand All @@ -144,4 +149,4 @@
"printBasicPrototype": false
}
}
}
}
22 changes: 22 additions & 0 deletions packages/amis-core/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"runtime": "classic"
}
},
"keepClassNames": true,
"externalHelpers": true,
"loose": false
},
"minify": false
}
9 changes: 2 additions & 7 deletions packages/amis-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@
"js"
],
"transform": {
"\\.(ts|tsx)$": [
"ts-jest",
{
"diagnostics": false
}
]
"^.+\\.(t|j)sx?$": "@swc/jest"
},
"setupFiles": [
"jest-canvas-mock"
Expand All @@ -109,4 +104,4 @@
]
},
"gitHead": "37d23b4a8eb1c663bc38e8dd9040889ea1526ec4"
}
}
9 changes: 2 additions & 7 deletions packages/amis-formula/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@
"js"
],
"transform": {
"\\.(ts|tsx)$": [
"ts-jest",
{
"diagnostics": false
}
]
"^.+\\.(t|j)sx?$": "@swc/jest"
},
"setupFiles": [
"jest-canvas-mock"
Expand All @@ -119,4 +114,4 @@
}
},
"gitHead": "37d23b4a8eb1c663bc38e8dd9040889ea1526ec4"
}
}
2 changes: 1 addition & 1 deletion packages/amis-theme-editor-helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"module": "esm/index.js",
"types": "lib/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\"",
"test": "echo \"Warnings: no test specified\"",
"build": "npm run clean-dist && NODE_ENV=production rollup -c ",
"clean-dist": "rimraf lib/** esm/**",
"i18n:update": "npx i18n update --config=./i18nConfig.js",
Expand Down
9 changes: 2 additions & 7 deletions packages/amis-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,7 @@
"js"
],
"transform": {
"\\.(ts|tsx)$": [
"ts-jest",
{
"diagnostics": false
}
]
"^.+\\.(t|j)sx?$": "@swc/jest"
},
"setupFiles": [
"jest-canvas-mock"
Expand All @@ -148,4 +143,4 @@
]
},
"gitHead": "37d23b4a8eb1c663bc38e8dd9040889ea1526ec4"
}
}
22 changes: 22 additions & 0 deletions packages/amis/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"runtime": "classic"
}
},
"keepClassNames": true,
"externalHelpers": true,
"loose": false
},
"minify": false
}
22 changes: 17 additions & 5 deletions packages/amis/__tests__/event-action/dialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {makeEnv, wait} from '../helper';

test('1. EventAction:dialog args', async () => {
const notify = jest.fn();
const {getByText, container}: any = render(
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
type: 'page',
Expand Down Expand Up @@ -142,6 +143,8 @@ test('1. EventAction:dialog args', async () => {
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;

// events
fireEvent.click(getByText('打开弹窗'));
Expand Down Expand Up @@ -222,7 +225,8 @@ test('1. EventAction:dialog args', async () => {

test('2. EventAction:dialog', async () => {
const notify = jest.fn();
const {getByText, container}: any = render(
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
type: 'page',
Expand Down Expand Up @@ -356,6 +360,9 @@ test('2. EventAction:dialog', async () => {
)
);

const getByText = renderResult.getByText;
container = renderResult.container;

// events
fireEvent.click(getByText('打开弹窗'));
expect(container).toMatchSnapshot();
Expand Down Expand Up @@ -434,7 +441,8 @@ test('2. EventAction:dialog', async () => {
}, 7000);

test('3. EventAction:dialog data', async () => {
const {getByText, container}: any = render(
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
type: 'page',
Expand Down Expand Up @@ -480,7 +488,8 @@ test('3. EventAction:dialog data', async () => {
})
)
);

const getByText = renderResult.getByText;
container = renderResult.container;
// events
fireEvent.click(getByText('打开弹窗'));
await waitFor(() => {
Expand All @@ -491,7 +500,8 @@ test('3. EventAction:dialog data', async () => {
}, 7000);

test('4. EventAction:dialog data2', async () => {
const {getByText, container}: any = render(
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
type: 'page',
Expand Down Expand Up @@ -535,6 +545,8 @@ test('4. EventAction:dialog data2', async () => {
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;

// events
fireEvent.click(getByText('打开弹窗'));
Expand Down
22 changes: 18 additions & 4 deletions packages/amis/__tests__/event-action/drawer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {makeEnv, wait} from '../helper';

test('EventAction:drawer args', async () => {
const notify = jest.fn();
const {getByText, container}: any = render(
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
type: 'page',
Expand Down Expand Up @@ -142,6 +143,8 @@ test('EventAction:drawer args', async () => {
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;

// events
fireEvent.click(getByText('打开抽屉'));
Expand Down Expand Up @@ -222,7 +225,8 @@ test('EventAction:drawer args', async () => {

test('EventAction:drawer', async () => {
const notify = jest.fn();
const {getByText, container}: any = render(
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
type: 'page',
Expand Down Expand Up @@ -356,6 +360,9 @@ test('EventAction:drawer', async () => {
)
);

const getByText = renderResult.getByText;
container = renderResult.container;

// events
fireEvent.click(getByText('打开抽屉'));
expect(container).toMatchSnapshot();
Expand Down Expand Up @@ -434,7 +441,8 @@ test('EventAction:drawer', async () => {
}, 7000);

test('EventAction:drawer data', async () => {
const {getByText, container}: any = render(
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
type: 'page',
Expand Down Expand Up @@ -480,6 +488,8 @@ test('EventAction:drawer data', async () => {
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;

// events
fireEvent.click(getByText('打开抽屉'));
Expand All @@ -491,7 +501,8 @@ test('EventAction:drawer data', async () => {
}, 7000);

test('EventAction:drawer data2', async () => {
const {getByText, container}: any = render(
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
type: 'page',
Expand Down Expand Up @@ -536,6 +547,9 @@ test('EventAction:drawer data2', async () => {
)
);

const getByText = renderResult.getByText;
container = renderResult.container;

// events
fireEvent.click(getByText('打开抽屉'));
await waitFor(() => {
Expand Down
10 changes: 8 additions & 2 deletions packages/amis/__tests__/event-action/prevent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ test('EventAction:prevent', async () => {
}
})
);
const {getByText, container}: any = render(
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
type: 'page',
Expand Down Expand Up @@ -84,6 +85,8 @@ test('EventAction:prevent', async () => {
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;

fireEvent.click(getByText('打开弹窗'));
await waitFor(() => {
Expand Down Expand Up @@ -111,7 +114,8 @@ test('EventAction:ignoreError', async () => {
}
})
);
const {getByText, container}: any = render(
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
type: 'page',
Expand Down Expand Up @@ -156,6 +160,8 @@ test('EventAction:ignoreError', async () => {
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;

fireEvent.click(getByText('按钮'));
await waitFor(() => {
Expand Down
Loading

0 comments on commit 50a66ef

Please sign in to comment.