8000 test: add ut for render-core/utils/common · fegg/lowcode-engine@d5daba8 · GitHub
[go: up one dir, main page]

Skip to content

Commit d5daba8

Browse files
JackLianliujuping
authored andcommitted
test: add ut for render-core/utils/common
1 parent e08084e commit d5daba8

File tree

24 files changed

+2666
-643
lines changed

24 files changed

+2666
-643
lines changed
Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
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+
// },
812
// 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'],
1318
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
1419
collectCoverage: false,
1520
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/**',
2334
],
2435
};
36+
37+
// 只对本仓库内的 pkg 做 mapping
38+
jestConfig.moduleNameMapper = {};
39+
jestConfig.moduleNameMapper[`^@alilc/lowcode\\-(${pkgNames.join('|')})$`] = '<rootDir>/../$1/src';
40+
41+
module.exports = jestConfig;

packages/renderer-core/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"es"
1111
],
1212
"scripts": {
13+
"build": "build-scripts build --skip-demo",
1314
"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"
1516
},
1617
"dependencies": {
1718
"@alilc/lowcode-datasource-engine": "^1.0.0",
@@ -32,20 +33,24 @@
3233
"zen-logger": "^1.1.4"
3334
},
3435
"devDependencies": {
36+
"@alilc/lowcode-designer": "^1.0.5",
3537
"@alib/build-scripts": "^0.1.18",
38+
"@alilc/lowcode-test-mate": "^1.0.1",
3639
"@babel/plugin-transform-typescript": "^7.16.8",
40+
"@testing-library/react": "^11.2.2",
3741
"@types/classnames": "^2.2.11",
3842
"@types/debug": "^4.1.5",
43+
"@types/jest": "^26.0.16",
3944
"@types/lodash": "^4.14.167",
4045
"@types/node": "^13.7.1",
4146
"@types/prop-types": "^15.7.3",
4247
"@types/react-test-renderer": "^17.0.1",
4348
"@types/serialize-javascript": "^5.0.0",
44-
"babel-jest": "^27.4.6",
49+
"babel-jest": "^26.5.2",
4550
"build-plugin-component": "^0.2.11",
46-
"jest": "^27.4.7",
51+
"jest": "^26.6.3",
4752
"react-test-renderer": "^17.0.2",
48-
"ts-jest": "^27.1.3"
53+
"ts-jest": "^26.5.0"
4954
},
5055
"publishConfig": {
5156
"access": "public",

packages/renderer-core/src/renderer/addon.tsx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PropTypes from 'prop-types';
22
import baseRendererFactory from './base';
3-
import { isEmpty, goldlog } from '../utils';
3+
import { isEmpty } from '../utils';
44
import { IRendererAppHelper, IBaseRendererProps, IBaseRenderComponent } from '../types';
55

66
export default function addonRendererFactory(): IBaseRenderComponent {
@@ -57,21 +57,6 @@ export default function addonRendererFactory(): IBaseRenderComponent {
5757
}
5858
}
5959

60-
goldlog = (goKey: string, params: any) => {
61-
const { addonKey, addonConfig = {} } = this.props.config || {};
62-
goldlog(
63-
goKey,
64-
{
65-
addonKey,
66-
52E5 package: addonConfig.package,
67-
version: addonConfig.version,
68-
...this.appHelper.logParams,
69-
...params,
70-
},
71-
'addon',
72-
);
73-
};
74-
7560
get utils() {
7661
const { utils = {} } = this.context.config || {};
7762
return { ...this.appHelper.utils, ...utils };

packages/renderer-core/src/renderer/base.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
930930

931931
const buitin = capitalizeFirstLetter(this.__namespace);
932932
const componentNames = [buitin, ...extraComponents];
933-
return !isSchema(schema, true) || !componentNames.includes(schema?.componentName ?? '');
933+
return !isSchema(schema) || !componentNames.includes(schema?.componentName ?? '');
934934
};
935935

936936
get requestHandlersMap() {

packages/renderer-core/src/renderer/renderer.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Debug from 'debug';
22
import adapter from '../adapter';
33
import contextFactory from '../context';
4-
import { isFileSchema, goldlog, isEmpty } from '../utils';
4+
import { isFileSchema, isEmpty } from '../utils';
55
import baseRendererFactory from './base';
66
import divFactory from '../components/Div';
77
import { IGeneralConstructor, IRenderComponent, IRendererProps, IRendererState } from '../types';
@@ -71,14 +71,6 @@ export default function rendererFactory(): IRenderComponent {
7171
}
7272

7373
async componentDidMount() {
74-
goldlog(
75-
'EXP',
76-
{
77-
action: 'appear',
78-
value: !!this.props.designMode,
79-
},
80-
'renderer',
81-
);
8274
debug(`entry.componentDidMount - ${this.props.schema && this.props.schema.componentName}`);
8375
}
8476

packages/renderer-core/src/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { ComponentLifecycle, CSSProperties } from 'react';
22
import { BuiltinSimulatorHost } from '@alilc/lowcode-designer';
33
import { RequestHandler, NodeSchema, NodeData, RootSchema, JSONObject } from '@alilc/lowcode-types';
44

5+
export type ISchema = NodeSchema | RootSchema;
6+
57
/*
68
** Duck typed component type supporting both react and rax
79
*/

0 commit comments

Comments
 (0)
0