GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add ut for render-core/adapter · WonRay/lowcode-engine@567fd56

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/renderer-core
    • src/adapter
      • index.ts
    • tests/adapter
      • adapter.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/renderer-core/src/adapter/index.ts‎

Copy file name to clipboardExpand all lines: packages/renderer-core/src/adapter/index.ts
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ class Adapter {
2525
setState() {}
2626
forceUpdate() {}
2727
render() {}
28-
state: {};
29-
props: {};
30-
refs: {};
31-
context: {};
28+
state: Record<string, unknown>;
29+
props: Record<string, unknown>;
30+
refs: Record<string, unknown>;
31+
context: Record<string, unknown>;
3232
};
3333
const PureComponent: IGeneralConstructor = class {
3434
setState() {}
3535
forceUpdate() {}
3636
render() {}
37-
state: {};
38-
props: {};
39-
refs: {};
40-
context: {};
37+
state: Record<string, unknown>;
38+
props: Record<string, unknown>;
39+
refs: Record<string, unknown>;
40+
context: Record<string, unknown>;
4141
};
4242
const createElement = () => {};
4343
const createContext = () => {};
@@ -64,10 +64,10 @@ class Adapter {
6464
return false;
6565
}
6666

67-
return this.builtinModules.every(m => {
68-
const flag = !!this.runtime[m];
67+
return this.builtinModules.every((m) => {
68+
const flag = !!runtime[m];
6969
if (!flag) {
70-
throw new Error(`runtime is inValid, module '${m}' is not existed`);
70+
throw new Error(`runtime is invalid, module '${m}' does not exist`);
7171
}
7272
return flag;
7373
});
Collapse file

‎packages/renderer-core/tests/adapter/adapter.test.ts‎

Copy file name to clipboard
+107Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// @ts-nocheck
2+
import adapter, { Env } from '../../src/adapter';
3+
import { IRuntime, IRendererModules, IGeneralConstructor } from '../../src/types';
4+
5+
6+
7+
describe('test src/adapter ', () => {
8+
9+
it('adapter basic use works', () => {
10+
expect(adapter).toBeTruthy();
11+
12+
});
13+
14+
it('isValidRuntime works', () => {
15+
expect(adapter.isValidRuntime([] as any)).toBeFalsy();
16+
17+
expect(adapter.isValidRuntime('' as any)).toBeFalsy();
18+
19+
let invalidRuntime = {};
20+
expect(() => adapter.isValidRuntime(invalidRuntime as any)).toThrowError(/Component/);
21+
invalidRuntime = {
22+
Component: {},
23+
};
24+
expect(() => adapter.isValidRuntime(invalidRuntime as any)).toThrowError(/PureComponent/);
25+
invalidRuntime = {
26+
Component: {},
27+
PureComponent: {},
28+
};
29+
expect(() => adapter.isValidRuntime(invalidRuntime as any)).toThrowError(/createElement/);
30+
invalidRuntime = {
31+
Component: {},
32+
PureComponent: {},
33+
createElement: {},
34+
};
35+
expect(() => adapter.isValidRuntime(invalidRuntime as any)).toThrowError(/createContext/);
36+
invalidRuntime = {
37+
Component: {},
38+
PureComponent: {},
39+
createElement: {},
40+
createContext: {},
41+
};
42+
expect(() => adapter.isValidRuntime(invalidRuntime as any)).toThrowError(/forwardRef/);
43+
invalidRuntime = {
44+
Component: {},
45+
PureComponent: {},
46+
createElement: {},
47+
createContext: {},
48+
forwardRef: {},
49+
};
50+
expect(() => adapter.isValidRuntime(invalidRuntime as any)).toThrowError(/findDOMNode/);
51+
const validRuntime = {
52+
Component: {},
53+
PureComponent: {},
54+
createElement: {},
55+
createContext: {},
56+
forwardRef: {},
57+
findDOMNode: {},
58+
};
59+
60+
expect(adapter.isValidRuntime(validRuntime as any)).toBeTruthy();
61+
});
62+
63+
it('setRuntime/getRuntime works', () => {
64+
const validRuntime = {
65+
Component: {},
66+
PureComponent: {},
67+
createElement: {},
68+
createContext: {},
69+
forwardRef: {},
70+
findDOMNode: {},
71+
};
72+
73+
adapter.setRuntime(validRuntime as any);
74+
expect(adapter.getRuntime()).toBe(validRuntime);
75+
76+
// won`t work when invalid runtime paased in.
77+
adapter.setRuntime([] as any);
78+
expect(adapter.getRuntime()).toBe(validRuntime);
79+
80+
81+
});
82+
83+
it('setEnv/.env/isReact/isRax works', () => {
84+
adapter.setEnv(Env.React);
85+
expect(adapter.env).toBe(Env.React);
86+
expect(adapter.isReact()).toBeTruthy();
87+
expect(adapter.isRax()).toBeFalsy();
88+
adapter.setEnv(Env.Rax);
89+
expect(adapter.env).toBe(Env.Rax);
90+
expect(adapter.isRax()).toBeTruthy();
91+
expect(adapter.isReact()).toBeFalsy();
92+
});
93+
94+
it('setRenderers/getRenderers works', () => {
95+
const mockRenderers = { BaseRenderer: {} as IBaseRenderComponent};
96+
adapter.setRenderers(mockRenderers);
97+
expect(adapter.getRenderers()).toBe(mockRenderers);
98+
adapter.setRenderers(undefined);
99+
expect(adapter.getRenderers()).toStrictEqual({});
100+
});
101+
102+
it('setConfigProvider/getConfigProvider works', () => {
103+
const mockConfigProvider = { a: 111 };
104+
adapter.setConfigProvider(mockConfigProvider);
105+
expect(adapter.getConfigProvider()).toBe(mockConfigProvider);
106+
});
107+
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.