Skip to content

Commit 5ea5394

Browse files
authored
chore: bump father & vitest (#308)
* chore: bump father & vitest * chore: code clena * chore: update
1 parent 3af0481 commit 5ea5394

13 files changed

+80
-57
lines changed

.eslintrc.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
const base = require('@umijs/fabric/dist/eslint');
2-
const path = require('path');
3-
41
module.exports = {
5-
...base,
2+
extends: [require.resolve('@umijs/fabric/dist/eslint')],
63
rules: {
7-
...base.rules,
84
'react/sort-comp': 0,
95
'react/require-default-props': 0,
106
'jsx-a11y/no-noninteractive-tabindex': 0,

.fatherrc.js

-9
This file was deleted.

.fatherrc.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineConfig } from 'father';
2+
3+
export default defineConfig({
4+
plugins: ['@rc-component/father-plugin'],
5+
});

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@ jobs:
108108
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
109109

110110
- name: coverage
111-
run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash)
111+
run: npm run coverage && bash <(curl -s https://codecov.io/bash)
112112

113113
needs: setup

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

package.json

+23-10
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,51 @@
4141
"compile": "father build && lessc assets/index.less assets/index.css",
4242
"prepublishOnly": "npm run compile && np --yolo --no-publish",
4343
"lint": "eslint src/ docs/examples/ --ext .tsx,.ts,.jsx,.js",
44-
"test": "father test",
45-
"now-build": "npm run build"
44+
"test": "vitest",
45+
"coverage": "vitest run --coverage",
46+
"now-build": "npm run build",
47+
"prepare": "husky install"
4648
},
4749
"peerDependencies": {
4850
"react": ">=16.9.0",
4951
"react-dom": ">=16.9.0"
5052
},
5153
"devDependencies": {
52-
"@testing-library/jest-dom": "^5.16.4",
53-
"@testing-library/react": "^13.0.1",
54+
"@rc-component/father-plugin": "^1.0.2",
55+
"@testing-library/jest-dom": "^5.0.0",
56+
"@testing-library/react": "^13.0.0",
5457
"@types/classnames": "^2.2.10",
55-
"@types/enzyme": "^3.10.7",
56-
"@types/jest": "^26.0.4",
5758
"@types/react": "^18.0.0",
5859
"@types/react-dom": "^18.0.0",
60+
"@types/testing-library__jest-dom": "^5.0.0",
61+
"@umijs/fabric": "^2.0.0",
62+
"@vitest/coverage-v8": "^0.34.2",
5963
"cross-env": "^7.0.0",
6064
"dumi": "^2.1.0",
61-
"enzyme": "^3.3.0",
62-
"enzyme-to-json": "^3.4.0",
6365
"eslint": "^7.8.1",
64-
"father": "^2.13.2",
66+
"father": "^4.0.0",
6567
"gh-pages": "^3.1.0",
68+
"husky": "^8.0.3",
69+
"jsdom": "^22.1.0",
6670
"less": "^3.10.3",
71+
"lint-staged": "^14.0.1",
6772
"np": "^6.0.0",
73+
"prettier": "^3.0.2",
6874
"react": "^18.0.0",
6975
"react-dom": "^18.0.0",
70-
"typescript": "^4.0.5"
76+
"typescript": "^4.0.5",
77+
"vitest": "^0.34.2"
7178
},
7279
"dependencies": {
7380
"@babel/runtime": "^7.10.1",
7481
"classnames": "2.x",
7582
"rc-motion": "^2.6.0",
7683
"rc-util": "^5.20.1"
84+
},
85+
"lint-staged": {
86+
"**/*.{js,jsx,tsx,ts,md,json}": [
87+
"prettier --write",
88+
"git add"
89+
]
7790
}
7891
}

tests/hooks.test.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ require('../assets/index.less');
77

