GeezerVison is showing github.com — test: add ut for render-core/utils/common · shibiaoz/lowcode-engine@d5daba8
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 clipboard +35-18Lines changed: 35 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -module.exports = { | 2 | | - transform: { | 3 | | - '^.+\\.(ts|tsx)$': 'ts-jest', | 4 | | - '^.+\\.(js|ts|tsx|jsx)$': 'babel-jest', | 5 | | - '^.+\\.(css|less|scss)$': './test/mock/styleMock.js', | 6 | | - }, | 7 | | - // testMatch: ['**/bugs/*.test.ts'], | | 1 | +const fs = require('fs'); | | 2 | +const { join } = require('path'); | | 3 | +const esModules = ['zen-logger'].join('|'); | | 4 | +const pkgNames = fs.readdirSync(join('..')).filter(pkgName => !pkgName.startsWith('.')); | | 5 | + | | 6 | +const jestConfig = { | | 7 | + // transform: { | | 8 | + // // '^.+\\.[jt]sx?$': 'babel-jest', | | 9 | + // '^.+\\.(ts|tsx)$': 'ts-jest', | | 10 | + // // '^.+\\.(js|jsx)$': 'babel-jest', | | 11 | + // }, | 8 | 12 | // testMatch: ['(/tests?/.*(test))\\.[jt]s$'], | 9 | | - // transformIgnorePatterns: [ | 10 | | - // `/node_modules/(?!${esModules})/`, | 11 | | - // ], | 12 | | - testEnvironment: 'jsdom', | | 13 | + // testMatch: ['**/*/common.test.ts'], | | 14 | + transformIgnorePatterns: [ | | 15 | + `/node_modules/(?!${esModules})/`, | | 16 | + ], | | 17 | + setupFiles: ['./tests/fixtures/unhandled-rejection.ts'], | 13 | 18 | moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], | 14 | 19 | collectCoverage: false, | 15 | 20 | collectCoverageFrom: [ | 16 | | - 'src/**/*.{ts,tsx}', | 17 | | - ], | 18 | | - moduleNameMapper: { | 19 | | - '^.+.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub', | 20 | | - }, | 21 | | - setupFilesAfterEnv: [ | 22 | | - './test/setup.ts', | | 21 | + 'src/**/*.ts', | | 22 | + '!src/**/*.d.ts', | | 23 | + '!src/icons/**', | | 24 | + '!src/locale/**', | | 25 | + '!src/builtin-simulator/utils/**', | | 26 | + '!src/plugin/sequencify.ts', | | 27 | + '!src/document/node/exclusive-group.ts', | | 28 | + '!src/document/node/props/value-to-source.ts', | | 29 | + '!src/builtin-simulator/live-editing/live-editing.ts', | | 30 | + '!src/designer/offset-observer.ts', | | 31 | + '!src/designer/clipboard.ts', | | 32 | + '!**/node_modules/**', | | 33 | + '!**/vendor/**', | 23 | 34 | ], | 24 | 35 | }; | | 36 | + | | 37 | +// 只对本仓库内的 pkg 做 mapping | | 38 | +jestConfig.moduleNameMapper = {}; | | 39 | +jestConfig.moduleNameMapper[`^@alilc/lowcode\\-(${pkgNames.join('|')})$`] = '<rootDir>/../$1/src'; | | 40 | + | | 41 | +module.exports = jestConfig; |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/package.json +9-4Lines changed: 9 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 | "es" | 11 | 11 | ], | 12 | 12 | "scripts": { | | 13 | + "build": "build-scripts build --skip-demo", | 13 | 14 | "test": "build-scripts test --config build.test.json", | 14 | | - "build": "build-scripts build --skip-demo" | | 15 | + "test:cov": "build-scripts test --config build.test.json --jest-coverage" | 15 | 16 | }, | 16 | 17 | "dependencies": { | 17 | 18 | "@alilc/lowcode-datasource-engine": "^1.0.0", | | 32 | 33 | "zen-logger": "^1.1.4" | 33 | 34 | }, | 34 | 35 | "devDependencies": { | | 36 | + "@alilc/lowcode-designer": "^1.0.5", | 35 | 37 | "@alib/build-scripts": "^0.1.18", | | 38 | + "@alilc/lowcode-test-mate": "^1.0.1", | 36 | 39 | "@babel/plugin-transform-typescript": "^7.16.8", | | 40 | + "@testing-library/react": "^11.2.2", | 37 | 41 | "@types/classnames": "^2.2.11", | 38 | 42 | "@types/debug": "^4.1.5", | | 43 | + "@types/jest": "^26.0.16", | 39 | 44 | "@types/lodash": "^4.14.167", | 40 | 45 | "@types/node": "^13.7.1", | 41 | 46 | "@types/prop-types": "^15.7.3", | 42 | 47 | "@types/react-test-renderer": "^17.0.1", | 43 | 48 | "@types/serialize-javascript": "^5.0.0", | 44 | | - "babel-jest": "^27.4.6", | | 49 | + "babel-jest": "^26.5.2", | 45 | 50 | "build-plugin-component": "^0.2.11", | 46 | | - "jest": "^27.4.7", | | 51 | + "jest": "^26.6.3", | 47 | 52 | "react-test-renderer": "^17.0.2", | 48 | | - "ts-jest": "^27.1.3" | | 53 | + "ts-jest": "^26.5.0" | 49 | 54 | }, | 50 | 55 | "publishConfig": { | 51 | 56 | "access": "public", | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/renderer/addon.tsx +1-16Lines changed: 1 addition & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import PropTypes from 'prop-types'; | 2 | 2 | import baseRendererFactory from './base'; | 3 | | -import { isEmpty, goldlog } from '../utils'; | | 3 | +import { isEmpty } from '../utils'; | 4 | 4 | import { IRendererAppHelper, IBaseRendererProps, IBaseRenderComponent } from '../types'; | 5 | 5 |
| 6 | 6 | export default function addonRendererFactory(): IBaseRenderComponent { | @@ -57,21 +57,6 @@ export default function addonRendererFactory(): IBaseRenderComponent { | 57 | 57 | } | 58 | 58 | } | 59 | 59 |
| 60 | | - goldlog = (goKey: string, params: any) => { | 61 | | - const { addonKey, addonConfig = {} } = this.props.config || {}; | 62 | | - goldlog( | 63 | | - goKey, | 64 | | - { | 65 | | - addonKey, | 66 | | - package: addonConfig.package, | 67 | | - version: addonConfig.version, | 68 | | - ...this.appHelper.logParams, | 69 | | - ...params, | 70 | | - }, | 71 | | - 'addon', | 72 | | - ); | 73 | | - }; | 74 | | - | 75 | 60 | get utils() { | 76 | 61 | const { utils = {} } = this.context.config || {}; | 77 | 62 | return { ...this.appHelper.utils, ...utils }; | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/renderer/base.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -930,7 +930,7 @@ export default function baseRendererFactory(): IBaseRenderComponent { | 930 | 930 |
| 931 | 931 | const buitin = capitalizeFirstLetter(this.__namespace); | 932 | 932 | const componentNames = [buitin, ...extraComponents]; | 933 | | - return !isSchema(schema, true) || !componentNames.includes(schema?.componentName ?? ''); | | 933 | + return !isSchema(schema) || !componentNames.includes(schema?.componentName ?? ''); | 934 | 934 | }; | 935 | 935 |
| 936 | 936 | get requestHandlersMap() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/renderer/renderer.tsx +1-9Lines changed: 1 addition & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import Debug from 'debug'; | 2 | 2 | import adapter from '../adapter'; | 3 | 3 | import contextFactory from '../context'; | 4 | | -import { isFileSchema, goldlog, isEmpty } from '../utils'; | | 4 | +import { isFileSchema, isEmpty } from '../utils'; | 5 | 5 | import baseRendererFactory from './base'; | 6 | 6 | import divFactory from '../components/Div'; | 7 | 7 | import { IGeneralConstructor, IRenderComponent, IRendererProps, IRendererState } from '../types'; | @@ -71,14 +71,6 @@ export default function rendererFactory(): IRenderComponent { | 71 | 71 | } | 72 | 72 |
| 73 | 73 | async componentDidMount() { | 74 | | - goldlog( | 75 | | - 'EXP', | 76 | | - { | 77 | | - action: 'appear', | 78 | | - value: !!this.props.designMode, | 79 | | - }, | 80 | | - 'renderer', | 81 | | - ); | 82 | 74 | debug(`entry.componentDidMount - ${this.props.schema && this.props.schema.componentName}`); | 83 | 75 | } | 84 | 76 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/types/index.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,8 @@ import type { ComponentLifecycle, CSSProperties } from 'react'; | 2 | 2 | import { BuiltinSimulatorHost } from '@alilc/lowcode-designer'; | 3 | 3 | import { RequestHandler, NodeSchema, NodeData, RootSchema, JSONObject } from '@alilc/lowcode-types'; | 4 | 4 |
| | 5 | +export type ISchema = NodeSchema | RootSchema; | | 6 | + | 5 | 7 | /* | 6 | 8 | ** Duck typed component type supporting both react and rax | 7 | 9 | */ | |
|