Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const base = require('@umijs/fabric/dist/eslint');
const path = require('path');

module.exports = {
...base,
extends: [require.resolve('@umijs/fabric/dist/eslint')],
rules: {
...base.rules,
'react/sort-comp': 0,
'react/require-default-props': 0,
'jsx-a11y/no-noninteractive-tabindex': 0,
Expand Down
9 changes: 0 additions & 9 deletions .fatherrc.js

This file was deleted.

5 changes: 5 additions & 0 deletions .fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'father';

export default defineConfig({
plugins: ['@rc-component/father-plugin'],
});
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ jobs:
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

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

needs: setup
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
33 changes: 23 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,51 @@
"compile": "father build && lessc assets/index.less assets/index.css",
"prepublishOnly": "npm run compile && np --yolo --no-publish",
"lint": "eslint src/ docs/examples/ --ext .tsx,.ts,.jsx,.js",
"test": "father test",
"now-build": "npm run build"
"test": "vitest",
"coverage": "vitest run --coverage",
"now-build": "npm run build",
"prepare": "husky install"
},
"peerDependencies": {
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.0.1",
"@rc-component/father-plugin": "^1.0.2",
"@testing-library/jest-dom": "^5.0.0",
"@testing-library/react": "^13.0.0",
"@types/classnames": "^2.2.10",
"@types/enzyme": "^3.10.7",
"@types/jest": "^26.0.4",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/testing-library__jest-dom": "^5.0.0",
"@umijs/fabric": "^2.0.0",
"@vitest/coverage-v8": "^0.34.2",
"cross-env": "^7.0.0",
"dumi": "^2.1.0",
"enzyme": "^3.3.0",
"enzyme-to-json": "^3.4.0",
"eslint": "^7.8.1",
"father": "^2.13.2",
"father": "^4.0.0",
"gh-pages": "^3.1.0",
"husky": "^8.0.3",
"jsdom": "^22.1.0",
"less": "^3.10.3",
"lint-staged": "^14.0.1",
"np": "^6.0.0",
"prettier": "^3.0.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"typescript": "^4.0.5"
"typescript": "^4.0.5",
"vitest": "^0.34.2"
},
"dependencies": {
"@babel/runtime": "^7.10.1",
"classnames": "2.x",
"rc-motion": "^2.6.0",
"rc-util": "^5.20.1"
},
"lint-staged": {
"**/*.{js,jsx,tsx,ts,md,json}": [
"prettier --write",
"git add"
]
}
}
14 changes: 7 additions & 7 deletions tests/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ require('../assets/index.less');

describe('Notification.Hooks', () => {
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});

afterEach(() => {
jest.useRealTimers();
vi.useRealTimers();
});

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

act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(document.querySelectorAll('.rc-notification-notice')).toHaveLength(0);

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

act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(document.querySelector('.context-content').textContent).toEqual('bamboo');

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

act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(document.querySelector('.bamboo')).toBeTruthy();

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

act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(document.querySelector('.little')).toBeFalsy();

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

act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(document.querySelector('.light')).toBeTruthy();
});
Expand Down
32 changes: 16 additions & 16 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ require('../assets/index.less');
// This only test for hooks usage.
describe('Notification.Basic', () => {
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});

afterEach(() => {
jest.useRealTimers();
vi.useRealTimers();
});

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

act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(document.querySelector('.test')).toBeFalsy();

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

act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(document.querySelectorAll('.test')).toHaveLength(0);
});
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('Notification.Basic', () => {
fireEvent.click(document.querySelector('#closeButton'));

act(() => {
jest.runAllTimers();
vi.runAllTimers();
});

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

act(() => {
jest.runAllTimers();
vi.runAllTimers();
});

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

// Mouse out will remove
fireEvent.mouseLeave(document.querySelector('.rc-notification-notice'));
act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(document.querySelectorAll('.freeze')).toHaveLength(0);
});
Expand Down Expand Up @@ -329,7 +329,7 @@ describe('Notification.Basic', () => {
});

act(() => {
jest.runAllTimers();
vi.runAllTimers();
});

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

act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(document.querySelectorAll('.auto-remove')).toHaveLength(0);
});
Expand Down Expand Up @@ -518,7 +518,7 @@ describe('Notification.Basic', () => {
});

it('motion as function', () => {
const motionFn = jest.fn();
const motionFn = vi.fn();

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

it('notice when empty', () => {
const onAllRemoved = jest.fn();
const onAllRemoved = vi.fn();

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

// Hide
act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(onAllRemoved).toHaveBeenCalled();

Expand Down Expand Up @@ -589,7 +589,7 @@ describe('Notification.Basic', () => {
});

it('when the same key message is closing, dont open new until it closed', () => {
const onClose = jest.fn();
const onClose = vi.fn();
const Demo = () => {
const [api, holder] = useNotification();
return (
Expand Down Expand Up @@ -620,11 +620,11 @@ describe('Notification.Basic', () => {
const { container: demoContainer, unmount } = render(<Demo />);
fireEvent.click(demoContainer.querySelector('button'));
act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(onClose).not.toHaveBeenCalled();
act(() => {
jest.runAllTimers();
vi.runAllTimers();
});
expect(onClose).toHaveBeenCalled();

Expand Down
1 change: 0 additions & 1 deletion tests/setup.js

This file was deleted.

8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"target": "esnext",
"moduleResolution": "node",
"baseUrl": "./",
"jsx": "preserve",
"jsx": "react",
"declaration": true,
"skipLibCheck": true,
"esModuleInterop": true,
"paths": {
"@/*": ["src/*"],
"@@/*": [".dumi/tmp/*"],
"rc-notification": ["src/index.tsx"]
}
},
"include": [".dumi/**/*", ".dumirc.ts", "./src/**/*.ts", "./src/**/*.tsx", "./docs/**/*.tsx"]
},
"types": ["vitest/globals"]
}
}
4 changes: 0 additions & 4 deletions tsconfig.test.json

This file was deleted.

9 changes: 9 additions & 0 deletions vitest-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers';
import matchers from '@testing-library/jest-dom/matchers';
import { expect } from 'vitest';

declare module 'vitest' {
interface Assertion<T = any> extends jest.Matchers<void, T>, TestingLibraryMatchers<T, void> {}
}

expect.extend(matchers);
10 changes: 10 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
include: ['**/tests/*.test.*'],
globals: true,
setupFiles: './vitest-setup.ts',
environment: 'jsdom',
},
});