Skip to content

Commit 476604d

Browse files
authored
chore: update to use rc-test & father@4 (#611)
* chore: update rc-test * chore: update father * chore: update ci * test: part * test: part * test: part * test: part * test: part * chore: tmp * test: more * test: more * test: more * test: more * test: more * chore: tmp * chore: tmp * chore: clean up * test: more * chore: clean up * test: part * test: part * chore: clean up * chore: bump ci * chore: bump ci * chore: bump ci * docs: use dumi2 * chore: tmp file * chore: bump ci * chore: fix now * chore: bump co * chore: rm npm ci * test: rm umi test * chore: back of ci
1 parent 188e23c commit 476604d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+662
-634
lines changed

.dumirc.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { defineConfig } from 'dumi';
2+
import path from 'path';
3+
4+
const isProdSite =
5+
// 不是预览模式 同时是生产环境
6+
process.env.PREVIEW !== 'true' && process.env.NODE_ENV === 'production';
7+
8+
const name = 'field-form';
9+
10+
export default defineConfig({
11+
alias: {
12+
'rc-field-form$': path.resolve('src'),
13+
'rc-field-form/es': path.resolve('src'),
14+
},
15+
mfsu: false,
16+
favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'],
17+
themeConfig: {
18+
name: 'FieldForm',
19+
logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4',
20+
},
21+
base: isProdSite ? `/${name}/` : '/',
22+
publicPath: isProdSite ? `/${name}/` : '/',
23+
});

.fatherrc.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
export default {
2-
cjs: 'babel',
3-
esm: { type: 'babel', importLibToEs: true },
4-
runtimeHelpers: true,
5-
preCommit: {
6-
eslint: true,
7-
prettier: true,
8-
},
9-
};
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
@@ -15,7 +15,7 @@ jobs:
1515

1616
- uses: actions/setup-node@v1
1717
with:
18-
node-version: '12'
18+
node-version: '16'
1919

2020
- name: cache package-lock.json
2121
uses: actions/cache@v2

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
.umi-production
2626
.umi-test
2727
.env.local
28+
.dumi/

.umirc.ts

-19
This file was deleted.

docs/demo/basic.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
## basic
22

33

4-
<code src="../examples/basic.tsx" />
4+
<code src="../examples/basic.tsx"></code>

docs/demo/component.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## component
22

3-
<code src="../examples/component.tsx" />
3+
<code src="../examples/component.tsx"></code>

docs/demo/context.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## context
22

3-
<code src="../examples/context.tsx" />
3+
<code src="../examples/context.tsx"></code>

docs/demo/deps.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
## deps
22

33

4-
<code src="../examples/deps.tsx" />
4+
<code src="../examples/deps.tsx"></code>

docs/demo/initialValues.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
## initialValues
22

33

4-
<code src="../examples/initialValues.tsx" />
4+
<code src="../examples/initialValues.tsx"></code>

docs/demo/layout.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## layout
22

3-
<code src="../examples/layout.tsx" />
3+
<code src="../examples/layout.tsx"></code>

docs/demo/list.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## list
22

3-
<code src="../examples/list.tsx" />
3+
<code src="../examples/list.tsx"></code>

docs/demo/preserve.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
## preserve
22

33

4-
<code src="../examples/preserve.tsx" />
4+
<code src="../examples/preserve.tsx"></code>

docs/demo/redux.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## redux
22

3-
<code src="../examples/redux.tsx" />
3+
<code src="../examples/redux.tsx"></code>

docs/demo/renderProps.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## renderProps
22

3-
<code src="../examples/renderProps.tsx" />
3+
<code src="../examples/renderProps.tsx"></code>

docs/demo/reset.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## reset
22

3-
<code src="../examples/reset.tsx" />
3+
<code src="../examples/reset.tsx"></code>

docs/demo/stateForm-list-draggable.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## stateForm-list-draggable
22

3-
<code src="../examples/stateForm-list-draggable.tsx" />
3+
<code src="../examples/stateForm-list-draggable.tsx"></code>

docs/demo/useForm.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## useForm
22

3-
<code src="../examples/useForm.tsx" />
3+
<code src="../examples/useForm.tsx"></code>

docs/demo/useWatch-list.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## useWatch-list
22

3-
<code src="../examples/useWatch-list.tsx" />
3+
<code src="../examples/useWatch-list.tsx"></code>

docs/demo/useWatch.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## useWatch
22

3-
<code src="../examples/useWatch.tsx" />
3+
<code src="../examples/useWatch.tsx"></code>

docs/demo/validate-perf.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## validate-perf
22

3-
<code src="../examples/validate-perf.tsx" />
3+
<code src="../examples/validate-perf.tsx"></code>

docs/demo/validate.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## validate
22

3-
<code src="../examples/validate.tsx" />
3+
<code src="../examples/validate.tsx"></code>

docs/demo/validateOnly.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## validateOnly
22

3-
<code src="../examples/validateOnly.tsx" />
3+
<code src="../examples/validateOnly.tsx"></code>

jest.config.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import type { Config } from 'jest';
2-
3-
const config: Config = {
1+
export default {
42
setupFilesAfterEnv: ['<rootDir>/tests/setupAfterEnv.ts'],
53
};
6-
7-
export default config;

now.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"src": "package.json",
77
"use": "@now/static-build",
8-
"config": { "distDir": ".doc" }
8+
"config": { "distDir": "dist" }
99
}
1010
],
1111
"routes": [

package.json

+13-17
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
"start": "dumi dev",
3535
"docs:build": "dumi build",
3636
"docs:deploy": "gh-pages -d docs-dist",
37-
"compile": "father-build",
37+
"compile": "father build",
3838
"deploy": "npm run docs:build && npm run docs:deploy",
3939
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
40-
"test": "father test",
40+
"test": "rc-test",
4141
"test:coverage": "umi-test --coverage",
4242
"prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish",
4343
"lint": "eslint src/ --ext .tsx,.ts",
@@ -54,32 +54,28 @@
5454
"rc-util": "^5.32.2"
5555
},
5656
"devDependencies": {
57-
"@testing-library/jest-dom": "^5.16.4",
58-
"@testing-library/react": "^12.1.5",
59-
"@types/enzyme": "^3.10.5",
57+
"@rc-component/father-plugin": "^1.0.0",
58+
"@testing-library/jest-dom": "^5.17.0",
59+
"@testing-library/react": "^14.0.0",
6060
"@types/jest": "^29.2.5",
6161
"@types/lodash": "^4.14.135",
6262
"@types/react": "^18.0.0",
6363
"@types/react-dom": "^18.0.0",
6464
"@umijs/fabric": "^2.5.2",
65-
"@umijs/test": "^3.2.27",
66-
"dumi": "^1.1.0",
67-
"enzyme": "^3.1.0",
68-
"enzyme-adapter-react-16": "^1.0.2",
69-
"enzyme-to-json": "^3.1.4",
65+
"dumi": "^2.0.0",
7066
"eslint": "^7.18.0",
71-
"father": "^2.13.6",
72-
"father-build": "^1.18.6",
67+
"father": "^4.0.0",
7368
"gh-pages": "^3.1.0",
74-
"jest": "^29.3.1",
69+
"jest": "^29.0.0",
7570
"np": "^5.0.3",
7671
"prettier": "^2.1.2",
77-
"react": "^16.14.0",
72+
"rc-test": "^7.0.15",
73+
"react": "^18.0.0",
7874
"react-dnd": "^8.0.3",
7975
"react-dnd-html5-backend": "^8.0.3",
80-
"react-dom": "^16.14.0",
81-
"react-redux": "^4.4.10",
82-
"redux": "^3.7.2",
76+
"react-dom": "^18.0.0",
77+
"react-redux": "^8.1.2",
78+
"redux": "^4.2.1",
8379
"typescript": "^5.1.6"
8480
}
8581
}

