GeezerVison is showing github.com — fix(utils): isReactComponent not including react.memo · yanxg/lowcode-engine@6160056
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/cov packages.yml +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 73 | 73 | package-manager: yarn | 74 | 74 | annotations: none | 75 | 75 |
| 76 | | -cov-utils: | | 76 | + cov-utils: | 77 | 77 | runs-on: ubuntu-latest | 78 | 78 | # skip fork's PR, otherwise it fails while making a comment | 79 | 79 | if: ${{ github.event.pull_request.head.repo.full_name == 'alibaba/lowcode-engine' }} | @@ -91,6 +91,6 @@ cov-utils: | 91 | 91 | - uses: ArtiomTr/jest-coverage-report-action@v2 | 92 | 92 | with: | 93 | 93 | working-directory: packages/utils | 94 | | - test-script: npm test | | 94 | + test-script: npm test -- --jest-ci --jest-json --jest-coverage --jest-testLocationInResults --jest-outputFile=report.json | 95 | 95 | package-manager: yarn | 96 | 96 | annotations: none |
Collapse file Copy file name to clipboardExpand all lines: .github/workflows/test packages.yml +50-2Lines changed: 50 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 43 | 43 | - name: test | 44 | 44 | run: cd packages/designer && npm test | 45 | 45 |
| 46 | | - editor-skeleton: | | 46 | + test-editor-skeleton: | 47 | 47 | runs-on: ubuntu-latest | 48 | 48 | steps: | 49 | 49 | - name: checkout | | 57 | 57 | run: npm i && npm run setup:skip-build | 58 | 58 |
| 59 | 59 | - name: test | 60 | | - run: cd packages/editor-skeleton && npm test | | 60 | + run: cd packages/editor-skeleton && npm test | | 61 | + | | 62 | + test-renderer-core: | | 63 | + runs-on: ubuntu-latest | | 64 | + steps: | | 65 | + - name: checkout | | 66 | + uses: actions/checkout@v2 | | 67 | + | | 68 | + - uses: actions/setup-node@v2 | | 69 | + with: | | 70 | + node-version: '14' | | 71 | + | | 72 | + - name: install | | 73 | + run: npm i && npm run setup:skip-build | | 74 | + | | 75 | + - name: test | | 76 | + run: cd packages/renderer-core && npm test | | 77 | + | | 78 | + test-react-simulator-renderer: | | 79 | + runs-on: ubuntu-latest | | 80 | + steps: | | 81 | + - name: checkout | | 82 | + uses: actions/checkout@v2 | | 83 | + | | 84 | + - uses: actions/setup-node@v2 | | 85 | + with: | | 86 | + node-version: '14' | | 87 | + | | 88 | + - name: install | | 89 | + run: npm i && npm run setup:skip-build | | 90 | + | | 91 | + - name: test | | 92 | + run: cd packages/react-simulator-renderer && npm test | | 93 | + | | 94 | + test-utils: | | 95 | + runs-on: ubuntu-latest | | 96 | + steps: | | 97 | + - name: checkout | | 98 | + uses: actions/checkout@v2 | | 99 | + | | 100 | + - uses: actions/setup-node@v2 | | 101 | + with: | | 102 | + node-version: '14' | | 103 | + | | 104 | + - name: install | | 105 | + run: npm i && npm run setup:skip-build | | 106 | + | | 107 | + - name: test | | 108 | + run: cd packages/utils && npm test |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/jest.config.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,7 @@ const jestConfig = { | 11 | 11 | // }, | 12 | 12 | // testMatch: ['(/tests?/.*(test))\\.[jt]s$'], | 13 | 13 | // testMatch: ['**/*/base.test.tsx'], | | 14 | + // testMatch: ['**/utils/common.test.ts'], | 14 | 15 | transformIgnorePatterns: [ | 15 | 16 | `/node_modules/(?!${esModules})/`, | 16 | 17 | ], | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/tests/utils/common.test.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -374,7 +374,7 @@ describe('test parseThisRequiredExpression', () => { | 374 | 374 | }; | 375 | 375 | const fn = logger.error = jest.fn(); | 376 | 376 | parseThisRequiredExpression(mockExpression, { state: { text: 'text' } }); | 377 | | - expect(fn).toBeCalledWith('parseExpression.error', new ReferenceError('state is not defined'), {"type": "JSExpression", "value": "state.text"}, {"state": {"text": "text"}}); | | 377 | + expect(fn).toBeCalledWith(' parseExpression.error', new ReferenceError('state is not defined'), {"type": "JSExpression", "value": "state.text"}, {"state": {"text": "text"}}); | 378 | 378 | }); | 379 | 379 |
| 380 | 380 | it('[success] JSExpression handle without this use scopeValue', () => { | |
Collapse file Copy file name to clipboard +14-3Lines changed: 14 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -module.exports = { | | 1 | +const fs = require('fs'); | | 2 | +const { join } = require('path'); | | 3 | +const pkgNames = fs.readdirSync(join('..')).filter(pkgName => !pkgName.startsWith('.')); | | 4 | + | | 5 | +const jestConfig = { | 2 | 6 | moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], | 3 | | - collectCoverage: true, | | 7 | + collectCoverage: false, | 4 | 8 | collectCoverageFrom: [ | 5 | | - 'src/**/*.{ts,tsx}', | | 9 | + 'src/**/*.ts', | | 10 | + '!src/**/*.d.ts', | 6 | 11 | '!**/node_modules/**', | 7 | 12 | '!**/vendor/**', | 8 | 13 | ], | 9 | 14 | }; | | 15 | + | | 16 | +// 只对本仓库内的 pkg 做 mapping | | 17 | +jestConfig.moduleNameMapper = {}; | | 18 | +jestConfig.moduleNameMapper[`^@alilc/lowcode\\-(${pkgNames.join('|')})$`] = '<rootDir>/../$1/src'; | | 19 | + | | 20 | +module.exports = jestConfig; |
Collapse file Copy file name to clipboardExpand all lines: packages/utils/src/is-react.ts +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import { cloneEnumerableProperty } from './clone-enumerable-property'; | 3 | 3 |
| 4 | 4 | const hasSymbol = typeof Symbol === 'function' && Symbol.for; | 5 | 5 | const REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0; | | 6 | +const REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; | 6 | 7 |
| 7 | 8 | export function isReactClass(obj: any): obj is ComponentClass<any> { | 8 | 9 | return obj && obj.prototype && (obj.prototype.isReactComponent || obj.prototype instanceof Component); | @@ -16,8 +17,16 @@ function isForwardRefType(obj: any): boolean { | 16 | 17 | return obj?.$$typeof && obj?.$$typeof === REACT_FORWARD_REF_TYPE; | 17 | 18 | } | 18 | 19 |
| | 20 | +function isMemoType(obj: any): boolean { | | 21 | + return obj?.$$typeof && obj.$$typeof === REACT_MEMO_TYPE; | | 22 | +} | | 23 | + | 19 | 24 | export function isReactComponent(obj: any): obj is ComponentType<any> { | 20 | | - return obj && (isReactClass(obj) || typeof obj === 'function' || isForwardRefType(obj)); | | 25 | + if (!obj) { | | 26 | + return false; | | 27 | + } | | 28 | + | | 29 | + return Boolean(isReactClass(obj) || typeof obj === 'function' || isForwardRefType(obj) || isMemoType(obj)); | 21 | 30 | } | 22 | 31 |
| 23 | 32 | export function wrapReactClass(view: FunctionComponent) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/utils/test/src/build-components/buildComponents.test.ts +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -309,8 +309,14 @@ describe('build-component', () => { | 309 | 309 | )) | 310 | 310 | .toEqual({ | 311 | 311 | Button: { | 312 | | - componentName: 'Component', | 313 | | - schema: {}, | | 312 | + componentsMap: [], | | 313 | + componentsTree: [ | | 314 | + { | | 315 | + componentName: 'Component', | | 316 | + schema: {}, | | 317 | + } | | 318 | + ], | | 319 | + version: "", | 314 | 320 | }, | 315 | 321 | }); | 316 | 322 | }) | |
Collapse file Copy file name to clipboard +38Lines changed: 38 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import React from "react"; | | 2 | +import { isReactComponent, wrapReactClass } from "../../src/is-react"; | | 3 | + | | 4 | +class reactDemo extends React.Component { | | 5 | + | | 6 | +} | | 7 | + | | 8 | +const reactMemo = React.memo(reactDemo); | | 9 | + | | 10 | +const reactForwardRef = React.forwardRef((props, ref): any => { | | 11 | + return ''; | | 12 | +}); | | 13 | + | | 14 | +describe('is-react-ut', () => { | | 15 | + it('isReactComponent', () => { | | 16 | + expect(isReactComponent(null)).toBeFalsy(); | | 17 | + expect(isReactComponent(() => {})).toBeTruthy(); | | 18 | + expect(isReactComponent({ | | 19 | + $$typeof: Symbol.for('react.memo') | | 20 | + })).toBeTruthy(); | | 21 | + expect(isReactComponent({ | | 22 | + $$typeof: Symbol.for('react.forward_ref') | | 23 | + })).toBeTruthy(); | | 24 | + expect(isReactComponent(reactDemo)).toBeTruthy(); | | 25 | + expect(isReactComponent(reactMemo)).toBeTruthy(); | | 26 | + expect(isReactComponent(reactForwardRef)).toBeTruthy(); | | 27 | + | | 28 | + }); | | 29 | + | | 30 | + it('wrapReactClass', () => { | | 31 | + const wrap = wrapReactClass(() => {}); | | 32 | + expect(isReactComponent(wrap)).toBeTruthy(); | | 33 | + | | 34 | + const fun = () => {}; | | 35 | + fun.displayName = 'mock'; | | 36 | + expect(wrapReactClass(fun).displayName).toBe('mock'); | | 37 | + }) | | 38 | +}) |
|