Skip to content

Commit

Permalink
test: use codecov/codecov-action (#554)
Browse files Browse the repository at this point in the history
Co-authored-by: afc163 <[email protected]>
  • Loading branch information
Layouwen and afc163 authored Aug 23, 2024
1 parent 4b0830a commit 23606d8
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 128 deletions.
118 changes: 5 additions & 113 deletions .github/workflows/react-component-ci.yml
Original file line number Diff line number Diff line change
@@ -1,114 +1,6 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

name: ✅ test
on: [push, pull_request]
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- uses: actions/setup-node@v1
with:
node-version: '18'

- name: cache package-lock.json
uses: actions/cache@v2
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: create package-lock.json
run: npm i --package-lock-only --ignore-scripts

- name: hack for singe file
run: |
if [ ! -d "package-temp-dir" ]; then
mkdir package-temp-dir
fi
cp package-lock.json package-temp-dir
- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: install
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
run: npm ci

lint:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: restore cache from package-lock.json
uses: actions/cache@v2
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: lint
run: npm run lint

needs: setup

compile:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: restore cache from package-lock.json
uses: actions/cache@v2
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: compile
run: npm run compile

needs: setup

coverage:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: restore cache from package-lock.json
uses: actions/cache@v2
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

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

needs: setup
test:
uses: react-component/rc-test/.github/workflows/test.yml@main
secrets: inherit
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ es/*
.dumi/tmp-test
.dumi/tmp-production
.env.local

bun.lockb
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[install]
peer = false
2 changes: 1 addition & 1 deletion examples/dynamic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Demo extends React.Component {

loadData = treeNode => {
console.log('trigger load:', treeNode);
return new Promise(resolve => {
return new Promise<void>(resolve => {
setTimeout(() => {
let { treeData } = this.state;
treeData = treeData.slice();
Expand Down
4 changes: 2 additions & 2 deletions examples/utils/dataUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-plusplus, no-mixed-operators, no-underscore-dangle */
export function generateData(x = 3, y = 2, z = 1, gData = []) {
// x:每一级下的节点总数。y:每级节点里有y个节点、存在子节点。z:树的level层级数(0表示一级)
function _loop(_level, _preKey, _tns) {
function _loop(_level, _preKey?, _tns?) {
const preKey = _preKey || '0';
const tns = _tns || gData;

Expand Down Expand Up @@ -88,7 +88,7 @@ export function getNewTreeData(treeData, curKey, child, level) {
}

function loopData(data, callback) {
const loop = (d, level = 0) => {
const loop = (d, level = '0') => {
d.forEach((item, index) => {
const pos = `${level}-${index}`;
if (item.children) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"rc-virtual-list": "^3.0.0",
"react": "^16.8.0",
"react-dom": "^16.8.0",
"typescript": "^5.0.0"
"typescript": "^5.0.0",
"cheerio": "1.0.0-rc.12"
},
"peerDependencies": {
"react": "*",
Expand Down
8 changes: 1 addition & 7 deletions src/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
// Back fill with origin label
const labeledValues = values.map(val => {
const targetItem = rawLabeledValues.find(item => item.value === val);
let label;
// Ensure that when labelInValue is true, if label is undefined, it remains undefined.
if (labelInValue && targetItem.label !== undefined) {
label = targetItem.label;
} else if (!labelInValue && treeTitleRender) {
label = treeTitleRender(targetItem);
}
const label = labelInValue ? targetItem?.label : treeTitleRender?.(targetItem);
return {
value: val,
label,
Expand Down
2 changes: 1 addition & 1 deletion tests/Select.checkable.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ describe('TreeSelect.checkable', () => {
describe('labelInValue', () => {
it('basic', () => {
const wrapper = mount(
<TreeSelect checkable labelInValue value={[{ value: '0-0' }]}>
<TreeSelect treeCheckable showCheckedStrategy="SHOW_PARENT" labelInValue value={[{ value: '0-0' }]}>
<TreeNode key="0-0" value="0-0" title="0-0">
<TreeNode key="0-0-0" value="0-0-0" title="0-0-0" />
</TreeNode>
Expand Down
6 changes: 3 additions & 3 deletions tests/Select.multiple.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('TreeSelect.multiple', () => {

it('remove by backspace key', () => {
const wrapper = mount(createSelect({ defaultValue: ['0', '1'] }));
wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE });
wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE, key: 'Backspace' });
expect(wrapper.getSelection()).toHaveLength(1);
expect(wrapper.getSelection(0).text()).toBe('label0');
});
Expand All @@ -59,9 +59,9 @@ describe('TreeSelect.multiple', () => {
}
}
const wrapper = mount(<App />);
wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE });
wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE, key: 'Backspace' });
wrapper.selectNode(1);
wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE });
wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE, key: 'Backspace' });
expect(wrapper.getSelection()).toHaveLength(1);
expect(wrapper.getSelection(0).text()).toBe('label0');
});
Expand Down

0 comments on commit 23606d8

Please sign in to comment.