@modern-js/plugin-testing 2.14.0 → 2.16.0
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/CHANGELOG.md +32 -0
- package/dist/cjs/base/config/index.js +15 -39
- package/dist/cjs/base/config/patches/assetsModule.js +7 -35
- package/dist/cjs/base/config/patches/filemock.js +8 -24
- package/dist/cjs/base/config/patches/index.js +13 -28
- package/dist/cjs/base/config/patches/transformer.js +13 -38
- package/dist/cjs/base/config/resolver.js +23 -26
- package/dist/cjs/base/config/testConfigOperator.js +39 -38
- package/dist/cjs/base/config/transformer/babelTransformer.js +16 -37
- package/dist/cjs/base/hook.js +17 -31
- package/dist/cjs/base/index.js +36 -41
- package/dist/cjs/base/runJest.js +31 -57
- package/dist/cjs/base/types/index.js +4 -15
- package/dist/cjs/base/utils.js +30 -53
- package/dist/cjs/cli/bff/app.js +17 -32
- package/dist/cjs/cli/bff/constant.js +7 -25
- package/dist/cjs/cli/bff/index.js +71 -92
- package/dist/cjs/cli/bff/mockAPI.js +115 -92
- package/dist/cjs/cli/bff/setup.js +30 -51
- package/dist/cjs/cli/bff/utils/index.js +21 -45
- package/dist/cjs/cli/index.js +43 -59
- package/dist/cjs/cli/test.js +35 -62
- package/dist/cjs/constant.js +7 -25
- package/dist/cjs/index.js +20 -19
- package/dist/cjs/runtime-testing/app.js +40 -45
- package/dist/cjs/runtime-testing/base.js +34 -40
- package/dist/cjs/runtime-testing/customRender.js +21 -39
- package/dist/cjs/runtime-testing/index.js +19 -18
- package/dist/cjs/runtime-testing/reduck.js +35 -55
- package/dist/cjs/runtime-testing/request.js +16 -39
- package/dist/cjs/runtime-testing/resolvePlugins.js +12 -25
- package/dist/esm/base/config/index.js +146 -139
- package/dist/esm/base/config/patches/assetsModule.js +7 -8
- package/dist/esm/base/config/patches/filemock.js +1 -2
- package/dist/esm/base/config/patches/index.js +214 -207
- package/dist/esm/base/config/patches/transformer.js +27 -28
- package/dist/esm/base/config/resolver.js +22 -35
- package/dist/esm/base/config/testConfigOperator.js +119 -116
- package/dist/esm/base/config/transformer/babelTransformer.js +12 -13
- package/dist/esm/base/hook.js +5 -6
- package/dist/esm/base/index.js +5 -6
- package/dist/esm/base/runJest.js +270 -264
- package/dist/esm/base/types/index.js +1 -1
- package/dist/esm/base/utils.js +66 -67
- package/dist/esm/cli/bff/app.js +187 -179
- package/dist/esm/cli/bff/constant.js +1 -2
- package/dist/esm/cli/bff/index.js +285 -278
- package/dist/esm/cli/bff/mockAPI.js +177 -163
- package/dist/esm/cli/bff/setup.js +182 -174
- package/dist/esm/cli/bff/utils/index.js +40 -41
- package/dist/esm/cli/index.js +249 -242
- package/dist/esm/cli/test.js +172 -166
- package/dist/esm/constant.js +1 -2
- package/dist/esm/runtime-testing/app.js +79 -77
- package/dist/esm/runtime-testing/base.js +2 -3
- package/dist/esm/runtime-testing/customRender.js +30 -31
- package/dist/esm/runtime-testing/reduck.js +72 -73
- package/dist/esm/runtime-testing/request.js +55 -45
- package/dist/esm/runtime-testing/resolvePlugins.js +38 -39
- package/dist/esm-node/base/config/index.js +2 -6
- package/dist/esm-node/base/config/patches/assetsModule.js +1 -4
- package/dist/esm-node/base/config/patches/filemock.js +1 -4
- package/dist/esm-node/base/config/patches/index.js +5 -5
- package/dist/esm-node/base/config/patches/transformer.js +5 -5
- package/dist/esm-node/base/config/resolver.js +20 -19
- package/dist/esm-node/base/config/testConfigOperator.js +30 -13
- package/dist/esm-node/base/config/transformer/babelTransformer.js +3 -6
- package/dist/esm-node/base/hook.js +3 -8
- package/dist/esm-node/base/index.js +5 -13
- package/dist/esm-node/base/runJest.js +8 -20
- package/dist/esm-node/base/types/index.js +1 -0
- package/dist/esm-node/base/utils.js +8 -17
- package/dist/esm-node/cli/bff/app.js +2 -7
- package/dist/esm-node/cli/bff/constant.js +1 -4
- package/dist/esm-node/cli/bff/index.js +43 -54
- package/dist/esm-node/cli/bff/mockAPI.js +65 -59
- package/dist/esm-node/cli/bff/setup.js +11 -19
- package/dist/esm-node/cli/bff/utils/index.js +6 -10
- package/dist/esm-node/cli/index.js +11 -23
- package/dist/esm-node/cli/test.js +19 -28
- package/dist/esm-node/constant.js +1 -4
- package/dist/esm-node/runtime-testing/app.js +22 -10
- package/dist/esm-node/runtime-testing/base.js +2 -6
- package/dist/esm-node/runtime-testing/customRender.js +5 -5
- package/dist/esm-node/runtime-testing/reduck.js +10 -16
- package/dist/esm-node/runtime-testing/request.js +1 -3
- package/dist/esm-node/runtime-testing/resolvePlugins.js +6 -6
- package/package.json +18 -14
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { createDebugger } from "@modern-js/utils";
|
|
4
|
-
const debug = createDebugger("test");
|
|
5
|
-
const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") => {
|
|
4
|
+
export const debug = createDebugger("test");
|
|
5
|
+
export const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") => {
|
|
6
6
|
let tsConfig = {};
|
|
7
7
|
let extendedCompilerOptions = {};
|
|
8
8
|
let tsconfigFile = "";
|
|
@@ -13,26 +13,22 @@ const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") =>
|
|
|
13
13
|
} else {
|
|
14
14
|
tsconfigFile = require.resolve(filename);
|
|
15
15
|
}
|
|
16
|
-
({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(
|
|
17
|
-
tsconfigFile,
|
|
18
|
-
fs.readFileSync(tsconfigFile, "utf8")
|
|
19
|
-
));
|
|
16
|
+
({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(tsconfigFile, fs.readFileSync(tsconfigFile, "utf8")));
|
|
20
17
|
} catch (e) {
|
|
21
18
|
return {};
|
|
22
19
|
}
|
|
23
20
|
if (tsConfig.extends) {
|
|
24
|
-
extendedCompilerOptions = readCompilerOptions(
|
|
25
|
-
path.dirname(tsconfigFile),
|
|
26
|
-
tsConfig.extends
|
|
27
|
-
);
|
|
21
|
+
extendedCompilerOptions = readCompilerOptions(path.dirname(tsconfigFile), tsConfig.extends);
|
|
28
22
|
}
|
|
29
23
|
return {
|
|
30
24
|
...extendedCompilerOptions,
|
|
31
25
|
...tsConfig.compilerOptions
|
|
32
26
|
};
|
|
33
27
|
};
|
|
34
|
-
const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
|
|
35
|
-
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [
|
|
28
|
+
export const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
|
|
29
|
+
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [
|
|
30
|
+
alias[cur]
|
|
31
|
+
];
|
|
36
32
|
const isFile = aliasValue.some((s) => s.endsWith(".js"));
|
|
37
33
|
if (cur === "@modern-js/runtime$") {
|
|
38
34
|
memo[`.+${cur}`] = aliasValue[0];
|
|
@@ -46,8 +42,3 @@ const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) =>
|
|
|
46
42
|
memo[key] = value;
|
|
47
43
|
return memo;
|
|
48
44
|
}, {});
|
|
49
|
-
export {
|
|
50
|
-
debug,
|
|
51
|
-
getModuleNameMapper,
|
|
52
|
-
readCompilerOptions
|
|
53
|
-
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "async_hooks";
|
|
2
2
|
import { Server } from "@modern-js/prod-server";
|
|
3
3
|
const store = new AsyncLocalStorage();
|
|
4
|
-
const isInHandler = () => Boolean(store.getStore());
|
|
4
|
+
export const isInHandler = () => Boolean(store.getStore());
|
|
5
5
|
let server = null;
|
|
6
6
|
const createApp = async (pwd, config, plugins, routes) => {
|
|
7
7
|
if (!server) {
|
|
@@ -30,9 +30,4 @@ const closeServer = async () => {
|
|
|
30
30
|
}
|
|
31
31
|
await server.close();
|
|
32
32
|
};
|
|
33
|
-
export {
|
|
34
|
-
closeServer,
|
|
35
|
-
createApp,
|
|
36
|
-
getApp,
|
|
37
|
-
isInHandler
|
|
38
|
-
};
|
|
33
|
+
export { createApp, getApp, closeServer };
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { isApiOnly } from "@modern-js/utils";
|
|
3
|
-
import {
|
|
4
|
-
getModuleNameMapper,
|
|
5
|
-
DEFAULT_RESOLVER_PATH
|
|
6
|
-
} from "../../base";
|
|
3
|
+
import { getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../../base";
|
|
7
4
|
import { bff_info_key } from "./constant";
|
|
8
5
|
import { isBFFProject } from "./utils";
|
|
9
|
-
const setJestConfigForBFF = async ({
|
|
10
|
-
|
|
11
|
-
userConfig,
|
|
12
|
-
plugins,
|
|
13
|
-
routes,
|
|
14
|
-
utils
|
|
15
|
-
}) => {
|
|
16
|
-
var _a;
|
|
6
|
+
export const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils }) => {
|
|
7
|
+
var _userConfig_source;
|
|
17
8
|
const bffConfig = {
|
|
18
9
|
rootDir: path.join(pwd, "./api"),
|
|
19
|
-
setupFilesAfterEnv: [
|
|
10
|
+
setupFilesAfterEnv: [
|
|
11
|
+
require.resolve("./setup")
|
|
12
|
+
],
|
|
20
13
|
testEnvironment: "node",
|
|
21
|
-
testMatch: [
|
|
14
|
+
testMatch: [
|
|
15
|
+
`**/api/**/*.test.[jt]s`
|
|
16
|
+
],
|
|
22
17
|
globals: {
|
|
23
18
|
[bff_info_key]: {
|
|
24
19
|
appDir: pwd,
|
|
@@ -29,7 +24,7 @@ const setJestConfigForBFF = async ({
|
|
|
29
24
|
}
|
|
30
25
|
};
|
|
31
26
|
const { jestConfig } = utils;
|
|
32
|
-
const alias = (
|
|
27
|
+
const alias = (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.alias) || {};
|
|
33
28
|
const aliasMapper = getModuleNameMapper(alias);
|
|
34
29
|
const { moduleNameMapper } = jestConfig;
|
|
35
30
|
const transform = {
|
|
@@ -48,7 +43,11 @@ const setJestConfigForBFF = async ({
|
|
|
48
43
|
...aliasMapper
|
|
49
44
|
};
|
|
50
45
|
const resolver = jestConfig.resolver || DEFAULT_RESOLVER_PATH;
|
|
51
|
-
const configFields = [
|
|
46
|
+
const configFields = [
|
|
47
|
+
"coverage",
|
|
48
|
+
"collectCoverage",
|
|
49
|
+
"testTimeout"
|
|
50
|
+
];
|
|
52
51
|
const commonConfig = configFields.reduce((obj, field) => {
|
|
53
52
|
if (jestConfig.hasOwnProperty(field)) {
|
|
54
53
|
obj[field] = jestConfig[field];
|
|
@@ -56,44 +55,38 @@ const setJestConfigForBFF = async ({
|
|
|
56
55
|
return obj;
|
|
57
56
|
}, {});
|
|
58
57
|
if (!apiOnly) {
|
|
59
|
-
utils.setJestConfig(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
force: true
|
|
75
|
-
}
|
|
76
|
-
);
|
|
58
|
+
utils.setJestConfig({
|
|
59
|
+
projects: [
|
|
60
|
+
{
|
|
61
|
+
...jestConfig
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
transform,
|
|
65
|
+
moduleNameMapper: mergedModuleNameMapper,
|
|
66
|
+
resolver,
|
|
67
|
+
...bffConfig
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}, {
|
|
71
|
+
force: true
|
|
72
|
+
});
|
|
77
73
|
} else {
|
|
78
|
-
utils.setJestConfig(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
force: true
|
|
91
|
-
}
|
|
92
|
-
);
|
|
74
|
+
utils.setJestConfig({
|
|
75
|
+
projects: [
|
|
76
|
+
{
|
|
77
|
+
transform,
|
|
78
|
+
moduleNameMapper: mergedModuleNameMapper,
|
|
79
|
+
resolver,
|
|
80
|
+
...bffConfig
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}, {
|
|
84
|
+
force: true
|
|
85
|
+
});
|
|
93
86
|
}
|
|
94
87
|
utils.setJestConfig(commonConfig);
|
|
95
88
|
};
|
|
96
|
-
|
|
89
|
+
export default () => ({
|
|
97
90
|
name: "@modern-js/testing-plugin-bff",
|
|
98
91
|
setup(api) {
|
|
99
92
|
return {
|
|
@@ -116,7 +109,3 @@ var bff_default = () => ({
|
|
|
116
109
|
};
|
|
117
110
|
}
|
|
118
111
|
});
|
|
119
|
-
export {
|
|
120
|
-
bff_default as default,
|
|
121
|
-
setJestConfigForBFF
|
|
122
|
-
};
|
|
@@ -9,7 +9,9 @@ const mock_replaceUrlWithParams = (url, paramValues, payload) => {
|
|
|
9
9
|
}
|
|
10
10
|
return cur;
|
|
11
11
|
}, {});
|
|
12
|
-
const getFinalPath = ptr.compile(url, {
|
|
12
|
+
const getFinalPath = ptr.compile(url, {
|
|
13
|
+
encode: encodeURIComponent
|
|
14
|
+
});
|
|
13
15
|
return getFinalPath({
|
|
14
16
|
...params,
|
|
15
17
|
...payload
|
|
@@ -17,80 +19,84 @@ const mock_replaceUrlWithParams = (url, paramValues, payload) => {
|
|
|
17
19
|
};
|
|
18
20
|
const mock_getParamsAndPayload = (args) => {
|
|
19
21
|
if (args.length === 0) {
|
|
20
|
-
return [
|
|
22
|
+
return [
|
|
23
|
+
[],
|
|
24
|
+
{}
|
|
25
|
+
];
|
|
21
26
|
}
|
|
22
27
|
const head = args[0];
|
|
23
28
|
if (typeof head === "object") {
|
|
24
|
-
return [
|
|
29
|
+
return [
|
|
30
|
+
[],
|
|
31
|
+
head
|
|
32
|
+
];
|
|
25
33
|
} else {
|
|
26
34
|
const latest = args[args.length - 1];
|
|
27
35
|
if (typeof latest === "object") {
|
|
28
|
-
return [
|
|
36
|
+
return [
|
|
37
|
+
args.slice(0, args.length - 1),
|
|
38
|
+
latest
|
|
39
|
+
];
|
|
29
40
|
} else {
|
|
30
|
-
return [
|
|
41
|
+
return [
|
|
42
|
+
args,
|
|
43
|
+
{}
|
|
44
|
+
];
|
|
31
45
|
}
|
|
32
46
|
}
|
|
33
47
|
};
|
|
34
|
-
|
|
48
|
+
export default (mockApiInfosByFile) => {
|
|
35
49
|
const files = Object.keys(mockApiInfosByFile);
|
|
36
50
|
files.forEach((mockedFile) => {
|
|
37
51
|
jest.mock(mockedFile, () => {
|
|
38
52
|
const supertest = require("supertest");
|
|
39
|
-
return mockApiInfosByFile[mockedFile].reduce(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
test = test.send(payload.data);
|
|
63
|
-
}
|
|
64
|
-
if (payload.headers) {
|
|
65
|
-
for (const name in payload.headers) {
|
|
66
|
-
test = test.set(name, payload.headers[name]);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (payload.cookies) {
|
|
70
|
-
test = test.set("Cookie", [payload.cookies]);
|
|
71
|
-
}
|
|
72
|
-
if (returnHttp) {
|
|
73
|
-
return test;
|
|
53
|
+
return mockApiInfosByFile[mockedFile].reduce((res, info) => {
|
|
54
|
+
const module = {
|
|
55
|
+
[info.name]: (...args) => {
|
|
56
|
+
if (mockAppModule.isInHandler()) {
|
|
57
|
+
return info.handler(...args);
|
|
58
|
+
}
|
|
59
|
+
const [params, payload] = mock_getParamsAndPayload(args);
|
|
60
|
+
const { returnHttp } = module[info.name];
|
|
61
|
+
const url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
|
|
62
|
+
const app = mockAppModule.getApp();
|
|
63
|
+
let test = supertest(app)[info.httpMethod.toLowerCase()](url);
|
|
64
|
+
if (payload.query) {
|
|
65
|
+
test = test.query(payload.query);
|
|
66
|
+
}
|
|
67
|
+
if (payload.body) {
|
|
68
|
+
test = test.send(payload.body);
|
|
69
|
+
}
|
|
70
|
+
if (payload.data) {
|
|
71
|
+
test = test.send(payload.data);
|
|
72
|
+
}
|
|
73
|
+
if (payload.headers) {
|
|
74
|
+
for (const name in payload.headers) {
|
|
75
|
+
test = test.set(name, payload.headers[name]);
|
|
74
76
|
}
|
|
75
|
-
return test.then((value) => {
|
|
76
|
-
try {
|
|
77
|
-
return JSON.parse(value.text);
|
|
78
|
-
} catch {
|
|
79
|
-
return value.text;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
77
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
if (payload.cookies) {
|
|
79
|
+
test = test.set("Cookie", [
|
|
80
|
+
payload.cookies
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
if (returnHttp) {
|
|
84
|
+
return test;
|
|
85
|
+
}
|
|
86
|
+
return test.then((value) => {
|
|
87
|
+
try {
|
|
88
|
+
return JSON.parse(value.text);
|
|
89
|
+
} catch {
|
|
90
|
+
return value.text;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
res[info.name] = module[info.name];
|
|
96
|
+
Object.assign(res[info.name], info.handler);
|
|
97
|
+
res.__esModule = true;
|
|
98
|
+
return res;
|
|
99
|
+
}, {});
|
|
91
100
|
});
|
|
92
101
|
});
|
|
93
102
|
};
|
|
94
|
-
export {
|
|
95
|
-
mockAPI_default as default
|
|
96
|
-
};
|
|
@@ -5,39 +5,31 @@ import mockAPI from "./mockAPI";
|
|
|
5
5
|
import { createApp, closeServer } from "./app";
|
|
6
6
|
let uped = false;
|
|
7
7
|
const setup = () => {
|
|
8
|
-
var
|
|
8
|
+
var _bff_info_modernUserConfig, _bff_info_modernUserConfig_bff, _bff_info_modernUserConfig1, _bff_info_modernUserConfig_bff1;
|
|
9
9
|
if (uped) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
uped = true;
|
|
13
13
|
const bff_info = global[bff_info_key];
|
|
14
|
-
const prefix =
|
|
15
|
-
const httpMethodDecider =
|
|
14
|
+
const prefix = bff_info === null || bff_info === void 0 ? void 0 : (_bff_info_modernUserConfig = bff_info.modernUserConfig) === null || _bff_info_modernUserConfig === void 0 ? void 0 : (_bff_info_modernUserConfig_bff = _bff_info_modernUserConfig.bff) === null || _bff_info_modernUserConfig_bff === void 0 ? void 0 : _bff_info_modernUserConfig_bff.prefix;
|
|
15
|
+
const httpMethodDecider = bff_info === null || bff_info === void 0 ? void 0 : (_bff_info_modernUserConfig1 = bff_info.modernUserConfig) === null || _bff_info_modernUserConfig1 === void 0 ? void 0 : (_bff_info_modernUserConfig_bff1 = _bff_info_modernUserConfig1.bff) === null || _bff_info_modernUserConfig_bff1 === void 0 ? void 0 : _bff_info_modernUserConfig_bff1.httpMethodDecider;
|
|
16
16
|
const apiRouter = new ApiRouter({
|
|
17
17
|
apiDir: path.join(bff_info.appDir, "./api"),
|
|
18
18
|
prefix,
|
|
19
19
|
httpMethodDecider
|
|
20
20
|
});
|
|
21
21
|
const apiInfos = apiRouter.getApiHandlers();
|
|
22
|
-
const apiInfosByFile = apiInfos.reduce(
|
|
23
|
-
(res
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
{}
|
|
31
|
-
);
|
|
22
|
+
const apiInfosByFile = apiInfos.reduce((res, apiInfo) => {
|
|
23
|
+
if (!res[apiInfo.filename]) {
|
|
24
|
+
res[apiInfo.filename] = [];
|
|
25
|
+
}
|
|
26
|
+
res[apiInfo.filename].push(apiInfo);
|
|
27
|
+
return res;
|
|
28
|
+
}, {});
|
|
32
29
|
let app = null;
|
|
33
30
|
beforeAll(async () => {
|
|
34
31
|
if (!app) {
|
|
35
|
-
app = await createApp(
|
|
36
|
-
bff_info.appDir,
|
|
37
|
-
bff_info.modernUserConfig,
|
|
38
|
-
bff_info.plugins,
|
|
39
|
-
bff_info.routes
|
|
40
|
-
);
|
|
32
|
+
app = await createApp(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes);
|
|
41
33
|
}
|
|
42
34
|
});
|
|
43
35
|
afterAll(async () => {
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { chalk } from "@modern-js/utils";
|
|
3
|
-
const isBFFProject = (pwd) => {
|
|
3
|
+
export const isBFFProject = (pwd) => {
|
|
4
4
|
try {
|
|
5
5
|
const packageJson = require(path.join(pwd, "./package.json"));
|
|
6
6
|
const { dependencies, devDependencies } = packageJson;
|
|
7
|
-
const isBFF = Object.keys({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
);
|
|
7
|
+
const isBFF = Object.keys({
|
|
8
|
+
...dependencies,
|
|
9
|
+
...devDependencies
|
|
10
|
+
}).some((dependency) => dependency.includes("plugin-bff"));
|
|
11
|
+
const isMWA = Object.keys(devDependencies).some((devDependency) => devDependency.includes("app-tools"));
|
|
13
12
|
return isMWA && isBFF;
|
|
14
13
|
} catch (error) {
|
|
15
14
|
console.log(chalk.red(error));
|
|
16
15
|
return false;
|
|
17
16
|
}
|
|
18
17
|
};
|
|
19
|
-
export {
|
|
20
|
-
isBFFProject
|
|
21
|
-
};
|
|
@@ -1,30 +1,25 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
mergeAlias,
|
|
5
|
-
PLUGIN_SCHEMAS,
|
|
6
|
-
createRuntimeExportsUtils
|
|
7
|
-
} from "@modern-js/utils";
|
|
8
|
-
import {
|
|
9
|
-
testingHooks,
|
|
10
|
-
getModuleNameMapper,
|
|
11
|
-
DEFAULT_RESOLVER_PATH
|
|
12
|
-
} from "../base";
|
|
2
|
+
import { isApiOnly, mergeAlias, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from "@modern-js/utils";
|
|
3
|
+
import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../base";
|
|
13
4
|
import { MODERNJS_CONFIG_KEY } from "../constant";
|
|
14
5
|
import testingBffPlugin from "./bff";
|
|
15
6
|
import test from "./test";
|
|
16
|
-
const mergeUserJestConfig = (testUtils) => {
|
|
7
|
+
export const mergeUserJestConfig = (testUtils) => {
|
|
17
8
|
const resolveJestConfig = testUtils.testConfig.jest;
|
|
18
9
|
if (resolveJestConfig && typeof resolveJestConfig !== "function") {
|
|
19
10
|
testUtils.mergeJestConfig(resolveJestConfig);
|
|
20
11
|
}
|
|
21
12
|
};
|
|
22
|
-
|
|
13
|
+
export default () => {
|
|
23
14
|
const bffPlugin = testingBffPlugin();
|
|
24
15
|
return {
|
|
25
16
|
name: "@modern-js/plugin-testing",
|
|
26
|
-
usePlugins: [
|
|
27
|
-
|
|
17
|
+
usePlugins: [
|
|
18
|
+
bffPlugin
|
|
19
|
+
],
|
|
20
|
+
post: [
|
|
21
|
+
bffPlugin.name
|
|
22
|
+
],
|
|
28
23
|
registerHook: testingHooks,
|
|
29
24
|
setup: (api) => {
|
|
30
25
|
let testingExportsUtils;
|
|
@@ -39,10 +34,7 @@ var cli_default = () => {
|
|
|
39
34
|
},
|
|
40
35
|
config() {
|
|
41
36
|
const appContext = api.useAppContext();
|
|
42
|
-
testingExportsUtils = createRuntimeExportsUtils(
|
|
43
|
-
appContext.internalDirectory,
|
|
44
|
-
"testing"
|
|
45
|
-
);
|
|
37
|
+
testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "testing");
|
|
46
38
|
return {
|
|
47
39
|
source: {
|
|
48
40
|
alias: {
|
|
@@ -92,7 +84,3 @@ var cli_default = () => {
|
|
|
92
84
|
}
|
|
93
85
|
};
|
|
94
86
|
};
|
|
95
|
-
export {
|
|
96
|
-
cli_default as default,
|
|
97
|
-
mergeUserJestConfig
|
|
98
|
-
};
|
|
@@ -2,40 +2,31 @@ import path from "path";
|
|
|
2
2
|
import { compiler } from "@modern-js/babel-compiler";
|
|
3
3
|
import { runTest } from "../base";
|
|
4
4
|
const test = async (api) => {
|
|
5
|
-
var
|
|
5
|
+
var _userConfig_tools, _userConfig_tools1;
|
|
6
6
|
const userConfig = api.useResolvedConfigContext();
|
|
7
7
|
const appContext = api.useAppContext();
|
|
8
8
|
userConfig.testing = userConfig.testing || {};
|
|
9
|
-
const jest = userConfig.testing.jest || (
|
|
9
|
+
const jest = userConfig.testing.jest || (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_tools = userConfig.tools) === null || _userConfig_tools === void 0 ? void 0 : _userConfig_tools.jest);
|
|
10
10
|
if (Array.isArray(jest)) {
|
|
11
11
|
userConfig.testing.jest = jest[0];
|
|
12
12
|
}
|
|
13
|
-
userConfig.testing.jest = userConfig.testing.jest || (
|
|
14
|
-
const runtimeExportsPath = path.join(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
[
|
|
28
|
-
require.resolve("@babel/preset-env"),
|
|
29
|
-
{
|
|
30
|
-
modules: "cjs"
|
|
31
|
-
}
|
|
32
|
-
]
|
|
13
|
+
userConfig.testing.jest = userConfig.testing.jest || (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_tools1 = userConfig.tools) === null || _userConfig_tools1 === void 0 ? void 0 : _userConfig_tools1.jest);
|
|
14
|
+
const runtimeExportsPath = path.join(appContext.internalDirectory, ".runtime-exports");
|
|
15
|
+
await compiler({
|
|
16
|
+
sourceDir: runtimeExportsPath,
|
|
17
|
+
rootDir: runtimeExportsPath,
|
|
18
|
+
distDir: runtimeExportsPath,
|
|
19
|
+
quiet: true
|
|
20
|
+
}, {
|
|
21
|
+
presets: [
|
|
22
|
+
[
|
|
23
|
+
require.resolve("@babel/preset-env"),
|
|
24
|
+
{
|
|
25
|
+
modules: "cjs"
|
|
26
|
+
}
|
|
33
27
|
]
|
|
34
|
-
|
|
35
|
-
);
|
|
28
|
+
]
|
|
29
|
+
});
|
|
36
30
|
await runTest(api, userConfig.testing);
|
|
37
31
|
};
|
|
38
|
-
|
|
39
|
-
export {
|
|
40
|
-
test_default as default
|
|
41
|
-
};
|
|
32
|
+
export default test;
|
|
@@ -1,21 +1,32 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
1
14
|
import { createApp } from "@modern-js/runtime";
|
|
2
15
|
import { MODERNJS_CONFIG_KEY } from "../constant";
|
|
3
16
|
import resolvePlugins from "./resolvePlugins";
|
|
4
17
|
class ModernRuntime {
|
|
5
|
-
constructor(options) {
|
|
6
|
-
this.options = options;
|
|
7
|
-
}
|
|
8
18
|
init(options) {
|
|
9
19
|
this.options = options;
|
|
10
20
|
}
|
|
11
21
|
createApp(props) {
|
|
12
|
-
var
|
|
22
|
+
var _this_options;
|
|
13
23
|
const { entry, children } = props || {};
|
|
14
|
-
let runtimeFeatures = (
|
|
24
|
+
let runtimeFeatures = (_this_options = this.options) === null || _this_options === void 0 ? void 0 : _this_options.runtime;
|
|
15
25
|
if (entry) {
|
|
26
|
+
var _this_options_runtimeByEntries;
|
|
16
27
|
runtimeFeatures = {
|
|
17
28
|
...runtimeFeatures || {},
|
|
18
|
-
...(
|
|
29
|
+
...(_this_options_runtimeByEntries = this.options.runtimeByEntries) === null || _this_options_runtimeByEntries === void 0 ? void 0 : _this_options_runtimeByEntries[entry]
|
|
19
30
|
};
|
|
20
31
|
}
|
|
21
32
|
const Component = () => {
|
|
@@ -28,8 +39,9 @@ class ModernRuntime {
|
|
|
28
39
|
plugins: resolvePlugins(runtimeFeatures || {})
|
|
29
40
|
})(Component);
|
|
30
41
|
}
|
|
42
|
+
constructor(options) {
|
|
43
|
+
_define_property(this, "options", void 0);
|
|
44
|
+
this.options = options;
|
|
45
|
+
}
|
|
31
46
|
}
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
app_default as default
|
|
35
|
-
};
|
|
47
|
+
export default new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
export { default as renderApp } from "./customRender";
|
|
2
2
|
export * from "@testing-library/react";
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
default2 as renderApp,
|
|
6
|
-
request as testBff
|
|
7
|
-
};
|
|
3
|
+
export { request as testBff } from "./request";
|
|
@@ -2,8 +2,8 @@ import React from "react";
|
|
|
2
2
|
import { render } from "@testing-library/react";
|
|
3
3
|
import app from "./app";
|
|
4
4
|
const WrapModernProviders = (props) => React.createElement(app.createApp(props));
|
|
5
|
-
const customRender = (ui, options) => render(ui, {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const customRender = (ui, options) => render(ui, {
|
|
6
|
+
wrapper: WrapModernProviders,
|
|
7
|
+
...options
|
|
8
|
+
});
|
|
9
|
+
export default customRender;
|