src/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ RefForm.List = List;
3131
RefForm.useForm = useForm;
3232
RefForm.useWatch = useWatch;
3333

34-
export { FormInstance, Field, List, useForm, FormProvider, FieldContext, ListContext, useWatch };
34+
export { Field, List, useForm, FormProvider, FieldContext, ListContext, useWatch };
3535

36-
export type { FormProps };
36+
export type { FormProps, FormInstance };
3737

3838
export default RefForm;

src/interface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export interface FormInstance<Values = any> {
260260
((allFieldsTouched?: boolean) => boolean);
261261
isFieldTouched: (name: NamePath) => boolean;
262262
isFieldValidating: (name: NamePath) => boolean;
263-
isFieldsValidating: (nameList: NamePath[]) => boolean;
263+
isFieldsValidating: (nameList?: NamePath[]) => boolean;
264264
resetFields: (fields?: NamePath[]) => void;
265265
setFields: (fields: FieldData[]) => void;
266266
setFieldValue: (name: NamePath, value: any) => void;

tests/common/InfoField.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const InfoField: React.FC<InfoFieldProps> = ({ children, ...props }) => (
1919
const { errors, warnings, validating } = info;
2020

2121
return (
22-
<div>
22+
<div className='field'>
2323
{children ? React.cloneElement(children, control) : <Input {...control} />}
2424
<ul className="errors">
2525
{errors.map((error, index) => (

tests/common/index.ts

+44-31
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,72 @@
11
import { act } from 'react-dom/test-utils';
2-
import type { ReactWrapper } from 'enzyme';
32
import timeout from './timeout';
4-
import { Field } from '../../src';
5-
import { getNamePath, matchNamePath } from '../../src/utils/valueUtil';
3+
import { matchNamePath } from '../../src/utils/valueUtil';
4+
import { fireEvent } from '@testing-library/react';
65

7-
export async function changeValue(wrapper: ReactWrapper, value: string | string[]) {
8-
wrapper.find('input').simulate('change', { target: { value } });
9-
await act(async () => {
10-
await timeout();
11-
});
12-
wrapper.update();
6+
export function getInput(
7+
container: HTMLElement,
8+
dataNameOrIndex?: string | number,
9+
parentField = false,
10+
): HTMLInputElement {
11+
let ele: HTMLInputElement | null = null;
12+
13+
if (!dataNameOrIndex) {
14+
ele = container.querySelector('input');
15+
} else if (typeof dataNameOrIndex === 'number') {
16+
ele = container.querySelectorAll('input')[dataNameOrIndex];
17+
} else {
18+
ele = container.querySelector(`[data-name="${dataNameOrIndex}"]`);
19+
}
20+
21+
if (parentField) {
22+
return ele.closest('.field');
23+
}
24+
25+
return ele!;
26+
}
27+
28+
export async function changeValue(wrapper: HTMLElement, value: string | string[]) {
29+
const values = Array.isArray(value) ? value : [value];
30+
31+
for (let i = 0; i < values.length; i += 1) {
32+
fireEvent.change(wrapper, { target: { value: values[i] } });
33+
34+
await act(async () => {
35+
await timeout();
36+
});
37+
}
38+
39+
return;
1340
}
1441

1542
export function matchError(
16-
wrapper: ReactWrapper,
43+
wrapper: HTMLElement,
1744
error?: boolean | string,
1845
warning?: boolean | string,
1946
) {
2047
// Error
2148
if (error) {
22-
expect(wrapper.find('.errors li').length).toBeTruthy();
49+
expect(wrapper.querySelector('.errors li')).toBeTruthy();
2350
} else {
24-
expect(wrapper.find('.errors li').length).toBeFalsy();
51+
expect(wrapper.querySelector('.errors li')).toBeFalsy();
2552
}
2653

2754
if (error && typeof error !== 'boolean') {
28-
expect(wrapper.find('.errors li').text()).toBe(error);
55+
expect(wrapper.querySelector('.errors li').textContent).toBe(error);
2956
}
3057

3158
// Warning
3259
if (warning) {
33-
expect(wrapper.find('.warnings li').length).toBeTruthy();
60+
expect(wrapper.querySelector('.warnings li')).toBeTruthy();
3461
} else {
35-
expect(wrapper.find('.warnings li').length).toBeFalsy();
62+
expect(wrapper.querySelector('.warnings li')).toBeFalsy();
3663
}
3764

3865
if (warning && typeof warning !== 'boolean') {
39-
expect(wrapper.find('.warnings li').text()).toBe(warning);
66+
expect(wrapper.querySelector('.warnings li').textContent).toBe(warning);
4067
}
41-
}
4268

43-
export function getField(wrapper: ReactWrapper, index: string | number | string[] = 0) {
44-
if (typeof index === 'number') {
45-
return wrapper.find(Field).at(index);
46-
}
47-
const name = getNamePath(index);
48-
const fields = wrapper.find(Field);
49-
for (let i = 0; i < fields.length; i += 1) {
50-
const field = fields.at(i);
51-
const fieldName = getNamePath((field.props() as any).name);
52-
if (matchNamePath(name, fieldName)) {
53-
return field;
54-
}
55-
}
56-
return null;
69+
return;
5770
}
5871

5972
export function matchArray(source: any[], target: any[], matchKey: React.Key) {

tests/common/timeout.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default (timeout: number = 0) => {
1+
export default async (timeout: number = 10) => {
22
return new Promise<void>(resolve => {
33
setTimeout(resolve, timeout);
44
});

0 commit comments

Comments
 (0)