88
describe('Notification.Hooks', () => {
99
beforeEach(() => {
10-
jest.useFakeTimers();
10+
vi.useFakeTimers();
1111
});
1212

1313
afterEach(() => {
14-
jest.useRealTimers();
14+
vi.useRealTimers();
1515
});
1616

1717
function renderDemo(config?: NotificationConfig) {
@@ -60,7 +60,7 @@ describe('Notification.Hooks', () => {
6060
expect(document.querySelector('.context-content').textContent).toEqual('bamboo');
6161

6262
act(() => {
63-
jest.runAllTimers();
63+
vi.runAllTimers();
6464
});
6565
expect(document.querySelectorAll('.rc-notification-notice')).toHaveLength(0);
6666

@@ -101,7 +101,7 @@ describe('Notification.Hooks', () => {
101101
expect(document.querySelector('.context-content').textContent).toEqual('light');
102102

103103
act(() => {
104-
jest.runAllTimers();
104+
vi.runAllTimers();
105105
});
106106
expect(document.querySelector('.context-content').textContent).toEqual('bamboo');
107107

@@ -122,7 +122,7 @@ describe('Notification.Hooks', () => {
122122
expect(document.querySelector('.bamboo')).toBeTruthy();
123123

124124
act(() => {
125-
jest.runAllTimers();
125+
vi.runAllTimers();
126126
});
127127
expect(document.querySelector('.bamboo')).toBeTruthy();
128128

@@ -135,7 +135,7 @@ describe('Notification.Hooks', () => {
135135
});
136136

137137
act(() => {
138-
jest.runAllTimers();
138+
vi.runAllTimers();
139139
});
140140
expect(document.querySelector('.little')).toBeFalsy();
141141

@@ -148,7 +148,7 @@ describe('Notification.Hooks', () => {
148148
});
149149

150150
act(() => {
151-
jest.runAllTimers();
151+
vi.runAllTimers();
152152
});
153153
expect(document.querySelector('.light')).toBeTruthy();
154154
});

tests/index.test.tsx

+16-16
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ require('../assets/index.less');
1010
// This only test for hooks usage.
1111
describe('Notification.Basic', () => {
1212
beforeEach(() => {
13-
jest.useFakeTimers();
13+
vi.useFakeTimers();
1414
});
1515

1616
afterEach(() => {
17-
jest.useRealTimers();
17+
vi.useRealTimers();
1818
});
1919

2020
function renderDemo(config?: NotificationConfig) {
@@ -44,7 +44,7 @@ describe('Notification.Basic', () => {
4444
expect(document.querySelector('.test')).toBeTruthy();
4545

4646
act(() => {
47-
jest.runAllTimers();
47+
vi.runAllTimers();
4848
});
4949
expect(document.querySelector('.test')).toBeFalsy();
5050

@@ -87,7 +87,7 @@ describe('Notification.Basic', () => {
8787
expect(document.querySelectorAll('.test')).toHaveLength(2);
8888

8989
act(() => {
90-
jest.runAllTimers();
90+
vi.runAllTimers();
9191
});
9292
expect(document.querySelectorAll('.test')).toHaveLength(0);
9393
});
@@ -170,7 +170,7 @@ describe('Notification.Basic', () => {
170170
fireEvent.click(document.querySelector('#closeButton'));
171171

172172
act(() => {
173-
jest.runAllTimers();
173+
vi.runAllTimers();
174174
});
175175

176176
expect(document.querySelectorAll('.test')).toHaveLength(0);
@@ -228,7 +228,7 @@ describe('Notification.Basic', () => {
228228
expect(document.querySelector('.updatable').textContent).toEqual(newValue);
229229

230230
act(() => {
231-
jest.runAllTimers();
231+
vi.runAllTimers();
232232
});
233233

234234
// Other notices are not affected
@@ -258,14 +258,14 @@ describe('Notification.Basic', () => {
258258
// Mouse in should not remove
259259
fireEvent.mouseEnter(document.querySelector('.rc-notification-notice'));
260260
act(() => {
261-
jest.runAllTimers();
261+
vi.runAllTimers();
262262
});
263263
expect(document.querySelectorAll('.freeze')).toHaveLength(1);
264264

265265
// Mouse out will remove
266266
fireEvent.mouseLeave(document.querySelector('.rc-notification-notice'));
267267
act(() => {
268-
jest.runAllTimers();
268+
vi.runAllTimers();
269269
});
270270
expect(document.querySelectorAll('.freeze')).toHaveLength(0);
271271
});
@@ -329,7 +329,7 @@ describe('Notification.Basic', () => {
329329
});
330330

331331
act(() => {
332-
jest.runAllTimers();
332+
vi.runAllTimers();
333333
});
334334

335335
expect(document.querySelectorAll('.test-maxcount')).toHaveLength(1);
@@ -358,7 +358,7 @@ describe('Notification.Basic', () => {
358358
expect(document.querySelector('.auto-remove').textContent).toEqual('light');
359359

360360
act(() => {
361-
jest.runAllTimers();
361+
vi.runAllTimers();
362362
});
363363
expect(document.querySelectorAll('.auto-remove')).toHaveLength(0);
364364
});
@@ -518,7 +518,7 @@ describe('Notification.Basic', () => {
518518
});
519519

520520
it('motion as function', () => {
521-
const motionFn = jest.fn();
521+
const motionFn = vi.fn();
522522

523523
const { instance } = renderDemo({
524524
motion: motionFn,
@@ -534,7 +534,7 @@ describe('Notification.Basic', () => {
534534
});
535535

536536
it('notice when empty', () => {
537-
const onAllRemoved = jest.fn();
537+
const onAllRemoved = vi.fn();
538538

539539
const { instance } = renderDemo({
540540
onAllRemoved,
@@ -552,7 +552,7 @@ describe('Notification.Basic', () => {
552552

553553
// Hide
554554
act(() => {
555-
jest.runAllTimers();
555+
vi.runAllTimers();
556556
});
557557
expect(onAllRemoved).toHaveBeenCalled();
558558

@@ -589,7 +589,7 @@ describe('Notification.Basic', () => {
589589
});
590590

591591
it('when the same key message is closing, dont open new until it closed', () => {
592-
const onClose = jest.fn();
592+
const onClose = vi.fn();
593593
const Demo = () => {
594594
const [api, holder] = useNotification();
595595
return (
@@ -620,11 +620,11 @@ describe('Notification.Basic', () => {
620620
const { container: demoContainer, unmount } = render(<Demo />);
621621
fireEvent.click(demoContainer.querySelector('button'));
622622
act(() => {
623-
jest.runAllTimers();
623+
vi.runAllTimers();
624624
});
625625
expect(onClose).not.toHaveBeenCalled();
626626
act(() => {
627-
jest.runAllTimers();
627+
vi.runAllTimers();
628628
});
629629
expect(onClose).toHaveBeenCalled();
630630

tests/setup.js

-1
This file was deleted.

tsconfig.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"target": "esnext",
44
"moduleResolution": "node",
55
"baseUrl": "./",
6-
"jsx": "preserve",
6+
"jsx": "react",
77
"declaration": true,
88
"skipLibCheck": true,
99
"esModuleInterop": true,
1010
"paths": {
1111
"@/*": ["src/*"],
1212
"@@/*": [".dumi/tmp/*"],
1313
"rc-notification": ["src/index.tsx"]
14-
}
15-
},
16-
"include": [".dumi/**/*", ".dumirc.ts", "./src/**/*.ts", "./src/**/*.tsx", "./docs/**/*.tsx"]
14+
},
15+
"types": ["vitest/globals"]
16+
}
1717
}

tsconfig.test.json

-4
This file was deleted.

vitest-setup.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers';
2+
import matchers from '@testing-library/jest-dom/matchers';
3+
import { expect } from 'vitest';
4+
5+
declare module 'vitest' {
6+
interface Assertion<T = any> extends jest.Matchers<void, T>, TestingLibraryMatchers<T, void> {}
7+
}
8+
9+
expect.extend(matchers);

vitest.config.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
include: ['**/tests/*.test.*'],
6+
globals: true,
7+
setupFiles: './vitest-setup.ts',
8+
environment: 'jsdom',
9+
},
10+
});

0 commit comments

Comments
 (0)