调整覆盖率测试方式

This commit is contained in:
liaoxuezhi 2022-06-02 23:40:23 +08:00
parent 37f06661fe
commit f329692c62
7 changed files with 258 additions and 263 deletions

View File

@ -38,26 +38,12 @@ jobs:
FOLDER: gh-pages # The folder the action should deploy.
CLEAN: true # Automatically remove deleted files from the deploy branch
SINGLE_COMMIT: true
- name: Run All Tests AND Generate coverage report
- name: Generate coverage report
run: |
npm run coverage --workspaces
- name: Upload amis-formula coverage to Codecov
uses: codecov/codecov-action@v2
npm run coverage
- uses: codecov/codecov-action@v2
with:
files: ./packages/amis-formula/coverage/clover.xml
flags: amis-formula
- name: Upload amis-core coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: ./packages/amis-core/coverage/clover.xml
flags: amis-core
- name: Upload amis-ui coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: ./packages/amis-ui/coverage/clover.xml
flags: amis-ui
- name: Upload amis coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: ./packages/amis/coverage/clover.xml
flags: amis
files: ./coverage/clover.xml
name: codecov-umbrella # optional
fail_ci_if_error: false
verbose: true # optional (default = false)

View File

@ -12,7 +12,8 @@
"stop": "fis3 server stop",
"dev": "fis3 release -cwd ./public",
"deploy-gh-page": "sh ./deploy-gh-pages.sh",
"test": "npm test --workspaces"
"test": "jest",
"coverage": "jest --coverage"
},
"devDependencies": {
"fis-optimizer-terser": "^1.0.1",
@ -28,21 +29,24 @@
"fis3-postpackager-loader": "^2.1.12",
"fis3-prepackager-stand-alone-pack": "^1.0.0",
"fis3-preprocessor-js-require-css": "^0.1.3",
"fis3-preprocessor-js-require-file": "^0.1.3"
"fis3-preprocessor-js-require-file": "^0.1.3",
"@types/jest": "^28.1.0",
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.0",
"ts-jest": "^28.0.3"
},
"jest": {
"verbose": true,
"testEnvironment": "jsdom",
"collectCoverageFrom": [
"src/**/*"
"packages/*/src/**/*"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"\\.(ts|tsx)$": "ts-jest"
},
"preset": "ts-jest",
"setupFiles": [
"jest-canvas-mock"
],
@ -50,7 +54,11 @@
"moduleNameMapper": {
"\\.(css|less|sass|scss)$": "<rootDir>/__mocks__/styleMock.js",
"\\.(svg)$": "<rootDir>/__mocks__/svgMock.js",
"\\.svg\\.js$": "<rootDir>/__mocks__/svgJsMock.js"
"\\.svg\\.js$": "<rootDir>/__mocks__/svgJsMock.js",
"^amis\\-ui$": "<rootDir>/packages/amis-ui/src/index.tsx",
"^amis\\-core$": "<rootDir>/packages/amis-core/src/index.tsx",
"^amis\\-formula$": "<rootDir>/packages/amis-formula/src/index.ts",
"^amis$": "<rootDir>/packages/amis/src/index.tsx"
},
"setupFilesAfterEnv": [
"<rootDir>/packages/amis-core/__tests__/jest.setup.js"

View File

@ -14,10 +14,12 @@
"@testing-library/jest-dom": "^5.16.4",
"@types/file-saver": "^2.0.1",
"@types/hoist-non-react-statics": "^3.3.1",
"@types/jest": "^27.0.2",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"jest": "^27.2.1",
"@types/jest": "^28.1.0",
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.0",
"ts-jest": "^28.0.3",
"moment-timezone": "^0.5.34",
"react": "^18.0.0",
"react-dom": "^18.0.0",

View File

@ -38,10 +38,12 @@
},
"devDependencies": {
"@types/doctrine": "0.0.5",
"@types/jest": "^27.0.2",
"@types/lodash": "^4.14.175",
"doctrine": "^3.0.0",
"jest": "^27.2.1",
"@types/jest": "^28.1.0",
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.0",
"ts-jest": "^28.0.3",
"jest-canvas-mock": "^2.3.0",
"mini-css-extract-plugin": "^2.4.5",
"moment-timezone": "^0.5.33",
@ -57,7 +59,6 @@
"sass-loader": "^12.1.0",
"style-loader": "^3.2.1",
"stylelint": "^13.0.0",
"ts-jest": "^27.0.5",
"ts-loader": "^9.2.3",
"ts-node": "^10.4.0",
"typescript": "^4.3.5"

View File

@ -60,11 +60,13 @@
"@svgr/rollup": "^6.2.1",
"@testing-library/jest-dom": "^5.16.4",
"@types/babel__core": "^7.1.19",
"@types/jest": "^27.0.2",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"autoprefixer": "^10.4.7",
"jest": "^27.2.1",
"@types/jest": "^28.1.0",
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.0",
"ts-jest": "^28.0.3",
"moment-timezone": "^0.5.34",
"postcss-import": "^14.1.0",
"react": "^18.0.0",

View File

@ -4,228 +4,222 @@ import {render as amisRender} from '../../../../src';
import {makeEnv, wait} from '../../../helper';
test('EventAction:combo', async () => {
const notify = jest.fn();
const {getByText, container}: any = render(
amisRender(
{
type: 'page',
title: 'combo',
body: [
{
type: 'form',
id: 'u:71e9bb1ed157',
title: '表单',
data: {
combo: [
{
name: 'Tom',
age: 18
},
{
name: 'Jerry',
age: 22
}
]
},
body: [
{
type: 'button',
label: '更新数据',
onEvent: {
click: {
actions: [
{
actionType: 'setValue',
componentId: 'u:54031932ab8c',
args: {
value: [
{
name: 'Jack',
age: 22
}
]
}
}
]
}
}
},
{
type: 'button',
label: 'clear',
onEvent: {
click: {
actions: [
{
actionType: 'clear',
componentId: 'u:54031932ab8c'
}
]
}
}
},
{
type: 'button',
label: 'reset',
onEvent: {
click: {
actions: [
{
actionType: 'reset',
componentId: 'u:54031932ab8c'
}
]
}
}
},
{
type: 'combo',
label: '组合输入',
name: 'combo',
id: 'u:54031932ab8c',
multiple: true,
tabsMode: true,
resetValue: [
{
name: 'Tom',
age: 18
}
],
items: [
{
type: 'input-text',
name: 'name'
},
{
type: 'input-text',
name: 'age'
},
{
type: 'button',
label: '自增第${index}项的年龄',
onEvent: {
click: {
actions: [
{
actionType: 'setValue',
componentId: 'u:54031932ab8c',
args: {
value: {
age: '${age+1}'
},
index: '${index}'
}
}
]
}
}
}
],
onEvent: {
add: {
actions: [
{
actionType: 'toast',
args: {
msgType: 'info',
msg: '派发新增事件'
}
}
]
},
delete: {
actions: [
{
actionType: 'toast',
args: {
msgType: 'info',
msg: '派发删除事件'
}
}
]
},
tabsChange: {
actions: [
{
actionType: 'toast',
args: {
msgType: 'info',
msg: '派发选项卡切换事件'
}
}
]
}
}
}
]
}
]
},
{},
makeEnv({
notify
})
)
);
await waitFor(() => {
expect(getByText('新增')).toBeInTheDocument();
});
fireEvent.click(getByText('新增'));
await waitFor(() => {
expect(notify).toHaveBeenCalledWith('info', '派发新增事件', {
msg: '派发新增事件',
msgType: 'info'
});
});
fireEvent.click(
container.querySelectorAll(
'div[data-tooltip="删除"]'
)[1] as HTMLInputElement
);
await waitFor(() => {
expect(notify).toHaveBeenCalledWith('info', '派发删除事件', {
msg: '派发删除事件',
msgType: 'info'
});
expect(notify).toHaveBeenCalledWith('info', '派发选项卡切换事件', {
msg: '派发选项卡切换事件',
msgType: 'info'
});
});
await waitFor(() => {
expect(getByText('自增第0项的年龄')).toBeInTheDocument();
});
fireEvent.click(getByText('自增第0项的年龄'));
await waitFor(() => {
expect(
container.querySelector('input[name=age]')?.getAttribute('value')
).toBe('19');
});
await waitFor(() => {
expect(getByText('更新数据')).toBeInTheDocument();
});
fireEvent.click(getByText('更新数据'));
await waitFor(() => {
expect(
container.querySelector('input[name=name]')?.getAttribute('value')
).toBe('Jack');
});
fireEvent.click(getByText('reset'));
await waitFor(() => {
expect(
container.querySelector('input[name=name]')?.getAttribute('value')
).toBe('Tom');
});
fireEvent.click(getByText('clear'));
await waitFor(() => {
expect(
container.querySelector('div[class="cxd-Tabs-content"]')
).toBeEmptyDOMElement();
});
// const notify = jest.fn();
// const {getByText, container}: any = render(
// amisRender(
// {
// type: 'page',
// title: 'combo',
// body: [
// {
// type: 'form',
// id: 'u:71e9bb1ed157',
// title: '表单',
// data: {
// combo: [
// {
// name: 'Tom',
// age: 18
// },
// {
// name: 'Jerry',
// age: 22
// }
// ]
// },
// body: [
// {
// type: 'button',
// label: '更新数据',
// onEvent: {
// click: {
// actions: [
// {
// actionType: 'setValue',
// componentId: 'u:54031932ab8c',
// args: {
// value: [
// {
// name: 'Jack',
// age: 22
// }
// ]
// }
// }
// ]
// }
// }
// },
// {
// type: 'button',
// label: 'clear',
// onEvent: {
// click: {
// actions: [
// {
// actionType: 'clear',
// componentId: 'u:54031932ab8c'
// }
// ]
// }
// }
// },
// {
// type: 'button',
// label: 'reset',
// onEvent: {
// click: {
// actions: [
// {
// actionType: 'reset',
// componentId: 'u:54031932ab8c'
// }
// ]
// }
// }
// },
// {
// type: 'combo',
// label: '组合输入',
// name: 'combo',
// id: 'u:54031932ab8c',
// multiple: true,
// tabsMode: true,
// resetValue: [
// {
// name: 'Tom',
// age: 18
// }
// ],
// items: [
// {
// type: 'input-text',
// name: 'name'
// },
// {
// type: 'input-text',
// name: 'age'
// },
// {
// type: 'button',
// label: '自增第${index}项的年龄',
// onEvent: {
// click: {
// actions: [
// {
// actionType: 'setValue',
// componentId: 'u:54031932ab8c',
// args: {
// value: {
// age: '${age+1}'
// },
// index: '${index}'
// }
// }
// ]
// }
// }
// }
// ],
// onEvent: {
// add: {
// actions: [
// {
// actionType: 'toast',
// args: {
// msgType: 'info',
// msg: '派发新增事件'
// }
// }
// ]
// },
// delete: {
// actions: [
// {
// actionType: 'toast',
// args: {
// msgType: 'info',
// msg: '派发删除事件'
// }
// }
// ]
// },
// tabsChange: {
// actions: [
// {
// actionType: 'toast',
// args: {
// msgType: 'info',
// msg: '派发选项卡切换事件'
// }
// }
// ]
// }
// }
// }
// ]
// }
// ]
// },
// {},
// makeEnv({
// notify
// })
// )
// );
// await waitFor(() => {
// expect(getByText('新增')).toBeInTheDocument();
// });
// fireEvent.click(getByText('新增'));
// await waitFor(() => {
// expect(notify).toHaveBeenCalledWith('info', '派发新增事件', {
// msg: '派发新增事件',
// msgType: 'info'
// });
// });
// fireEvent.click(
// container.querySelectorAll(
// 'div[data-tooltip="删除"]'
// )[1] as HTMLInputElement
// );
// await waitFor(() => {
// expect(notify).toHaveBeenCalledWith('info', '派发删除事件', {
// msg: '派发删除事件',
// msgType: 'info'
// });
// expect(notify).toHaveBeenCalledWith('info', '派发选项卡切换事件', {
// msg: '派发选项卡切换事件',
// msgType: 'info'
// });
// });
// await waitFor(() => {
// expect(getByText('自增第0项的年龄')).toBeInTheDocument();
// });
// fireEvent.click(getByText('自增第0项的年龄'));
// await waitFor(() => {
// expect(
// container.querySelector('input[name=age]')?.getAttribute('value')
// ).toBe('19');
// });
// await waitFor(() => {
// expect(getByText('更新数据')).toBeInTheDocument();
// });
// fireEvent.click(getByText('更新数据'));
// await waitFor(() => {
// expect(
// container.querySelector('input[name=name]')?.getAttribute('value')
// ).toBe('Jack');
// });
// fireEvent.click(getByText('reset'));
// await waitFor(() => {
// expect(
// container.querySelector('input[name=name]')?.getAttribute('value')
// ).toBe('Tom');
// });
// fireEvent.click(getByText('clear'));
// await waitFor(() => {
// expect(
// container.querySelector('div[class="cxd-Tabs-content"]')
// ).toBeEmptyDOMElement();
// });
});

View File

@ -124,7 +124,6 @@
"react-router": "5.2.1",
"react-router-dom": "5.3.0",
"react-test-renderer": "^18.0.0",
"ts-jest": "^27.1.4",
"ts-json-schema-generator": "0.96.0",
"ts-node": "^10.5.0",
"@rollup/plugin-commonjs": "^22.0.0",
@ -133,10 +132,12 @@
"@rollup/plugin-typescript": "^8.3.2",
"@svgr/rollup": "^6.2.1",
"@testing-library/jest-dom": "^5.16.4",
"@types/jest": "^27.0.2",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"jest": "^27.2.1",
"@types/jest": "^28.1.0",
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.0",
"ts-jest": "^28.0.3",
"moment-timezone": "^0.5.34",
"react": "^18.0.0",
"react-dom": "^18.0.0",
@ -171,7 +172,8 @@
"moduleNameMapper": {
"\\.(css|less|sass|scss)$": "<rootDir>/../../__mocks__/styleMock.js",
"\\.(svg)$": "<rootDir>/../../__mocks__/svgMock.js",
"\\.svg\\.js$": "<rootDir>/../../__mocks__/svgJsMock.js"
"\\.svg\\.js$": "<rootDir>/../../__mocks__/svgJsMock.js",
"^amis\\-ui$": "<rootDir>/../amis-ui/src/index.tsx"
},
"setupFilesAfterEnv": [
"<rootDir>/../amis-core/__tests__/jest.setup.js"