@modern-js/plugin-garfish 1.4.6 → 1.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +2 -1
- package/CHANGELOG.md +38 -0
- package/dist/js/modern/cli/index.js +5 -3
- package/dist/js/modern/runtime/index.js +1 -1
- package/dist/js/modern/runtime/utils/apps.js +6 -1
- package/dist/js/modern/util.js +5 -2
- package/dist/js/node/cli/index.js +5 -3
- package/dist/js/node/runtime/index.js +6 -0
- package/dist/js/node/runtime/utils/apps.js +6 -1
- package/dist/js/node/util.js +7 -2
- package/dist/js/treeshaking/cli/index.js +5 -3
- package/dist/js/treeshaking/runtime/index.js +1 -1
- package/dist/js/treeshaking/runtime/utils/apps.js +8 -2
- package/dist/js/treeshaking/util.js +5 -2
- package/dist/types/runtime/index.d.ts +1 -1
- package/dist/types/runtime/useModuleApps.d.ts +3 -2
- package/dist/types/runtime/utils/apps.d.ts +2 -2
- package/dist/types/util.d.ts +5 -1
- package/package.json +10 -8
- package/tests/__snapshots__/cli.test.tsx.snap +0 -89
- package/tests/cli.test.tsx +0 -239
- package/tests/hooks.test.tsx +0 -57
- package/tests/index.test.tsx +0 -252
- package/tests/resource/dashboard.ts +0 -44
- package/tests/resource/table.ts +0 -43
- package/tests/resource/userInfo.ts +0 -44
package/.eslintrc.js
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# @modern-js/plugin-garfish
|
|
2
2
|
|
|
3
|
+
## 1.4.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5e15976e: fix(garfish-plugin): garfish unregister undefined and export garfish instance
|
|
8
|
+
- 895fa0ff: chore: using "workspace:\*" in devDependencies
|
|
9
|
+
- Updated dependencies [2d155c4c]
|
|
10
|
+
- Updated dependencies [123e432d]
|
|
11
|
+
- Updated dependencies [e5a9b26d]
|
|
12
|
+
- Updated dependencies [0b26b93b]
|
|
13
|
+
- Updated dependencies [123e432d]
|
|
14
|
+
- Updated dependencies [f9f66ef9]
|
|
15
|
+
- Updated dependencies [592edabc]
|
|
16
|
+
- Updated dependencies [895fa0ff]
|
|
17
|
+
- Updated dependencies [3578913e]
|
|
18
|
+
- Updated dependencies [1c3beab3]
|
|
19
|
+
- @modern-js/utils@1.6.0
|
|
20
|
+
- @modern-js/plugin-router@1.2.11
|
|
21
|
+
- @modern-js/runtime-core@1.4.3
|
|
22
|
+
|
|
23
|
+
## 1.4.8
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 36e702f8: fix(plugin-garfish): fix useModules component props type and cors config
|
|
28
|
+
- 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
|
|
29
|
+
- 60f7d8bf: feat: add tests dir to npmignore
|
|
30
|
+
- e4cec1ce: types: fix config hook type
|
|
31
|
+
- d558d4b5: fix: should not import from @modern-js/utils
|
|
32
|
+
- Updated dependencies [b8599d09]
|
|
33
|
+
- Updated dependencies [6cffe99d]
|
|
34
|
+
- Updated dependencies [04ae5262]
|
|
35
|
+
- Updated dependencies [60f7d8bf]
|
|
36
|
+
- Updated dependencies [3bf4f8b0]
|
|
37
|
+
- @modern-js/utils@1.5.0
|
|
38
|
+
- @modern-js/plugin-router@1.2.10
|
|
39
|
+
- @modern-js/runtime-core@1.4.2
|
|
40
|
+
|
|
3
41
|
## 1.4.6
|
|
4
42
|
|
|
5
43
|
### Patch Changes
|
|
@@ -71,6 +71,11 @@ export default (({
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
tools: {
|
|
74
|
+
devServer: {
|
|
75
|
+
headers: {
|
|
76
|
+
'Access-Control-Allow-Origin': '*'
|
|
77
|
+
}
|
|
78
|
+
},
|
|
74
79
|
webpack: (webpackConfig, {
|
|
75
80
|
chain,
|
|
76
81
|
webpack,
|
|
@@ -82,9 +87,6 @@ export default (({
|
|
|
82
87
|
var _resolveOptions$serve, _resolveOptions$deplo2, _resolveOptions$deplo3;
|
|
83
88
|
|
|
84
89
|
chain.output.libraryTarget('umd');
|
|
85
|
-
chain.devServer.headers({
|
|
86
|
-
'Access-Control-Allow-Origin': '*'
|
|
87
|
-
});
|
|
88
90
|
|
|
89
91
|
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port) {
|
|
90
92
|
chain.output.publicPath(_env === 'development' ? `//localhost:${resolveOptions.server.port}/` : webpackConfig.output.publicPath);
|
|
@@ -37,6 +37,8 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
37
37
|
appInstance: null,
|
|
38
38
|
domId: generateSubAppContainerKey(appInfo)
|
|
39
39
|
};
|
|
40
|
+
|
|
41
|
+
this.unregisterHistoryListener = () => {};
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
@@ -114,7 +116,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
114
116
|
await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount());
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
history === null || history === void 0 ? void 0 : history.listen(() => {
|
|
119
|
+
this.unregisterHistoryListener = history === null || history === void 0 ? void 0 : history.listen(() => {
|
|
118
120
|
if (locationHref !== history.location.pathname) {
|
|
119
121
|
locationHref = history.location.pathname;
|
|
120
122
|
const popStateEvent = new PopStateEvent('popstate');
|
|
@@ -131,9 +133,12 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
131
133
|
}
|
|
132
134
|
|
|
133
135
|
async componentWillUnmount() {
|
|
136
|
+
var _this$unregisterHisto;
|
|
137
|
+
|
|
134
138
|
const {
|
|
135
139
|
appInstance
|
|
136
140
|
} = this.state;
|
|
141
|
+
(_this$unregisterHisto = this.unregisterHistoryListener) === null || _this$unregisterHisto === void 0 ? void 0 : _this$unregisterHisto.call(this);
|
|
137
142
|
|
|
138
143
|
if (appInstance) {
|
|
139
144
|
const {
|
package/dist/js/modern/util.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Tips: this package will be bundled and running in the browser, do not import from `@modern-js/utils`.
|
|
3
|
+
*/
|
|
4
|
+
import createDebug from 'debug';
|
|
5
|
+
export const logger = createDebug('modern-js:plugin-garfish');
|
|
3
6
|
export const SUBMODULE_APP_COMPONENT_KEY = 'SubModuleComponent';
|
|
4
7
|
export function generateSubAppContainerKey(moduleInfo) {
|
|
5
8
|
return moduleInfo ? `modern_sub_app_container_${decodeURIComponent(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.name)}` : 'modern_sub_app_container';
|
|
@@ -86,6 +86,11 @@ var _default = ({
|
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
tools: {
|
|
89
|
+
devServer: {
|
|
90
|
+
headers: {
|
|
91
|
+
'Access-Control-Allow-Origin': '*'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
89
94
|
webpack: (webpackConfig, {
|
|
90
95
|
chain,
|
|
91
96
|
webpack,
|
|
@@ -97,9 +102,6 @@ var _default = ({
|
|
|
97
102
|
var _resolveOptions$serve, _resolveOptions$deplo2, _resolveOptions$deplo3;
|
|
98
103
|
|
|
99
104
|
chain.output.libraryTarget('umd');
|
|
100
|
-
chain.devServer.headers({
|
|
101
|
-
'Access-Control-Allow-Origin': '*'
|
|
102
|
-
});
|
|
103
105
|
|
|
104
106
|
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port) {
|
|
105
107
|
chain.output.publicPath(_env === 'development' ? `//localhost:${resolveOptions.server.port}/` : webpackConfig.output.publicPath);
|
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "default", {
|
|
|
15
15
|
return _plugin.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "garfish", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _garfish.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "useModuleApp", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function () {
|
|
@@ -43,6 +43,8 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
43
43
|
appInstance: null,
|
|
44
44
|
domId: (0, _util.generateSubAppContainerKey)(appInfo)
|
|
45
45
|
};
|
|
46
|
+
|
|
47
|
+
this.unregisterHistoryListener = () => {};
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
@@ -120,7 +122,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
120
122
|
await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount());
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
history === null || history === void 0 ? void 0 : history.listen(() => {
|
|
125
|
+
this.unregisterHistoryListener = history === null || history === void 0 ? void 0 : history.listen(() => {
|
|
124
126
|
if (locationHref !== history.location.pathname) {
|
|
125
127
|
locationHref = history.location.pathname;
|
|
126
128
|
const popStateEvent = new PopStateEvent('popstate');
|
|
@@ -137,9 +139,12 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
async componentWillUnmount() {
|
|
142
|
+
var _this$unregisterHisto;
|
|
143
|
+
|
|
140
144
|
const {
|
|
141
145
|
appInstance
|
|
142
146
|
} = this.state;
|
|
147
|
+
(_this$unregisterHisto = this.unregisterHistoryListener) === null || _this$unregisterHisto === void 0 ? void 0 : _this$unregisterHisto.call(this);
|
|
143
148
|
|
|
144
149
|
if (appInstance) {
|
|
145
150
|
const {
|
package/dist/js/node/util.js
CHANGED
|
@@ -7,9 +7,14 @@ exports.SUBMODULE_APP_COMPONENT_KEY = void 0;
|
|
|
7
7
|
exports.generateSubAppContainerKey = generateSubAppContainerKey;
|
|
8
8
|
exports.logger = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Tips: this package will be bundled and running in the browser, do not import from `@modern-js/utils`.
|
|
16
|
+
*/
|
|
17
|
+
const logger = (0, _debug.default)('modern-js:plugin-garfish');
|
|
13
18
|
exports.logger = logger;
|
|
14
19
|
const SUBMODULE_APP_COMPONENT_KEY = 'SubModuleComponent';
|
|
15
20
|
exports.SUBMODULE_APP_COMPONENT_KEY = SUBMODULE_APP_COMPONENT_KEY;
|
|
@@ -94,6 +94,11 @@ export default (function () {
|
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
tools: {
|
|
97
|
+
devServer: {
|
|
98
|
+
headers: {
|
|
99
|
+
'Access-Control-Allow-Origin': '*'
|
|
100
|
+
}
|
|
101
|
+
},
|
|
97
102
|
webpack: function webpack(webpackConfig, _ref3) {
|
|
98
103
|
var _resolveOptions$deplo, _resolveWebpackConfig;
|
|
99
104
|
|
|
@@ -106,9 +111,6 @@ export default (function () {
|
|
|
106
111
|
var _resolveOptions$serve, _resolveOptions$deplo2, _resolveOptions$deplo3;
|
|
107
112
|
|
|
108
113
|
chain.output.libraryTarget('umd');
|
|
109
|
-
chain.devServer.headers({
|
|
110
|
-
'Access-Control-Allow-Origin': '*'
|
|
111
|
-
});
|
|
112
114
|
|
|
113
115
|
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port) {
|
|
114
116
|
chain.output.publicPath(env === 'development' ? "//localhost:".concat(resolveOptions.server.port, "/") : webpackConfig.output.publicPath);
|
|
@@ -76,6 +76,9 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
76
76
|
appInstance: null,
|
|
77
77
|
domId: generateSubAppContainerKey(appInfo)
|
|
78
78
|
};
|
|
79
|
+
|
|
80
|
+
_this.unregisterHistoryListener = function () {};
|
|
81
|
+
|
|
79
82
|
return _this;
|
|
80
83
|
}
|
|
81
84
|
|
|
@@ -174,7 +177,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
174
177
|
return appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount();
|
|
175
178
|
|
|
176
179
|
case 22:
|
|
177
|
-
history === null || history === void 0 ? void 0 : history.listen(function () {
|
|
180
|
+
this.unregisterHistoryListener = history === null || history === void 0 ? void 0 : history.listen(function () {
|
|
178
181
|
if (locationHref !== history.location.pathname) {
|
|
179
182
|
locationHref = history.location.pathname;
|
|
180
183
|
var popStateEvent = new PopStateEvent('popstate');
|
|
@@ -211,6 +214,8 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
211
214
|
key: "componentWillUnmount",
|
|
212
215
|
value: function () {
|
|
213
216
|
var _componentWillUnmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
217
|
+
var _this$unregisterHisto;
|
|
218
|
+
|
|
214
219
|
var appInstance, _appInfo;
|
|
215
220
|
|
|
216
221
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
@@ -218,6 +223,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
218
223
|
switch (_context2.prev = _context2.next) {
|
|
219
224
|
case 0:
|
|
220
225
|
appInstance = this.state.appInstance;
|
|
226
|
+
(_this$unregisterHisto = this.unregisterHistoryListener) === null || _this$unregisterHisto === void 0 ? void 0 : _this$unregisterHisto.call(this);
|
|
221
227
|
|
|
222
228
|
if (appInstance) {
|
|
223
229
|
_appInfo = appInstance.appInfo;
|
|
@@ -231,7 +237,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
231
237
|
}
|
|
232
238
|
}
|
|
233
239
|
|
|
234
|
-
case
|
|
240
|
+
case 3:
|
|
235
241
|
case "end":
|
|
236
242
|
return _context2.stop();
|
|
237
243
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Tips: this package will be bundled and running in the browser, do not import from `@modern-js/utils`.
|
|
3
|
+
*/
|
|
4
|
+
import createDebug from 'debug';
|
|
5
|
+
export var logger = createDebug('modern-js:plugin-garfish');
|
|
3
6
|
export var SUBMODULE_APP_COMPONENT_KEY = 'SubModuleComponent';
|
|
4
7
|
export function generateSubAppContainerKey(moduleInfo) {
|
|
5
8
|
return moduleInfo ? "modern_sub_app_container_".concat(decodeURIComponent(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.name)) : 'modern_sub_app_container';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default } from './plugin';
|
|
2
2
|
export { useModuleApps, useModuleApp } from './useModuleApps';
|
|
3
3
|
export type { Manifest, ModuleInfo } from './useModuleApps';
|
|
4
|
-
export { default as Garfish } from 'garfish';
|
|
4
|
+
export { default as Garfish, default as garfish } from 'garfish';
|
|
@@ -28,10 +28,11 @@ export declare type ModernGarfishConfig = {
|
|
|
28
28
|
};
|
|
29
29
|
export declare type MicroComponentProps = {
|
|
30
30
|
loadable?: LoadableConfig;
|
|
31
|
+
[index: string]: any;
|
|
31
32
|
};
|
|
32
33
|
export declare type Config = Partial<Options> & ModernGarfishConfig;
|
|
33
|
-
export declare type UseModuleApps = { [index in 'apps' | string]: index extends 'apps' ? ModulesInfo : React.FC<
|
|
34
|
-
readonly MApp: React.FC<
|
|
34
|
+
export declare type UseModuleApps = { [index in 'apps' | string]: index extends 'apps' ? ModulesInfo : React.FC<MicroComponentProps> } & {
|
|
35
|
+
readonly MApp: React.FC<MicroComponentProps>;
|
|
35
36
|
readonly apps: ModulesInfo;
|
|
36
37
|
};
|
|
37
38
|
export declare function useModuleApps(): UseModuleApps;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import Garfish from 'garfish';
|
|
3
|
-
import { Manifest, ModulesInfo } from '../useModuleApps';
|
|
3
|
+
import { Manifest, MicroComponentProps, ModulesInfo } from '../useModuleApps';
|
|
4
4
|
export interface AppMap {
|
|
5
|
-
[key: string]: React.FC<
|
|
5
|
+
[key: string]: React.FC<MicroComponentProps>;
|
|
6
6
|
}
|
|
7
7
|
export declare function generateApps(options: typeof Garfish.options, manifest?: Manifest): {
|
|
8
8
|
apps: AppMap;
|
package/dist/types/util.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tips: this package will be bundled and running in the browser, do not import from `@modern-js/utils`.
|
|
3
|
+
*/
|
|
4
|
+
import createDebug from 'debug';
|
|
1
5
|
import { ModuleInfo } from './runtime';
|
|
2
|
-
export declare const logger:
|
|
6
|
+
export declare const logger: createDebug.Debugger;
|
|
3
7
|
export declare const SUBMODULE_APP_COMPONENT_KEY = "SubModuleComponent";
|
|
4
8
|
export declare function generateSubAppContainerKey(moduleInfo?: ModuleInfo): string;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.4.
|
|
14
|
+
"version": "1.4.9",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/runtime/index.d.ts",
|
|
17
17
|
"typesVersions": {
|
|
@@ -50,17 +50,19 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@babel/runtime": "^7",
|
|
53
|
-
"@modern-js/utils": "^1.
|
|
53
|
+
"@modern-js/utils": "^1.6.0",
|
|
54
|
+
"@types/debug": "^4.1.7",
|
|
54
55
|
"@types/react-loadable": "^5.5.6",
|
|
56
|
+
"debug": "^4.3.2",
|
|
55
57
|
"garfish": "^1.3.3",
|
|
56
58
|
"hoist-non-react-statics": "^3.3.2",
|
|
57
59
|
"react-loadable": "^5.5.0"
|
|
58
60
|
},
|
|
59
61
|
"devDependencies": {
|
|
60
|
-
"@modern-js/core": "1.
|
|
61
|
-
"@modern-js/plugin-router": "
|
|
62
|
-
"@modern-js/runtime-core": "1.4.
|
|
63
|
-
"@modern-js/types": "
|
|
62
|
+
"@modern-js/core": "1.9.0",
|
|
63
|
+
"@modern-js/plugin-router": "1.2.11",
|
|
64
|
+
"@modern-js/runtime-core": "1.4.3",
|
|
65
|
+
"@modern-js/types": "1.5.1",
|
|
64
66
|
"@scripts/build": "0.0.0",
|
|
65
67
|
"@scripts/jest-config": "0.0.0",
|
|
66
68
|
"@testing-library/jest-dom": "^5.16.1",
|
|
@@ -81,8 +83,8 @@
|
|
|
81
83
|
"webpack-chain": "^6.5.1"
|
|
82
84
|
},
|
|
83
85
|
"peerDependencies": {
|
|
84
|
-
"@modern-js/plugin-router": "^1.2.
|
|
85
|
-
"@modern-js/runtime-core": "^1.4.
|
|
86
|
+
"@modern-js/plugin-router": "^1.2.11",
|
|
87
|
+
"@modern-js/runtime-core": "^1.4.3",
|
|
86
88
|
"react": "^17"
|
|
87
89
|
},
|
|
88
90
|
"sideEffects": false,
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`plugin-garfish cli cli addRuntimeExports 1`] = `
|
|
4
|
-
Array [
|
|
5
|
-
"export { default as garfish, default as masterApp } from '@modern-js/test/plugin-garfish'",
|
|
6
|
-
"export * from '@modern-js/test/plugin-garfish'",
|
|
7
|
-
]
|
|
8
|
-
`;
|
|
9
|
-
|
|
10
|
-
exports[`plugin-garfish cli cli get runtime config 1`] = `
|
|
11
|
-
Object {
|
|
12
|
-
"masterApp": Object {
|
|
13
|
-
"basename": "/test",
|
|
14
|
-
},
|
|
15
|
-
}
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
exports[`plugin-garfish cli cli get runtime features config 1`] = `
|
|
19
|
-
Object {
|
|
20
|
-
"masterApp": Object {
|
|
21
|
-
"basename": "/test2",
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
`;
|
|
25
|
-
|
|
26
|
-
exports[`plugin-garfish cli cli makeRender function 1`] = `
|
|
27
|
-
Object {
|
|
28
|
-
"renderByProvider": true,
|
|
29
|
-
"routerConfig": Object {
|
|
30
|
-
"basename": "/test",
|
|
31
|
-
"historyOptions": Object {
|
|
32
|
-
"basename": "/test",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
`;
|
|
37
|
-
|
|
38
|
-
exports[`plugin-garfish cli cli set runtime config 1`] = `
|
|
39
|
-
Object {
|
|
40
|
-
"masterApp": true,
|
|
41
|
-
}
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
|
-
exports[`plugin-garfish cli cli set runtime features config 1`] = `
|
|
45
|
-
Object {
|
|
46
|
-
"features": Object {
|
|
47
|
-
"masterApp": true,
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
`;
|
|
51
|
-
|
|
52
|
-
exports[`plugin-garfish cli webpack config close external and use js entry 1`] = `
|
|
53
|
-
Object {
|
|
54
|
-
"devServer": Object {
|
|
55
|
-
"headers": Object {
|
|
56
|
-
"Access-Control-Allow-Origin": "*",
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
"externals": Object {
|
|
60
|
-
"react": "react",
|
|
61
|
-
"react-dom": "react-dom",
|
|
62
|
-
},
|
|
63
|
-
"optimization": Object {
|
|
64
|
-
"runtimeChunk": false,
|
|
65
|
-
"splitChunks": Object {
|
|
66
|
-
"chunks": "async",
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
"output": Object {
|
|
70
|
-
"filename": "index.js",
|
|
71
|
-
"libraryTarget": "umd",
|
|
72
|
-
"publicPath": "//localhost:8080/",
|
|
73
|
-
},
|
|
74
|
-
}
|
|
75
|
-
`;
|
|
76
|
-
|
|
77
|
-
exports[`plugin-garfish cli webpack config default micro config 1`] = `
|
|
78
|
-
Object {
|
|
79
|
-
"devServer": Object {
|
|
80
|
-
"headers": Object {
|
|
81
|
-
"Access-Control-Allow-Origin": "*",
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
"output": Object {
|
|
85
|
-
"libraryTarget": "umd",
|
|
86
|
-
"publicPath": "//localhost:8080/",
|
|
87
|
-
},
|
|
88
|
-
}
|
|
89
|
-
`;
|
package/tests/cli.test.tsx
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
2
|
-
import { Hooks, manager, ToRunners } from '@modern-js/core';
|
|
3
|
-
import WebpackChain from 'webpack-chain';
|
|
4
|
-
import GarfishPlugin, { externals } from '../src/cli';
|
|
5
|
-
import { getRuntimeConfig, makeRenderFunction, setRuntimeConfig } from '../src/cli/utils';
|
|
6
|
-
|
|
7
|
-
const addExportList = [];
|
|
8
|
-
jest.mock('@modern-js/utils', () => {
|
|
9
|
-
const originalModule = jest.requireActual('@modern-js/utils');
|
|
10
|
-
return {
|
|
11
|
-
__esModule: true,
|
|
12
|
-
...originalModule,
|
|
13
|
-
createRuntimeExportsUtils: ()=>({
|
|
14
|
-
addExport: (val: any)=> {
|
|
15
|
-
addExportList.push(val);
|
|
16
|
-
},
|
|
17
|
-
getPath: ()=> 'test',
|
|
18
|
-
}),
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('plugin-garfish cli', () => {
|
|
23
|
-
test('cli garfish basename', async () => {
|
|
24
|
-
expect(GarfishPlugin().name).toBe('@modern-js/plugin-garfish');
|
|
25
|
-
|
|
26
|
-
const main = manager.clone().usePlugin(GarfishPlugin);
|
|
27
|
-
const runner = await main.init();
|
|
28
|
-
await runner.prepare();
|
|
29
|
-
const configHistoryOptions: any = await runner.resolvedConfig({
|
|
30
|
-
resolved: {
|
|
31
|
-
runtime: {
|
|
32
|
-
router: {
|
|
33
|
-
historyOptions: { basename: '/test' }
|
|
34
|
-
},
|
|
35
|
-
masterApp: {}
|
|
36
|
-
},
|
|
37
|
-
}
|
|
38
|
-
} as any);
|
|
39
|
-
|
|
40
|
-
expect(configHistoryOptions.resolved.runtime.masterApp.basename).toBe('/test');
|
|
41
|
-
|
|
42
|
-
const configHistory: any = await runner.resolvedConfig({
|
|
43
|
-
resolved: {
|
|
44
|
-
runtime: {
|
|
45
|
-
router: {
|
|
46
|
-
basename: '/test2'
|
|
47
|
-
},
|
|
48
|
-
masterApp: {}
|
|
49
|
-
},
|
|
50
|
-
}
|
|
51
|
-
} as any);
|
|
52
|
-
|
|
53
|
-
expect(configHistory.resolved.runtime.masterApp.basename).toBe('/test2');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('cli get runtime config', ()=>{
|
|
57
|
-
const runtimeConfig = getRuntimeConfig({
|
|
58
|
-
runtime: {
|
|
59
|
-
masterApp: {
|
|
60
|
-
basename: '/test'
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
expect(runtimeConfig).toMatchSnapshot();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('cli get runtime features config', ()=>{
|
|
68
|
-
const runtimeConfig = getRuntimeConfig({
|
|
69
|
-
runtime: {
|
|
70
|
-
masterApp: {
|
|
71
|
-
basename: '/test'
|
|
72
|
-
},
|
|
73
|
-
features: {
|
|
74
|
-
masterApp: {
|
|
75
|
-
basename: '/test2'
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
expect(runtimeConfig).toMatchSnapshot();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('cli set runtime config', ()=>{
|
|
85
|
-
const runtimeConfig = {
|
|
86
|
-
runtime: {
|
|
87
|
-
masterApp: {
|
|
88
|
-
basename: '/test'
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
setRuntimeConfig(runtimeConfig, 'masterApp', true);
|
|
94
|
-
|
|
95
|
-
expect(runtimeConfig.runtime).toMatchSnapshot();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('cli set runtime features config', ()=>{
|
|
99
|
-
const runtimeConfig = {
|
|
100
|
-
runtime: {
|
|
101
|
-
features: {
|
|
102
|
-
masterApp: {
|
|
103
|
-
basename: '/test'
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
setRuntimeConfig(runtimeConfig, 'masterApp', true);
|
|
110
|
-
|
|
111
|
-
expect(runtimeConfig.runtime).toMatchSnapshot();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('cli makeRender function', ()=>{
|
|
115
|
-
const code = `
|
|
116
|
-
const router = (config)=> config;
|
|
117
|
-
const App = {};
|
|
118
|
-
const routerConfig = router({...App?.config?.router, ...App?.config?.features?.router});
|
|
119
|
-
const resultConfig = {
|
|
120
|
-
routerConfig,
|
|
121
|
-
renderByProvider: true,
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
if (IS_BROWSER) {
|
|
125
|
-
resultConfig.renderByProvider = false;
|
|
126
|
-
}
|
|
127
|
-
return resultConfig;
|
|
128
|
-
`;
|
|
129
|
-
const generateNewRenderFn = new Function('appInfo', 'IS_BROWSER', '__GARFISH_EXPORTS__', makeRenderFunction(code));
|
|
130
|
-
|
|
131
|
-
// render byGarfish but don't provider appInfo
|
|
132
|
-
expect(generateNewRenderFn(undefined, true, false)).toBe(null);
|
|
133
|
-
|
|
134
|
-
// run alone
|
|
135
|
-
expect(generateNewRenderFn(undefined, true)).toMatchObject({
|
|
136
|
-
renderByProvider: false
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// render ByGarfish and provider appInfo
|
|
140
|
-
expect(generateNewRenderFn({ basename: '/test' }, true, true)).toMatchSnapshot();
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
test('webpack config close external and use js entry', async ()=>{
|
|
145
|
-
const resolveConfig: any = {
|
|
146
|
-
deploy: {
|
|
147
|
-
microFrontend: {
|
|
148
|
-
externalBasicLibrary: true,
|
|
149
|
-
enableHtmlEntry: false,
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
server: {
|
|
153
|
-
port: 8080
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const main = manager.clone({
|
|
158
|
-
useResolvedConfigContext: ()=>resolveConfig
|
|
159
|
-
}).usePlugin(GarfishPlugin);
|
|
160
|
-
|
|
161
|
-
const runner = await main.init();
|
|
162
|
-
await runner.prepare();
|
|
163
|
-
const config: any = await runner.config();
|
|
164
|
-
const webpackConfig = new WebpackChain();
|
|
165
|
-
|
|
166
|
-
config[0].tools.webpack({}, {
|
|
167
|
-
chain: webpackConfig,
|
|
168
|
-
webpack: jest.fn(),
|
|
169
|
-
env: 'development'
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const generateConfig = webpackConfig.toConfig();
|
|
173
|
-
expect(generateConfig).toMatchSnapshot();
|
|
174
|
-
expect(generateConfig).toMatchObject({
|
|
175
|
-
output: {
|
|
176
|
-
libraryTarget: 'umd',
|
|
177
|
-
publicPath: '//localhost:8080/',
|
|
178
|
-
filename: 'index.js'
|
|
179
|
-
},
|
|
180
|
-
externals,
|
|
181
|
-
optimization: { runtimeChunk: false, splitChunks: { chunks: 'async' } }
|
|
182
|
-
});
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
test('webpack config default micro config', async ()=>{
|
|
186
|
-
const resolveConfig: any = {
|
|
187
|
-
deploy: {
|
|
188
|
-
microFrontend: true,
|
|
189
|
-
},
|
|
190
|
-
server: {
|
|
191
|
-
port: '8080'
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const main = manager.clone({
|
|
196
|
-
useResolvedConfigContext: ()=>resolveConfig
|
|
197
|
-
}).usePlugin(GarfishPlugin);
|
|
198
|
-
const runner = await main.init();
|
|
199
|
-
await runner.prepare();
|
|
200
|
-
const config: any = await runner.config();
|
|
201
|
-
const webpackConfig = new WebpackChain();
|
|
202
|
-
|
|
203
|
-
config[0].tools.webpack({}, {
|
|
204
|
-
chain: webpackConfig,
|
|
205
|
-
webpack: jest.fn(),
|
|
206
|
-
env: 'development'
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
const generateConfig = webpackConfig.toConfig();
|
|
210
|
-
expect(generateConfig).toMatchSnapshot();
|
|
211
|
-
expect(generateConfig).toMatchObject({
|
|
212
|
-
output: {
|
|
213
|
-
libraryTarget: 'umd',
|
|
214
|
-
publicPath: '//localhost:8080/'
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
expect(generateConfig.externals).toBeUndefined();
|
|
218
|
-
expect(generateConfig.output.filename).toBeUndefined();
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test('cli addRuntimeExports', async ()=>{
|
|
222
|
-
const resolveConfig: any = {};
|
|
223
|
-
const mfPackagePath = '@modern-js/test/plugin-garfish';
|
|
224
|
-
const plugin = GarfishPlugin({
|
|
225
|
-
mfPackagePath,
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
const lifecycle = await plugin.setup({
|
|
229
|
-
useResolvedConfigContext: () => resolveConfig,
|
|
230
|
-
useAppContext: ()=>({
|
|
231
|
-
internalDirectory: 'test'
|
|
232
|
-
}),
|
|
233
|
-
} as any);
|
|
234
|
-
|
|
235
|
-
lifecycle && lifecycle.config();
|
|
236
|
-
lifecycle && lifecycle.addRuntimeExports()
|
|
237
|
-
expect(addExportList).toMatchSnapshot();
|
|
238
|
-
});
|
|
239
|
-
});
|
package/tests/hooks.test.tsx
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import { createApp } from '@modern-js/runtime-core';
|
|
4
|
-
import '@testing-library/jest-dom';
|
|
5
|
-
|
|
6
|
-
import ModernGarfishPlugin, {
|
|
7
|
-
useModuleApp,
|
|
8
|
-
useModuleApps,
|
|
9
|
-
} from '../src/runtime';
|
|
10
|
-
|
|
11
|
-
global.React = React;
|
|
12
|
-
|
|
13
|
-
const dashboardPath = 'http://garfish-mock.com/dashboard';
|
|
14
|
-
const tableListPath = 'http://garfish-mock.com/table-list';
|
|
15
|
-
|
|
16
|
-
describe('plugin-garfish', () => {
|
|
17
|
-
test('legacyModule hooks params', async () => {
|
|
18
|
-
const dashBoardModuleInfo = {
|
|
19
|
-
name: 'Dashboard',
|
|
20
|
-
entry: dashboardPath,
|
|
21
|
-
};
|
|
22
|
-
const tableListModuleInfo = {
|
|
23
|
-
name: 'TableList',
|
|
24
|
-
entry: tableListPath,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const microFrontendConfig = {
|
|
28
|
-
apps: [tableListModuleInfo, dashBoardModuleInfo],
|
|
29
|
-
LoadingComponent() {
|
|
30
|
-
return <div data-testid="loading-id">loading</div>;
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const App = () => {
|
|
35
|
-
const { MApp, apps, Dashboard, TableList } = useModuleApps();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (apps.length > 0) {
|
|
39
|
-
expect(apps[0].name).toBe(tableListModuleInfo.name);
|
|
40
|
-
expect(apps[0].entry).toBe(tableListModuleInfo.entry);
|
|
41
|
-
expect(apps[0].Component === TableList).toBeTruthy();
|
|
42
|
-
|
|
43
|
-
expect(apps[1].name).toBe(dashBoardModuleInfo.name);
|
|
44
|
-
expect(apps[1].entry).toBe(dashBoardModuleInfo.entry);
|
|
45
|
-
expect(apps[1].Component === Dashboard).toBeTruthy();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return <div></div>;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const AppWrapper = createApp({
|
|
52
|
-
plugins: [ModernGarfishPlugin(microFrontendConfig)],
|
|
53
|
-
})(App);
|
|
54
|
-
|
|
55
|
-
render(<AppWrapper />);
|
|
56
|
-
});
|
|
57
|
-
});
|
package/tests/index.test.tsx
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import { createApp } from '@modern-js/runtime-core';
|
|
5
|
-
import fetchMock from 'jest-fetch-mock';
|
|
6
|
-
import '@testing-library/jest-dom';
|
|
7
|
-
// https://stackoverflow.com/questions/49034907/fetch-mock-does-not-mock-my-fetch
|
|
8
|
-
import {
|
|
9
|
-
Link,
|
|
10
|
-
Route,
|
|
11
|
-
Switch,
|
|
12
|
-
useLocation,
|
|
13
|
-
MemoryRouter,
|
|
14
|
-
} from '@modern-js/plugin-router';
|
|
15
|
-
import ModernGarfishPlugin, { useModuleApp } from '../src/runtime';
|
|
16
|
-
import { useModuleApps } from '../src';
|
|
17
|
-
import {
|
|
18
|
-
TABLE_LIST_ESCAPE_NODE,
|
|
19
|
-
TABLE_LIST_HTML,
|
|
20
|
-
TABLE_LIST_ROOT_NODE,
|
|
21
|
-
} from './resource/table';
|
|
22
|
-
import {
|
|
23
|
-
DASHBOARD_ESCAPE_NODE,
|
|
24
|
-
DASHBOARD_HTML,
|
|
25
|
-
DASHBOARD_ROOT_NODE,
|
|
26
|
-
} from './resource/dashboard';
|
|
27
|
-
import {
|
|
28
|
-
USER_INFO_ESCAPE_NODE,
|
|
29
|
-
USER_INFO_HTML,
|
|
30
|
-
USER_INFO_ROOT_NODE,
|
|
31
|
-
} from './resource/userInfo';
|
|
32
|
-
|
|
33
|
-
global.React = React;
|
|
34
|
-
global.fetch = fetchMock;
|
|
35
|
-
|
|
36
|
-
function waitFor(delay = 200) {
|
|
37
|
-
return new Promise(resolve => {
|
|
38
|
-
setTimeout(() => {
|
|
39
|
-
resolve(false);
|
|
40
|
-
}, delay);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const dashboardPath = 'http://garfish-mock.com/dashboard';
|
|
45
|
-
const tableListPath = 'http://garfish-mock.com/table-list';
|
|
46
|
-
const userInfoPath = 'http://garfish-mock.com/user-info';
|
|
47
|
-
|
|
48
|
-
describe('plugin-garfish', () => {
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
// https://www.npmjs.com/package/jest-fetch-mock
|
|
51
|
-
fetchMock.mockIf(/^https?:\/\/garfish-mock.com.*$/, req => {
|
|
52
|
-
if (req.url.endsWith('/dashboard')) {
|
|
53
|
-
return Promise.resolve({
|
|
54
|
-
body: DASHBOARD_HTML,
|
|
55
|
-
headers: {
|
|
56
|
-
'Content-Type': 'text/html',
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
} else if (req.url.endsWith('/table-list')) {
|
|
60
|
-
return Promise.resolve({
|
|
61
|
-
body: TABLE_LIST_HTML,
|
|
62
|
-
headers: {
|
|
63
|
-
'Content-Type': 'text/html',
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
} else if (req.url.endsWith('/user-info')) {
|
|
67
|
-
return Promise.resolve({
|
|
68
|
-
body: USER_INFO_HTML,
|
|
69
|
-
headers: {
|
|
70
|
-
'Content-Type': 'text/html',
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
} else {
|
|
74
|
-
return Promise.resolve({
|
|
75
|
-
status: 404,
|
|
76
|
-
body: 'Not Found',
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
fetchMock.doMock();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// testing-library.com/docs/example-react-router/
|
|
85
|
-
test('useModuleApps hooks', async () => {
|
|
86
|
-
const dashBoardModuleInfo = {
|
|
87
|
-
name: 'Dashboard',
|
|
88
|
-
entry: dashboardPath,
|
|
89
|
-
};
|
|
90
|
-
const tableListModuleInfo = {
|
|
91
|
-
name: 'TableList',
|
|
92
|
-
entry: tableListPath,
|
|
93
|
-
};
|
|
94
|
-
const userInfo = {
|
|
95
|
-
name: 'UserInfo',
|
|
96
|
-
activeWhen: '/user-info',
|
|
97
|
-
entry: userInfoPath,
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const microFrontendConfig = {
|
|
101
|
-
apps: [tableListModuleInfo, dashBoardModuleInfo, userInfo],
|
|
102
|
-
manifest: {
|
|
103
|
-
loadable: {
|
|
104
|
-
loading: ()=> {
|
|
105
|
-
return <div data-testid="loading-id">loading</div>;
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const App = () => {
|
|
112
|
-
const HomeTitle = 'Micro home page';
|
|
113
|
-
const Home = () => <div data-testid="home-title">{HomeTitle}</div>;
|
|
114
|
-
const { Dashboard, TableList } = useModuleApps();
|
|
115
|
-
|
|
116
|
-
const LocationDisplay = () => {
|
|
117
|
-
const location = useLocation();
|
|
118
|
-
return <div data-testid="location-display">{location.pathname}</div>;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
return (
|
|
122
|
-
<MemoryRouter>
|
|
123
|
-
<div id="app">
|
|
124
|
-
<Link to="/">home</Link>
|
|
125
|
-
<Link data-testid="dashboard-link" to="/dashboard">
|
|
126
|
-
dashboard
|
|
127
|
-
</Link>
|
|
128
|
-
<Link data-testid="table-list-link" to="/table-list">
|
|
129
|
-
table-list
|
|
130
|
-
</Link>
|
|
131
|
-
<Link data-testid="user-info-link" to="/user-info">
|
|
132
|
-
user-info
|
|
133
|
-
</Link>
|
|
134
|
-
<Switch>
|
|
135
|
-
<Route exact={true} path="/">
|
|
136
|
-
<Home />
|
|
137
|
-
</Route>
|
|
138
|
-
<Route path="/dashboard">
|
|
139
|
-
<Dashboard />
|
|
140
|
-
</Route>
|
|
141
|
-
<Route path="/table-list">
|
|
142
|
-
<TableList />
|
|
143
|
-
</Route>
|
|
144
|
-
<LocationDisplay />
|
|
145
|
-
</Switch>
|
|
146
|
-
</div>
|
|
147
|
-
</MemoryRouter>
|
|
148
|
-
);
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const AppWrapper = createApp({
|
|
152
|
-
plugins: [ModernGarfishPlugin(microFrontendConfig)],
|
|
153
|
-
})(App);
|
|
154
|
-
|
|
155
|
-
const { unmount } = render(<AppWrapper />);
|
|
156
|
-
expect(screen.getByTestId('home-title')).toBeInTheDocument();
|
|
157
|
-
const leftClick = { button: 0 };
|
|
158
|
-
userEvent.click(screen.getByTestId('dashboard-link'), leftClick);
|
|
159
|
-
// expect(await screen.findByText('loading')).toBeInTheDocument();
|
|
160
|
-
expect(
|
|
161
|
-
await screen.findByText(DASHBOARD_ROOT_NODE.text),
|
|
162
|
-
).toBeInTheDocument();
|
|
163
|
-
expect(
|
|
164
|
-
await screen.findByText(DASHBOARD_ESCAPE_NODE.text),
|
|
165
|
-
).toBeInTheDocument();
|
|
166
|
-
|
|
167
|
-
userEvent.click(screen.getByTestId('table-list-link'), leftClick);
|
|
168
|
-
expect(screen.queryByText(DASHBOARD_ROOT_NODE.text)).toBeNull();
|
|
169
|
-
expect(screen.queryByText(DASHBOARD_ESCAPE_NODE.text)).toBeNull();
|
|
170
|
-
// expect(await screen.findByText('loading')).toBeInTheDocument();
|
|
171
|
-
expect(
|
|
172
|
-
await screen.findByText(TABLE_LIST_ROOT_NODE.text),
|
|
173
|
-
).toBeInTheDocument();
|
|
174
|
-
expect(
|
|
175
|
-
await screen.findByText(TABLE_LIST_ESCAPE_NODE.text),
|
|
176
|
-
).toBeInTheDocument();
|
|
177
|
-
|
|
178
|
-
unmount();
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
test('legacyModule hooks MApp', async () => {
|
|
182
|
-
const userInfo = {
|
|
183
|
-
name: 'UserInfo',
|
|
184
|
-
activeWhen: '/user-info',
|
|
185
|
-
entry: userInfoPath,
|
|
186
|
-
};
|
|
187
|
-
const tableList2 = {
|
|
188
|
-
name: 'tablist2',
|
|
189
|
-
activeWhen: '/table-list',
|
|
190
|
-
entry: tableListPath,
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const microFrontendConfig = {
|
|
194
|
-
apps: [userInfo, tableList2],
|
|
195
|
-
LoadingComponent() {
|
|
196
|
-
return <div data-testid="loading-id">loading</div>;
|
|
197
|
-
},
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const App = () => {
|
|
201
|
-
const { MApp } = useModuleApps();
|
|
202
|
-
const NMApp = useModuleApp();
|
|
203
|
-
expect(MApp).toBe(NMApp);
|
|
204
|
-
|
|
205
|
-
return (
|
|
206
|
-
<MemoryRouter>
|
|
207
|
-
<div id="app">
|
|
208
|
-
<Link to="/">home</Link>
|
|
209
|
-
<Link data-testid="dashboard-link" to="/dashboard">
|
|
210
|
-
dashboard
|
|
211
|
-
</Link>
|
|
212
|
-
<Link data-testid="table-list-link" to="/table-list">
|
|
213
|
-
table-list
|
|
214
|
-
</Link>
|
|
215
|
-
<Link data-testid="user-info-link" to="/user-info">
|
|
216
|
-
user-info
|
|
217
|
-
</Link>
|
|
218
|
-
<MApp />
|
|
219
|
-
</div>
|
|
220
|
-
</MemoryRouter>
|
|
221
|
-
);
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
const AppWrapper = createApp({
|
|
225
|
-
plugins: [ModernGarfishPlugin(microFrontendConfig)],
|
|
226
|
-
})(App);
|
|
227
|
-
|
|
228
|
-
const { unmount } = render(<AppWrapper />);
|
|
229
|
-
|
|
230
|
-
history.pushState(null, '', '/user-info');
|
|
231
|
-
expect(
|
|
232
|
-
await screen.findByText(USER_INFO_ROOT_NODE.text),
|
|
233
|
-
).toBeInTheDocument();
|
|
234
|
-
expect(
|
|
235
|
-
await screen.findByText(USER_INFO_ESCAPE_NODE.text),
|
|
236
|
-
).toBeInTheDocument();
|
|
237
|
-
|
|
238
|
-
history.pushState(null, '', '/table-list');
|
|
239
|
-
await waitFor();
|
|
240
|
-
expect(screen.queryByText(USER_INFO_ROOT_NODE.text)).toBeNull();
|
|
241
|
-
expect(screen.queryByText(USER_INFO_ESCAPE_NODE.text)).toBeNull();
|
|
242
|
-
|
|
243
|
-
expect(
|
|
244
|
-
await screen.findByText(TABLE_LIST_ROOT_NODE.text),
|
|
245
|
-
).toBeInTheDocument();
|
|
246
|
-
expect(
|
|
247
|
-
await screen.findByText(TABLE_LIST_ESCAPE_NODE.text),
|
|
248
|
-
).toBeInTheDocument();
|
|
249
|
-
|
|
250
|
-
unmount();
|
|
251
|
-
});
|
|
252
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export const DASHBOARD_ROOT_NODE = {
|
|
2
|
-
text: 'dashboard content',
|
|
3
|
-
id: 'dashboard-id',
|
|
4
|
-
};
|
|
5
|
-
export const DASHBOARD_ESCAPE_NODE = {
|
|
6
|
-
text: 'dashboard-escape text',
|
|
7
|
-
id: 'dashboard-escape-id',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const DASHBOARD_HTML = `
|
|
11
|
-
<!DOCTYPE html>
|
|
12
|
-
<html lang="en">
|
|
13
|
-
<head>
|
|
14
|
-
<title>dashboard app</title>
|
|
15
|
-
</head>
|
|
16
|
-
<body>
|
|
17
|
-
<h1>dashboard</h1>
|
|
18
|
-
<div id="root"></div>
|
|
19
|
-
<script>
|
|
20
|
-
if (typeof __GARFISH_EXPORTS__ !=='undefined') {
|
|
21
|
-
__GARFISH_EXPORTS__.provider = ()=>{
|
|
22
|
-
return {
|
|
23
|
-
render ({ dom , basename }) {
|
|
24
|
-
let newContent = document.createElement('div');
|
|
25
|
-
newContent.innerHTML = "${DASHBOARD_ROOT_NODE.text}";
|
|
26
|
-
newContent.setAttribute('id','${DASHBOARD_ROOT_NODE.id}')
|
|
27
|
-
dom.querySelector('#root').appendChild(newContent);
|
|
28
|
-
|
|
29
|
-
let escapeNode = document.createElement('div');
|
|
30
|
-
escapeNode.innerHTML = "${DASHBOARD_ESCAPE_NODE.text}";
|
|
31
|
-
escapeNode.setAttribute('id',"${DASHBOARD_ESCAPE_NODE.id}")
|
|
32
|
-
document.body.appendChild(escapeNode);
|
|
33
|
-
},
|
|
34
|
-
destroy ({ dom , basename }){
|
|
35
|
-
document.body.removeChild(document.querySelector("#${DASHBOARD_ESCAPE_NODE.id}"));
|
|
36
|
-
dom.querySelector('#root').removeChild(dom.querySelector("#${DASHBOARD_ROOT_NODE.id}"));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
</script>
|
|
42
|
-
</body>
|
|
43
|
-
</html>
|
|
44
|
-
`;
|
package/tests/resource/table.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export const TABLE_LIST_ROOT_NODE = {
|
|
2
|
-
text: 'table-list content',
|
|
3
|
-
id: 'table-list-id',
|
|
4
|
-
};
|
|
5
|
-
export const TABLE_LIST_ESCAPE_NODE = {
|
|
6
|
-
text: 'table-list escape text',
|
|
7
|
-
id: 'table-list-escape-id',
|
|
8
|
-
};
|
|
9
|
-
export const TABLE_LIST_HTML = `
|
|
10
|
-
<!DOCTYPE html>
|
|
11
|
-
<html lang="en">
|
|
12
|
-
<head>
|
|
13
|
-
<title>table-list app</title>
|
|
14
|
-
</head>
|
|
15
|
-
<body>
|
|
16
|
-
<h1>table-list</h1>
|
|
17
|
-
<div id="root"></div>
|
|
18
|
-
<script>
|
|
19
|
-
if (typeof __GARFISH_EXPORTS__ !=='undefined') {
|
|
20
|
-
__GARFISH_EXPORTS__.provider = ()=>{
|
|
21
|
-
return {
|
|
22
|
-
render ({ dom , basename }) {
|
|
23
|
-
let newContent = document.createElement('div');
|
|
24
|
-
newContent.innerHTML = "${TABLE_LIST_ROOT_NODE.text}";
|
|
25
|
-
newContent.setAttribute('id','${TABLE_LIST_ROOT_NODE.id}')
|
|
26
|
-
dom.querySelector('#root').appendChild(newContent);
|
|
27
|
-
|
|
28
|
-
let escapeNode = document.createElement('div');
|
|
29
|
-
escapeNode.innerHTML = "${TABLE_LIST_ESCAPE_NODE.text}";
|
|
30
|
-
escapeNode.setAttribute('id',"${TABLE_LIST_ESCAPE_NODE.id}")
|
|
31
|
-
document.body.appendChild(escapeNode);
|
|
32
|
-
},
|
|
33
|
-
destroy ({ dom , basename }){
|
|
34
|
-
document.body.removeChild(document.querySelector("#${TABLE_LIST_ESCAPE_NODE.id}"));
|
|
35
|
-
dom.querySelector('#root').removeChild(dom.querySelector("#${TABLE_LIST_ROOT_NODE.id}"));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
</script>
|
|
41
|
-
</body>
|
|
42
|
-
</html>
|
|
43
|
-
`;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export const USER_INFO_ROOT_NODE = {
|
|
2
|
-
text: 'userInfo content',
|
|
3
|
-
id: 'userInfo-id',
|
|
4
|
-
};
|
|
5
|
-
export const USER_INFO_ESCAPE_NODE = {
|
|
6
|
-
text: 'userInfo-escape text',
|
|
7
|
-
id: 'userInfo-escape-id',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const USER_INFO_HTML = `
|
|
11
|
-
<!DOCTYPE html>
|
|
12
|
-
<html lang="en">
|
|
13
|
-
<head>
|
|
14
|
-
<title>userInfo app</title>
|
|
15
|
-
</head>
|
|
16
|
-
<body>
|
|
17
|
-
<h1>userInfo</h1>
|
|
18
|
-
<div id="root"></div>
|
|
19
|
-
<script>
|
|
20
|
-
if (typeof __GARFISH_EXPORTS__ !=='undefined') {
|
|
21
|
-
__GARFISH_EXPORTS__.provider = ()=>{
|
|
22
|
-
return {
|
|
23
|
-
render ({ dom , basename }) {
|
|
24
|
-
let newContent = document.createElement('div');
|
|
25
|
-
newContent.innerHTML = "${USER_INFO_ROOT_NODE.text}";
|
|
26
|
-
newContent.setAttribute('id','${USER_INFO_ROOT_NODE.id}')
|
|
27
|
-
dom.querySelector('#root').appendChild(newContent);
|
|
28
|
-
|
|
29
|
-
let escapeNode = document.createElement('div');
|
|
30
|
-
escapeNode.innerHTML = "${USER_INFO_ESCAPE_NODE.text}";
|
|
31
|
-
escapeNode.setAttribute('id',"${USER_INFO_ESCAPE_NODE.id}")
|
|
32
|
-
document.body.appendChild(escapeNode);
|
|
33
|
-
},
|
|
34
|
-
destroy ({ dom , basename }){
|
|
35
|
-
document.body.removeChild(document.querySelector("#${USER_INFO_ESCAPE_NODE.id}"));
|
|
36
|
-
dom.querySelector('#root').removeChild(dom.querySelector("#${USER_INFO_ROOT_NODE.id}"));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
</script>
|
|
42
|
-
</body>
|
|
43
|
-
</html>
|
|
44
|
-
`;
|