@modern-js/plugin-testing 2.4.1-beta.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +21 -6
- package/dist/{js/node → cjs}/base/config/index.js +3 -23
- package/dist/{js/node → cjs}/base/config/patches/assetsModule.js +0 -0
- package/dist/{js/node → cjs}/base/config/patches/filemock.js +0 -0
- package/dist/{js/node → cjs}/base/config/patches/index.js +6 -26
- package/dist/{js/node → cjs}/base/config/patches/transformer.js +0 -0
- package/dist/{js/node → cjs}/base/config/resolver.js +0 -0
- package/dist/{js/node → cjs}/base/config/testConfigOperator.js +1 -15
- package/dist/{js/node → cjs}/base/config/transformer/babelTransformer.js +0 -0
- package/dist/{js/node → cjs}/base/hook.js +0 -0
- package/dist/{js/node → cjs}/base/index.js +0 -0
- package/dist/{js/node → cjs}/base/runJest.js +24 -48
- package/dist/{js/node → cjs}/base/types/index.js +0 -0
- package/dist/{js/node → cjs}/base/utils.js +4 -15
- package/dist/{js/node → cjs}/cli/bff/app.js +6 -26
- package/dist/{js/node → cjs}/cli/bff/constant.js +0 -0
- package/dist/{js/node → cjs}/cli/bff/index.js +22 -49
- package/dist/{js/node → cjs}/cli/bff/mockAPI.js +5 -16
- package/dist/{js/node → cjs}/cli/bff/setup.js +6 -26
- package/dist/{js/node → cjs}/cli/bff/utils/index.js +1 -15
- package/dist/{js/node → cjs}/cli/index.js +6 -26
- package/dist/{js/node → cjs}/cli/test.js +4 -24
- package/dist/{js/node → cjs}/constant.js +0 -0
- package/dist/{js/node → cjs}/index.js +0 -0
- package/dist/{js/node → cjs}/runtime-testing/app.js +4 -15
- package/dist/{js/node → cjs}/runtime-testing/base.js +0 -0
- package/dist/{js/node → cjs}/runtime-testing/customRender.js +1 -15
- package/dist/{js/node → cjs}/runtime-testing/index.js +0 -0
- package/dist/{js/node → cjs}/runtime-testing/reduck.js +3 -19
- package/dist/{js/node → cjs}/runtime-testing/request.js +0 -0
- package/dist/{js/node → cjs}/runtime-testing/resolvePlugins.js +3 -15
- package/dist/{js/treeshaking → esm}/base/config/index.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/patches/assetsModule.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/patches/filemock.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/patches/index.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/patches/transformer.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/resolver.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/testConfigOperator.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/transformer/babelTransformer.js +0 -0
- package/dist/{js/treeshaking → esm}/base/hook.js +0 -0
- package/dist/{js/treeshaking → esm}/base/index.js +0 -0
- package/dist/{js/treeshaking → esm}/base/runJest.js +0 -0
- package/dist/{js/treeshaking → esm}/base/types/index.js +0 -0
- package/dist/{js/treeshaking → esm}/base/utils.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/app.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/constant.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/index.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/mockAPI.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/setup.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/utils/index.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/index.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/test.js +0 -0
- package/dist/{js/treeshaking → esm}/constant.js +0 -0
- package/dist/{js/treeshaking → esm}/index.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/app.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/base.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/customRender.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/index.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/reduck.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/request.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/resolvePlugins.js +0 -0
- package/dist/esm-node/base/config/index.js +16 -0
- package/dist/{js/modern → esm-node}/base/config/patches/assetsModule.js +0 -0
- package/dist/{js/modern → esm-node}/base/config/patches/filemock.js +0 -0
- package/dist/esm-node/base/config/patches/index.js +14 -0
- package/dist/{js/modern → esm-node}/base/config/patches/transformer.js +0 -0
- package/dist/{js/modern → esm-node}/base/config/resolver.js +0 -0
- package/dist/{js/modern → esm-node}/base/config/testConfigOperator.js +1 -17
- package/dist/{js/modern → esm-node}/base/config/transformer/babelTransformer.js +0 -0
- package/dist/{js/modern → esm-node}/base/hook.js +0 -0
- package/dist/{js/modern → esm-node}/base/index.js +0 -0
- package/dist/esm-node/base/runJest.js +78 -0
- package/dist/{js/modern → esm-node}/base/types/index.js +0 -0
- package/dist/{js/modern → esm-node}/base/utils.js +4 -17
- package/dist/esm-node/cli/bff/app.js +38 -0
- package/dist/{js/modern → esm-node}/cli/bff/constant.js +0 -0
- package/dist/{js/modern → esm-node}/cli/bff/index.js +22 -51
- package/dist/{js/modern → esm-node}/cli/bff/mockAPI.js +5 -18
- package/dist/esm-node/cli/bff/setup.js +46 -0
- package/dist/esm-node/cli/bff/utils/index.js +21 -0
- package/dist/{js/modern → esm-node}/cli/index.js +6 -26
- package/dist/{js/modern → esm-node}/cli/test.js +4 -24
- package/dist/{js/modern → esm-node}/constant.js +0 -0
- package/dist/{js/modern → esm-node}/index.js +0 -0
- package/dist/esm-node/runtime-testing/app.js +35 -0
- package/dist/{js/modern → esm-node}/runtime-testing/base.js +0 -0
- package/dist/esm-node/runtime-testing/customRender.js +9 -0
- package/dist/{js/modern → esm-node}/runtime-testing/index.js +0 -0
- package/dist/{js/modern → esm-node}/runtime-testing/reduck.js +3 -21
- package/dist/{js/modern → esm-node}/runtime-testing/request.js +0 -0
- package/dist/esm-node/runtime-testing/resolvePlugins.js +19 -0
- package/package.json +25 -26
- package/dist/js/modern/base/config/index.js +0 -36
- package/dist/js/modern/base/config/patches/index.js +0 -34
- package/dist/js/modern/base/runJest.js +0 -102
- package/dist/js/modern/cli/bff/app.js +0 -58
- package/dist/js/modern/cli/bff/setup.js +0 -75
- package/dist/js/modern/cli/bff/utils/index.js +0 -37
- package/dist/js/modern/runtime-testing/app.js +0 -48
- package/dist/js/modern/runtime-testing/customRender.js +0 -25
- package/dist/js/modern/runtime-testing/resolvePlugins.js +0 -33
@@ -1,39 +1,3 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
6
|
-
var __spreadValues = (a, b) => {
|
7
|
-
for (var prop in b || (b = {}))
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
10
|
-
if (__getOwnPropSymbols)
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
12
|
-
if (__propIsEnum.call(b, prop))
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
14
|
-
}
|
15
|
-
return a;
|
16
|
-
};
|
17
|
-
var __async = (__this, __arguments, generator) => {
|
18
|
-
return new Promise((resolve, reject) => {
|
19
|
-
var fulfilled = (value) => {
|
20
|
-
try {
|
21
|
-
step(generator.next(value));
|
22
|
-
} catch (e) {
|
23
|
-
reject(e);
|
24
|
-
}
|
25
|
-
};
|
26
|
-
var rejected = (value) => {
|
27
|
-
try {
|
28
|
-
step(generator.throw(value));
|
29
|
-
} catch (e) {
|
30
|
-
reject(e);
|
31
|
-
}
|
32
|
-
};
|
33
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
34
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
35
|
-
});
|
36
|
-
};
|
37
1
|
import path from "path";
|
38
2
|
import { isApiOnly } from "@modern-js/utils";
|
39
3
|
import {
|
@@ -42,13 +6,13 @@ import {
|
|
42
6
|
} from "../../base";
|
43
7
|
import { bff_info_key } from "./constant";
|
44
8
|
import { isBFFProject } from "./utils";
|
45
|
-
const setJestConfigForBFF =
|
9
|
+
const setJestConfigForBFF = async ({
|
46
10
|
pwd,
|
47
11
|
userConfig,
|
48
12
|
plugins,
|
49
13
|
routes,
|
50
14
|
utils
|
51
|
-
}) {
|
15
|
+
}) => {
|
52
16
|
var _a;
|
53
17
|
const bffConfig = {
|
54
18
|
rootDir: path.join(pwd, "./api"),
|
@@ -76,8 +40,11 @@ const setJestConfigForBFF = (_0) => __async(void 0, [_0], function* ({
|
|
76
40
|
const transform = {
|
77
41
|
"\\.[jt]sx?$": require.resolve("ts-jest")
|
78
42
|
};
|
79
|
-
const apiOnly =
|
80
|
-
const mergedModuleNameMapper =
|
43
|
+
const apiOnly = await isApiOnly(pwd);
|
44
|
+
const mergedModuleNameMapper = {
|
45
|
+
...moduleNameMapper,
|
46
|
+
...aliasMapper
|
47
|
+
};
|
81
48
|
const resolver = jestConfig.resolver || DEFAULT_RESOLVER_PATH;
|
82
49
|
const configFields = ["coverage", "collectCoverage", "testTimeout"];
|
83
50
|
const commonConfig = configFields.reduce((obj, field) => {
|
@@ -90,12 +57,15 @@ const setJestConfigForBFF = (_0) => __async(void 0, [_0], function* ({
|
|
90
57
|
utils.setJestConfig(
|
91
58
|
{
|
92
59
|
projects: [
|
93
|
-
|
94
|
-
|
60
|
+
{
|
61
|
+
...jestConfig
|
62
|
+
},
|
63
|
+
{
|
95
64
|
transform,
|
96
65
|
moduleNameMapper: mergedModuleNameMapper,
|
97
|
-
resolver
|
98
|
-
|
66
|
+
resolver,
|
67
|
+
...bffConfig
|
68
|
+
}
|
99
69
|
]
|
100
70
|
},
|
101
71
|
{
|
@@ -106,11 +76,12 @@ const setJestConfigForBFF = (_0) => __async(void 0, [_0], function* ({
|
|
106
76
|
utils.setJestConfig(
|
107
77
|
{
|
108
78
|
projects: [
|
109
|
-
|
79
|
+
{
|
110
80
|
transform,
|
111
81
|
moduleNameMapper: mergedModuleNameMapper,
|
112
|
-
resolver
|
113
|
-
|
82
|
+
resolver,
|
83
|
+
...bffConfig
|
84
|
+
}
|
114
85
|
]
|
115
86
|
},
|
116
87
|
{
|
@@ -119,19 +90,19 @@ const setJestConfigForBFF = (_0) => __async(void 0, [_0], function* ({
|
|
119
90
|
);
|
120
91
|
}
|
121
92
|
utils.setJestConfig(commonConfig);
|
122
|
-
}
|
93
|
+
};
|
123
94
|
var bff_default = () => ({
|
124
95
|
name: "@modern-js/testing-plugin-bff",
|
125
96
|
setup(api) {
|
126
97
|
return {
|
127
|
-
jestConfig: (utils, next) =>
|
98
|
+
jestConfig: async (utils, next) => {
|
128
99
|
const appContext = api.useAppContext();
|
129
100
|
const pwd = appContext.appDirectory;
|
130
101
|
if (!isBFFProject(pwd)) {
|
131
102
|
return next(utils);
|
132
103
|
}
|
133
104
|
const userConfig = api.useResolvedConfigContext();
|
134
|
-
|
105
|
+
await setJestConfigForBFF({
|
135
106
|
pwd,
|
136
107
|
userConfig,
|
137
108
|
routes: appContext.serverRoutes,
|
@@ -139,7 +110,7 @@ var bff_default = () => ({
|
|
139
110
|
utils
|
140
111
|
});
|
141
112
|
return next(utils);
|
142
|
-
}
|
113
|
+
}
|
143
114
|
};
|
144
115
|
}
|
145
116
|
});
|
@@ -1,19 +1,3 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
6
|
-
var __spreadValues = (a, b) => {
|
7
|
-
for (var prop in b || (b = {}))
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
10
|
-
if (__getOwnPropSymbols)
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
12
|
-
if (__propIsEnum.call(b, prop))
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
14
|
-
}
|
15
|
-
return a;
|
16
|
-
};
|
17
1
|
import * as ptr from "path-to-regexp";
|
18
2
|
import * as mockAppModule from "./app";
|
19
3
|
const mock_replaceUrlWithParams = (url, paramValues, payload) => {
|
@@ -26,7 +10,10 @@ const mock_replaceUrlWithParams = (url, paramValues, payload) => {
|
|
26
10
|
return cur;
|
27
11
|
}, {});
|
28
12
|
const getFinalPath = ptr.compile(url, { encode: encodeURIComponent });
|
29
|
-
return getFinalPath(
|
13
|
+
return getFinalPath({
|
14
|
+
...params,
|
15
|
+
...payload
|
16
|
+
});
|
30
17
|
};
|
31
18
|
const mock_getParamsAndPayload = (args) => {
|
32
19
|
if (args.length === 0) {
|
@@ -88,7 +75,7 @@ var mockAPI_default = (mockApiInfosByFile) => {
|
|
88
75
|
return test.then((value) => {
|
89
76
|
try {
|
90
77
|
return JSON.parse(value.text);
|
91
|
-
} catch
|
78
|
+
} catch {
|
92
79
|
return value.text;
|
93
80
|
}
|
94
81
|
});
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import path from "path";
|
2
|
+
import { ApiRouter } from "@modern-js/bff-core";
|
3
|
+
import { bff_info_key } from "./constant";
|
4
|
+
import mockAPI from "./mockAPI";
|
5
|
+
import { createApp, closeServer } from "./app";
|
6
|
+
let uped = false;
|
7
|
+
const setup = () => {
|
8
|
+
var _a, _b;
|
9
|
+
if (uped) {
|
10
|
+
return;
|
11
|
+
}
|
12
|
+
uped = true;
|
13
|
+
const bff_info = global[bff_info_key];
|
14
|
+
const prefix = (_b = (_a = bff_info == null ? void 0 : bff_info.modernUserConfig) == null ? void 0 : _a.bff) == null ? void 0 : _b.prefix;
|
15
|
+
const apiRouter = new ApiRouter({
|
16
|
+
apiDir: path.join(bff_info.appDir, "./api"),
|
17
|
+
prefix
|
18
|
+
});
|
19
|
+
const apiInfos = apiRouter.getApiHandlers();
|
20
|
+
const apiInfosByFile = apiInfos.reduce(
|
21
|
+
(res, apiInfo) => {
|
22
|
+
if (!res[apiInfo.filename]) {
|
23
|
+
res[apiInfo.filename] = [];
|
24
|
+
}
|
25
|
+
res[apiInfo.filename].push(apiInfo);
|
26
|
+
return res;
|
27
|
+
},
|
28
|
+
{}
|
29
|
+
);
|
30
|
+
let app = null;
|
31
|
+
beforeAll(async () => {
|
32
|
+
if (!app) {
|
33
|
+
app = await createApp(
|
34
|
+
bff_info.appDir,
|
35
|
+
bff_info.modernUserConfig,
|
36
|
+
bff_info.plugins,
|
37
|
+
bff_info.routes
|
38
|
+
);
|
39
|
+
}
|
40
|
+
});
|
41
|
+
afterAll(async () => {
|
42
|
+
await closeServer();
|
43
|
+
});
|
44
|
+
mockAPI(apiInfosByFile);
|
45
|
+
};
|
46
|
+
setup();
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import path from "path";
|
2
|
+
import { chalk } from "@modern-js/utils";
|
3
|
+
const isBFFProject = (pwd) => {
|
4
|
+
try {
|
5
|
+
const packageJson = require(path.join(pwd, "./package.json"));
|
6
|
+
const { dependencies, devDependencies } = packageJson;
|
7
|
+
const isBFF = Object.keys({ ...dependencies, ...devDependencies }).some(
|
8
|
+
(dependency) => dependency.includes("plugin-bff")
|
9
|
+
);
|
10
|
+
const isMWA = Object.keys(devDependencies).some(
|
11
|
+
(devDependency) => devDependency.includes("app-tools")
|
12
|
+
);
|
13
|
+
return isMWA && isBFF;
|
14
|
+
} catch (error) {
|
15
|
+
console.log(chalk.red(error));
|
16
|
+
return false;
|
17
|
+
}
|
18
|
+
};
|
19
|
+
export {
|
20
|
+
isBFFProject
|
21
|
+
};
|
@@ -1,23 +1,3 @@
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
2
|
-
return new Promise((resolve, reject) => {
|
3
|
-
var fulfilled = (value) => {
|
4
|
-
try {
|
5
|
-
step(generator.next(value));
|
6
|
-
} catch (e) {
|
7
|
-
reject(e);
|
8
|
-
}
|
9
|
-
};
|
10
|
-
var rejected = (value) => {
|
11
|
-
try {
|
12
|
-
step(generator.throw(value));
|
13
|
-
} catch (e) {
|
14
|
-
reject(e);
|
15
|
-
}
|
16
|
-
};
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
19
|
-
});
|
20
|
-
};
|
21
1
|
import path from "path";
|
22
2
|
import {
|
23
3
|
isApiOnly,
|
@@ -50,9 +30,9 @@ var cli_default = () => {
|
|
50
30
|
let testingExportsUtils;
|
51
31
|
return {
|
52
32
|
commands: ({ program }) => {
|
53
|
-
program.command("test").allowUnknownOption().usage("<regexForTestFiles> --[options]").action(() =>
|
54
|
-
|
55
|
-
})
|
33
|
+
program.command("test").allowUnknownOption().usage("<regexForTestFiles> --[options]").action(async () => {
|
34
|
+
await test(api);
|
35
|
+
});
|
56
36
|
},
|
57
37
|
validateSchema() {
|
58
38
|
return PLUGIN_SCHEMAS["@modern-js/plugin-testing"];
|
@@ -76,10 +56,10 @@ var cli_default = () => {
|
|
76
56
|
const testingPath = path.resolve(__dirname, "../");
|
77
57
|
testingExportsUtils.addExport(`export * from '${testingPath}'`);
|
78
58
|
},
|
79
|
-
jestConfig: (utils, next) =>
|
59
|
+
jestConfig: async (utils, next) => {
|
80
60
|
const appContext = api.useAppContext();
|
81
61
|
const userConfig = api.useResolvedConfigContext();
|
82
|
-
const apiOnly =
|
62
|
+
const apiOnly = await isApiOnly(appContext.appDirectory);
|
83
63
|
if (apiOnly) {
|
84
64
|
return next(utils);
|
85
65
|
}
|
@@ -104,7 +84,7 @@ var cli_default = () => {
|
|
104
84
|
});
|
105
85
|
mergeUserJestConfig(utils);
|
106
86
|
return next(utils);
|
107
|
-
}
|
87
|
+
}
|
108
88
|
};
|
109
89
|
}
|
110
90
|
};
|
@@ -1,27 +1,7 @@
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
2
|
-
return new Promise((resolve, reject) => {
|
3
|
-
var fulfilled = (value) => {
|
4
|
-
try {
|
5
|
-
step(generator.next(value));
|
6
|
-
} catch (e) {
|
7
|
-
reject(e);
|
8
|
-
}
|
9
|
-
};
|
10
|
-
var rejected = (value) => {
|
11
|
-
try {
|
12
|
-
step(generator.throw(value));
|
13
|
-
} catch (e) {
|
14
|
-
reject(e);
|
15
|
-
}
|
16
|
-
};
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
19
|
-
});
|
20
|
-
};
|
21
1
|
import path from "path";
|
22
2
|
import { compiler } from "@modern-js/babel-compiler";
|
23
3
|
import { runTest } from "../base";
|
24
|
-
const test = (api) =>
|
4
|
+
const test = async (api) => {
|
25
5
|
var _a, _b;
|
26
6
|
const userConfig = api.useResolvedConfigContext();
|
27
7
|
const appContext = api.useAppContext();
|
@@ -35,7 +15,7 @@ const test = (api) => __async(void 0, null, function* () {
|
|
35
15
|
appContext.internalDirectory,
|
36
16
|
".runtime-exports"
|
37
17
|
);
|
38
|
-
|
18
|
+
await compiler(
|
39
19
|
{
|
40
20
|
sourceDir: runtimeExportsPath,
|
41
21
|
rootDir: runtimeExportsPath,
|
@@ -53,8 +33,8 @@ const test = (api) => __async(void 0, null, function* () {
|
|
53
33
|
]
|
54
34
|
}
|
55
35
|
);
|
56
|
-
|
57
|
-
}
|
36
|
+
await runTest(api, userConfig.testing);
|
37
|
+
};
|
58
38
|
var test_default = test;
|
59
39
|
export {
|
60
40
|
test_default as default
|
File without changes
|
File without changes
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { createApp } from "@modern-js/runtime";
|
2
|
+
import { MODERNJS_CONFIG_KEY } from "../constant";
|
3
|
+
import resolvePlugins from "./resolvePlugins";
|
4
|
+
class ModernRuntime {
|
5
|
+
constructor(options) {
|
6
|
+
this.options = options;
|
7
|
+
}
|
8
|
+
init(options) {
|
9
|
+
this.options = options;
|
10
|
+
}
|
11
|
+
createApp(props) {
|
12
|
+
var _a, _b;
|
13
|
+
const { entry, children } = props || {};
|
14
|
+
let runtimeFeatures = (_a = this.options) == null ? void 0 : _a.runtime;
|
15
|
+
if (entry) {
|
16
|
+
runtimeFeatures = {
|
17
|
+
...runtimeFeatures || {},
|
18
|
+
...(_b = this.options.runtimeByEntries) == null ? void 0 : _b[entry]
|
19
|
+
};
|
20
|
+
}
|
21
|
+
const Component = () => {
|
22
|
+
if (!children) {
|
23
|
+
return null;
|
24
|
+
}
|
25
|
+
return children;
|
26
|
+
};
|
27
|
+
return createApp({
|
28
|
+
plugins: resolvePlugins(runtimeFeatures || {})
|
29
|
+
})(Component);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
var app_default = new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
|
33
|
+
export {
|
34
|
+
app_default as default
|
35
|
+
};
|
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { render } from "@testing-library/react";
|
3
|
+
import app from "./app";
|
4
|
+
const WrapModernProviders = (props) => React.createElement(app.createApp(props));
|
5
|
+
const customRender = (ui, options) => render(ui, { wrapper: WrapModernProviders, ...options });
|
6
|
+
var customRender_default = customRender;
|
7
|
+
export {
|
8
|
+
customRender_default as default
|
9
|
+
};
|
File without changes
|
@@ -1,22 +1,3 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __defProps = Object.defineProperties;
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
-
var __spreadValues = (a, b) => {
|
9
|
-
for (var prop in b || (b = {}))
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
12
|
-
if (__getOwnPropSymbols)
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
-
if (__propIsEnum.call(b, prop))
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
16
|
-
}
|
17
|
-
return a;
|
18
|
-
};
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
20
1
|
import { createStore as originCreateStore } from "@modern-js-reduck/store";
|
21
2
|
import effectsPlugin from "@modern-js-reduck/plugin-effects";
|
22
3
|
import autoActionsPlugin from "@modern-js-reduck/plugin-auto-actions";
|
@@ -42,9 +23,10 @@ const createStore = (props) => {
|
|
42
23
|
}
|
43
24
|
return ((props == null ? void 0 : props.plugins) || []).concat(plugins);
|
44
25
|
};
|
45
|
-
const config =
|
26
|
+
const config = {
|
27
|
+
...props || {},
|
46
28
|
plugins: createStatePlugins()
|
47
|
-
}
|
29
|
+
};
|
48
30
|
return originCreateStore(config);
|
49
31
|
};
|
50
32
|
export {
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
const allowedFeatures = ["router", "state"];
|
2
|
+
function resolvePlugins(features) {
|
3
|
+
const plugins = [];
|
4
|
+
if (!features) {
|
5
|
+
return plugins;
|
6
|
+
}
|
7
|
+
Object.keys(features).forEach((feature) => {
|
8
|
+
if (allowedFeatures.includes(feature)) {
|
9
|
+
const curPluginRes = require(`@modern-js/runtime/plugins`)[feature]({
|
10
|
+
...features[feature]
|
11
|
+
});
|
12
|
+
plugins.push(curPluginRes);
|
13
|
+
}
|
14
|
+
});
|
15
|
+
return plugins;
|
16
|
+
}
|
17
|
+
export {
|
18
|
+
resolvePlugins as default
|
19
|
+
};
|
package/package.json
CHANGED
@@ -11,12 +11,11 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "2.
|
14
|
+
"version": "2.5.0",
|
15
15
|
"jsnext:source": "./src/cli/index.ts",
|
16
16
|
"types": "./dist/types/cli/index.d.ts",
|
17
|
-
"main": "./dist/
|
18
|
-
"module": "./dist/
|
19
|
-
"jsnext:modern": "./dist/js/modern/cli/index.js",
|
17
|
+
"main": "./dist/cjs/cli/index.js",
|
18
|
+
"module": "./dist/esm/cli/index.js",
|
20
19
|
"exports": {
|
21
20
|
"./types": {
|
22
21
|
"jsnext:source": "./types/index.d.ts",
|
@@ -28,35 +27,35 @@
|
|
28
27
|
},
|
29
28
|
".": {
|
30
29
|
"jsnext:source": "./src/cli/index.ts",
|
31
|
-
"default": "./dist/
|
30
|
+
"default": "./dist/cjs/cli/index.js"
|
32
31
|
},
|
33
32
|
"./runtime": {
|
34
33
|
"jsnext:source": "./src/runtime-testing/index.ts",
|
35
34
|
"node": {
|
36
|
-
"import": "./dist/
|
37
|
-
"require": "./dist/
|
35
|
+
"import": "./dist/esm-node/runtime-testing/index.js",
|
36
|
+
"require": "./dist/cjs/runtime-testing/index.js"
|
38
37
|
},
|
39
|
-
"default": "./dist/
|
38
|
+
"default": "./dist/esm/runtime-testing/index.js"
|
40
39
|
},
|
41
40
|
"./runtime-base": {
|
42
41
|
"jsnext:source": "./src/runtime-testing/base.ts",
|
43
42
|
"node": {
|
44
|
-
"import": "./dist/
|
45
|
-
"require": "./dist/
|
43
|
+
"import": "./dist/esm-node/runtime-testing/base.js",
|
44
|
+
"require": "./dist/cjs/runtime-testing/base.js"
|
46
45
|
},
|
47
|
-
"default": "./dist/
|
46
|
+
"default": "./dist/esm/runtime-testing/base.js"
|
48
47
|
},
|
49
48
|
"./cli": {
|
50
49
|
"jsnext:source": "./src/cli/index.ts",
|
51
|
-
"default": "./dist/
|
50
|
+
"default": "./dist/cjs/cli/index.js"
|
52
51
|
},
|
53
52
|
"./bff-cli": {
|
54
53
|
"jsnext:source": "./src/cli/bff/index.ts",
|
55
|
-
"default": "./dist/
|
54
|
+
"default": "./dist/cjs/cli/bff/index.js"
|
56
55
|
},
|
57
56
|
"./base": {
|
58
57
|
"jsnext:source": "./src/base/index.ts",
|
59
|
-
"default": "./dist/
|
58
|
+
"default": "./dist/cjs/base/index.js"
|
60
59
|
}
|
61
60
|
},
|
62
61
|
"typesVersions": {
|
@@ -107,16 +106,16 @@
|
|
107
106
|
"jest": "^27.0.6",
|
108
107
|
"ts-jest": "^27.0.4",
|
109
108
|
"yargs": "^17.0.1",
|
110
|
-
"@modern-js/babel-compiler": "2.
|
111
|
-
"@modern-js/utils": "2.
|
112
|
-
"@modern-js/babel-preset-app": "2.
|
113
|
-
"@modern-js/plugin": "2.
|
114
|
-
"@modern-js/prod-server": "2.
|
109
|
+
"@modern-js/babel-compiler": "2.5.0",
|
110
|
+
"@modern-js/utils": "2.5.0",
|
111
|
+
"@modern-js/babel-preset-app": "2.5.0",
|
112
|
+
"@modern-js/plugin": "2.5.0",
|
113
|
+
"@modern-js/prod-server": "2.5.0"
|
115
114
|
},
|
116
115
|
"peerDependencies": {
|
117
116
|
"react": ">=17",
|
118
117
|
"react-dom": ">=17",
|
119
|
-
"@modern-js/runtime": "^2.
|
118
|
+
"@modern-js/runtime": "^2.5.0"
|
120
119
|
},
|
121
120
|
"peerDependenciesMeta": {
|
122
121
|
"@modern-js/runtime": {
|
@@ -133,12 +132,12 @@
|
|
133
132
|
"@jest/types": "^27.0.6",
|
134
133
|
"jest": "^27",
|
135
134
|
"typescript": "^4",
|
136
|
-
"@modern-js/core": "2.
|
137
|
-
"@modern-js/types": "2.
|
138
|
-
"@modern-js/runtime": "2.
|
139
|
-
"@modern-js/bff-core": "2.
|
140
|
-
"@scripts/build": "2.
|
141
|
-
"@scripts/jest-config": "2.
|
135
|
+
"@modern-js/core": "2.5.0",
|
136
|
+
"@modern-js/types": "2.5.0",
|
137
|
+
"@modern-js/runtime": "2.5.0",
|
138
|
+
"@modern-js/bff-core": "2.5.0",
|
139
|
+
"@scripts/build": "2.5.0",
|
140
|
+
"@scripts/jest-config": "2.5.0"
|
142
141
|
},
|
143
142
|
"sideEffects": false,
|
144
143
|
"modernConfig": {},
|
@@ -1,36 +0,0 @@
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
2
|
-
return new Promise((resolve, reject) => {
|
3
|
-
var fulfilled = (value) => {
|
4
|
-
try {
|
5
|
-
step(generator.next(value));
|
6
|
-
} catch (e) {
|
7
|
-
reject(e);
|
8
|
-
}
|
9
|
-
};
|
10
|
-
var rejected = (value) => {
|
11
|
-
try {
|
12
|
-
step(generator.throw(value));
|
13
|
-
} catch (e) {
|
14
|
-
reject(e);
|
15
|
-
}
|
16
|
-
};
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
19
|
-
});
|
20
|
-
};
|
21
|
-
import { applyPatches } from "./patches";
|
22
|
-
import { TestConfigOperator } from "./testConfigOperator";
|
23
|
-
const getJestUtils = (testConfig) => {
|
24
|
-
const testOperator = new TestConfigOperator(testConfig);
|
25
|
-
return testOperator;
|
26
|
-
};
|
27
|
-
const patchConfig = (testOperator) => __async(void 0, null, function* () {
|
28
|
-
yield applyPatches(testOperator);
|
29
|
-
return testOperator.jestConfig;
|
30
|
-
});
|
31
|
-
const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
32
|
-
export {
|
33
|
-
DEFAULT_RESOLVER_PATH,
|
34
|
-
getJestUtils,
|
35
|
-
patchConfig
|
36
|
-
};
|
@@ -1,34 +0,0 @@
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
2
|
-
return new Promise((resolve, reject) => {
|
3
|
-
var fulfilled = (value) => {
|
4
|
-
try {
|
5
|
-
step(generator.next(value));
|
6
|
-
} catch (e) {
|
7
|
-
reject(e);
|
8
|
-
}
|
9
|
-
};
|
10
|
-
var rejected = (value) => {
|
11
|
-
try {
|
12
|
-
step(generator.throw(value));
|
13
|
-
} catch (e) {
|
14
|
-
reject(e);
|
15
|
-
}
|
16
|
-
};
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
19
|
-
});
|
20
|
-
};
|
21
|
-
import { patchTransformer } from "./transformer";
|
22
|
-
import { patchAssetsModule } from "./assetsModule";
|
23
|
-
const _applyPatches = (patches2, testOperator) => __async(void 0, null, function* () {
|
24
|
-
for (const patch of patches2) {
|
25
|
-
yield patch(testOperator);
|
26
|
-
}
|
27
|
-
});
|
28
|
-
const patches = [patchTransformer, patchAssetsModule];
|
29
|
-
const applyPatches = (testConfig) => __async(void 0, null, function* () {
|
30
|
-
yield _applyPatches(patches, testConfig);
|
31
|
-
});
|
32
|
-
export {
|
33
|
-
applyPatches
|
34
|
-
};
|