@modern-js/plugin-testing 2.15.0 → 2.16.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +20 -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,47 +1,65 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
for (var name in all)
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
-
};
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
-
for (let key of __getOwnPropNames(from))
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
-
}
|
17
|
-
return to;
|
18
|
-
};
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
-
mod
|
26
|
-
));
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
-
var mockAPI_exports = {};
|
29
|
-
__export(mockAPI_exports, {
|
30
|
-
default: () => mockAPI_default
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "default", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => _default
|
31
8
|
});
|
32
|
-
|
33
|
-
|
34
|
-
|
9
|
+
const _pathtoregexp = /* @__PURE__ */ _interop_require_wildcard(require("path-to-regexp"));
|
10
|
+
const _app = /* @__PURE__ */ _interop_require_wildcard(require("./app"));
|
11
|
+
function _getRequireWildcardCache(nodeInterop) {
|
12
|
+
if (typeof WeakMap !== "function")
|
13
|
+
return null;
|
14
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
15
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
16
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
17
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
18
|
+
})(nodeInterop);
|
19
|
+
}
|
20
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
21
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
22
|
+
return obj;
|
23
|
+
}
|
24
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
25
|
+
return {
|
26
|
+
default: obj
|
27
|
+
};
|
28
|
+
}
|
29
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
30
|
+
if (cache && cache.has(obj)) {
|
31
|
+
return cache.get(obj);
|
32
|
+
}
|
33
|
+
var newObj = {};
|
34
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
35
|
+
for (var key in obj) {
|
36
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
37
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
38
|
+
if (desc && (desc.get || desc.set)) {
|
39
|
+
Object.defineProperty(newObj, key, desc);
|
40
|
+
} else {
|
41
|
+
newObj[key] = obj[key];
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
newObj.default = obj;
|
46
|
+
if (cache) {
|
47
|
+
cache.set(obj, newObj);
|
48
|
+
}
|
49
|
+
return newObj;
|
50
|
+
}
|
35
51
|
const mock_replaceUrlWithParams = (url, paramValues, payload) => {
|
36
52
|
const keys = [];
|
37
|
-
|
53
|
+
_pathtoregexp.pathToRegexp(url, keys);
|
38
54
|
const params = keys.reduce((cur, key, index) => {
|
39
55
|
if (paramValues[index]) {
|
40
56
|
cur[key.name] = paramValues[index];
|
41
57
|
}
|
42
58
|
return cur;
|
43
59
|
}, {});
|
44
|
-
const getFinalPath =
|
60
|
+
const getFinalPath = _pathtoregexp.compile(url, {
|
61
|
+
encode: encodeURIComponent
|
62
|
+
});
|
45
63
|
return getFinalPath({
|
46
64
|
...params,
|
47
65
|
...payload
|
@@ -49,79 +67,84 @@ const mock_replaceUrlWithParams = (url, paramValues, payload) => {
|
|
49
67
|
};
|
50
68
|
const mock_getParamsAndPayload = (args) => {
|
51
69
|
if (args.length === 0) {
|
52
|
-
return [
|
70
|
+
return [
|
71
|
+
[],
|
72
|
+
{}
|
73
|
+
];
|
53
74
|
}
|
54
75
|
const head = args[0];
|
55
76
|
if (typeof head === "object") {
|
56
|
-
return [
|
77
|
+
return [
|
78
|
+
[],
|
79
|
+
head
|
80
|
+
];
|
57
81
|
} else {
|
58
82
|
const latest = args[args.length - 1];
|
59
83
|
if (typeof latest === "object") {
|
60
|
-
return [
|
84
|
+
return [
|
85
|
+
args.slice(0, args.length - 1),
|
86
|
+
latest
|
87
|
+
];
|
61
88
|
} else {
|
62
|
-
return [
|
89
|
+
return [
|
90
|
+
args,
|
91
|
+
{}
|
92
|
+
];
|
63
93
|
}
|
64
94
|
}
|
65
95
|
};
|
66
|
-
|
96
|
+
const _default = (mockApiInfosByFile) => {
|
67
97
|
const files = Object.keys(mockApiInfosByFile);
|
68
98
|
files.forEach((mockedFile) => {
|
69
99
|
jest.mock(mockedFile, () => {
|
70
100
|
const supertest = require("supertest");
|
71
|
-
return mockApiInfosByFile[mockedFile].reduce(
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
test = test.send(payload.data);
|
95
|
-
}
|
96
|
-
if (payload.headers) {
|
97
|
-
for (const name in payload.headers) {
|
98
|
-
test = test.set(name, payload.headers[name]);
|
99
|
-
}
|
100
|
-
}
|
101
|
-
if (payload.cookies) {
|
102
|
-
test = test.set("Cookie", [payload.cookies]);
|
103
|
-
}
|
104
|
-
if (returnHttp) {
|
105
|
-
return test;
|
101
|
+
return mockApiInfosByFile[mockedFile].reduce((res, info) => {
|
102
|
+
const module = {
|
103
|
+
[info.name]: (...args) => {
|
104
|
+
if (_app.isInHandler()) {
|
105
|
+
return info.handler(...args);
|
106
|
+
}
|
107
|
+
const [params, payload] = mock_getParamsAndPayload(args);
|
108
|
+
const { returnHttp } = module[info.name];
|
109
|
+
const url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
|
110
|
+
const app = _app.getApp();
|
111
|
+
let test = supertest(app)[info.httpMethod.toLowerCase()](url);
|
112
|
+
if (payload.query) {
|
113
|
+
test = test.query(payload.query);
|
114
|
+
}
|
115
|
+
if (payload.body) {
|
116
|
+
test = test.send(payload.body);
|
117
|
+
}
|
118
|
+
if (payload.data) {
|
119
|
+
test = test.send(payload.data);
|
120
|
+
}
|
121
|
+
if (payload.headers) {
|
122
|
+
for (const name in payload.headers) {
|
123
|
+
test = test.set(name, payload.headers[name]);
|
106
124
|
}
|
107
|
-
return test.then((value) => {
|
108
|
-
try {
|
109
|
-
return JSON.parse(value.text);
|
110
|
-
} catch {
|
111
|
-
return value.text;
|
112
|
-
}
|
113
|
-
});
|
114
125
|
}
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
126
|
+
if (payload.cookies) {
|
127
|
+
test = test.set("Cookie", [
|
128
|
+
payload.cookies
|
129
|
+
]);
|
130
|
+
}
|
131
|
+
if (returnHttp) {
|
132
|
+
return test;
|
133
|
+
}
|
134
|
+
return test.then((value) => {
|
135
|
+
try {
|
136
|
+
return JSON.parse(value.text);
|
137
|
+
} catch {
|
138
|
+
return value.text;
|
139
|
+
}
|
140
|
+
});
|
141
|
+
}
|
142
|
+
};
|
143
|
+
res[info.name] = module[info.name];
|
144
|
+
Object.assign(res[info.name], info.handler);
|
145
|
+
res.__esModule = true;
|
146
|
+
return res;
|
147
|
+
}, {});
|
123
148
|
});
|
124
149
|
});
|
125
150
|
};
|
126
|
-
// Annotate the CommonJS export names for ESM import in node:
|
127
|
-
0 && (module.exports = {});
|
@@ -1,70 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
21
|
-
mod
|
22
|
-
));
|
23
|
-
var import_path = __toESM(require("path"));
|
24
|
-
var import_bff_core = require("@modern-js/bff-core");
|
25
|
-
var import_constant = require("./constant");
|
26
|
-
var import_mockAPI = __toESM(require("./mockAPI"));
|
27
|
-
var import_app = require("./app");
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
6
|
+
const _bffcore = require("@modern-js/bff-core");
|
7
|
+
const _constant = require("./constant");
|
8
|
+
const _mockAPI = /* @__PURE__ */ _interop_require_default(require("./mockAPI"));
|
9
|
+
const _app = require("./app");
|
10
|
+
function _interop_require_default(obj) {
|
11
|
+
return obj && obj.__esModule ? obj : {
|
12
|
+
default: obj
|
13
|
+
};
|
14
|
+
}
|
28
15
|
let uped = false;
|
29
16
|
const setup = () => {
|
30
|
-
var
|
17
|
+
var _bff_info_modernUserConfig, _bff_info_modernUserConfig_bff, _bff_info_modernUserConfig1, _bff_info_modernUserConfig_bff1;
|
31
18
|
if (uped) {
|
32
19
|
return;
|
33
20
|
}
|
34
21
|
uped = true;
|
35
|
-
const bff_info = global[
|
36
|
-
const prefix =
|
37
|
-
const httpMethodDecider =
|
38
|
-
const apiRouter = new
|
39
|
-
apiDir:
|
22
|
+
const bff_info = global[_constant.bff_info_key];
|
23
|
+
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;
|
24
|
+
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;
|
25
|
+
const apiRouter = new _bffcore.ApiRouter({
|
26
|
+
apiDir: _path.default.join(bff_info.appDir, "./api"),
|
40
27
|
prefix,
|
41
28
|
httpMethodDecider
|
42
29
|
});
|
43
30
|
const apiInfos = apiRouter.getApiHandlers();
|
44
|
-
const apiInfosByFile = apiInfos.reduce(
|
45
|
-
(res
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
},
|
52
|
-
{}
|
53
|
-
);
|
31
|
+
const apiInfosByFile = apiInfos.reduce((res, apiInfo) => {
|
32
|
+
if (!res[apiInfo.filename]) {
|
33
|
+
res[apiInfo.filename] = [];
|
34
|
+
}
|
35
|
+
res[apiInfo.filename].push(apiInfo);
|
36
|
+
return res;
|
37
|
+
}, {});
|
54
38
|
let app = null;
|
55
39
|
beforeAll(async () => {
|
56
40
|
if (!app) {
|
57
|
-
app = await (0,
|
58
|
-
bff_info.appDir,
|
59
|
-
bff_info.modernUserConfig,
|
60
|
-
bff_info.plugins,
|
61
|
-
bff_info.routes
|
62
|
-
);
|
41
|
+
app = await (0, _app.createApp)(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes);
|
63
42
|
}
|
64
43
|
});
|
65
44
|
afterAll(async () => {
|
66
|
-
await (0,
|
45
|
+
await (0, _app.closeServer)();
|
67
46
|
});
|
68
|
-
(0,
|
47
|
+
(0, _mockAPI.default)(apiInfosByFile);
|
69
48
|
};
|
70
49
|
setup();
|
@@ -1,54 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
-
var __export = (target, all) => {
|
8
|
-
for (var name in all)
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
-
};
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
-
for (let key of __getOwnPropNames(from))
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
-
}
|
17
|
-
return to;
|
18
|
-
};
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
-
mod
|
26
|
-
));
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
-
var utils_exports = {};
|
29
|
-
__export(utils_exports, {
|
30
|
-
isBFFProject: () => isBFFProject
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
31
4
|
});
|
32
|
-
|
33
|
-
|
34
|
-
|
5
|
+
Object.defineProperty(exports, "isBFFProject", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => isBFFProject
|
8
|
+
});
|
9
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
10
|
+
const _utils = require("@modern-js/utils");
|
11
|
+
function _interop_require_default(obj) {
|
12
|
+
return obj && obj.__esModule ? obj : {
|
13
|
+
default: obj
|
14
|
+
};
|
15
|
+
}
|
35
16
|
const isBFFProject = (pwd) => {
|
36
17
|
try {
|
37
|
-
const packageJson = require(
|
18
|
+
const packageJson = require(_path.default.join(pwd, "./package.json"));
|
38
19
|
const { dependencies, devDependencies } = packageJson;
|
39
|
-
const isBFF = Object.keys({
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
);
|
20
|
+
const isBFF = Object.keys({
|
21
|
+
...dependencies,
|
22
|
+
...devDependencies
|
23
|
+
}).some((dependency) => dependency.includes("plugin-bff"));
|
24
|
+
const isMWA = Object.keys(devDependencies).some((devDependency) => devDependency.includes("app-tools"));
|
45
25
|
return isMWA && isBFF;
|
46
26
|
} catch (error) {
|
47
|
-
console.log(
|
27
|
+
console.log(_utils.chalk.red(error));
|
48
28
|
return false;
|
49
29
|
}
|
50
30
|
};
|
51
|
-
// Annotate the CommonJS export names for ESM import in node:
|
52
|
-
0 && (module.exports = {
|
53
|
-
isBFFProject
|
54
|
-
});
|
package/dist/cjs/cli/index.js
CHANGED
@@ -1,95 +1,83 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
-
var __export = (target, all) => {
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
8
6
|
for (var name in all)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
return to;
|
18
|
-
};
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
-
mod
|
26
|
-
));
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
-
var cli_exports = {};
|
29
|
-
__export(cli_exports, {
|
30
|
-
default: () => cli_default,
|
31
|
-
mergeUserJestConfig: () => mergeUserJestConfig
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
mergeUserJestConfig: () => mergeUserJestConfig,
|
14
|
+
default: () => _default
|
32
15
|
});
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
16
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
17
|
+
const _utils = require("@modern-js/utils");
|
18
|
+
const _base = require("../base");
|
19
|
+
const _constant = require("../constant");
|
20
|
+
const _bff = /* @__PURE__ */ _interop_require_default(require("./bff"));
|
21
|
+
const _test = /* @__PURE__ */ _interop_require_default(require("./test"));
|
22
|
+
function _interop_require_default(obj) {
|
23
|
+
return obj && obj.__esModule ? obj : {
|
24
|
+
default: obj
|
25
|
+
};
|
26
|
+
}
|
40
27
|
const mergeUserJestConfig = (testUtils) => {
|
41
28
|
const resolveJestConfig = testUtils.testConfig.jest;
|
42
29
|
if (resolveJestConfig && typeof resolveJestConfig !== "function") {
|
43
30
|
testUtils.mergeJestConfig(resolveJestConfig);
|
44
31
|
}
|
45
32
|
};
|
46
|
-
|
47
|
-
const bffPlugin = (0,
|
33
|
+
const _default = () => {
|
34
|
+
const bffPlugin = (0, _bff.default)();
|
48
35
|
return {
|
49
36
|
name: "@modern-js/plugin-testing",
|
50
|
-
usePlugins: [
|
51
|
-
|
52
|
-
|
37
|
+
usePlugins: [
|
38
|
+
bffPlugin
|
39
|
+
],
|
40
|
+
post: [
|
41
|
+
bffPlugin.name
|
42
|
+
],
|
43
|
+
registerHook: _base.testingHooks,
|
53
44
|
setup: (api) => {
|
54
45
|
let testingExportsUtils;
|
55
46
|
return {
|
56
47
|
commands: ({ program }) => {
|
57
48
|
program.command("test").allowUnknownOption().usage("<regexForTestFiles> --[options]").action(async () => {
|
58
|
-
await (0,
|
49
|
+
await (0, _test.default)(api);
|
59
50
|
});
|
60
51
|
},
|
61
52
|
validateSchema() {
|
62
|
-
return
|
53
|
+
return _utils.PLUGIN_SCHEMAS["@modern-js/plugin-testing"];
|
63
54
|
},
|
64
55
|
config() {
|
65
56
|
const appContext = api.useAppContext();
|
66
|
-
testingExportsUtils = (0,
|
67
|
-
appContext.internalDirectory,
|
68
|
-
"testing"
|
69
|
-
);
|
57
|
+
testingExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, "testing");
|
70
58
|
return {
|
71
59
|
source: {
|
72
60
|
alias: {
|
73
61
|
// The module-tools alias configuration is different and more specific than app-tools.
|
74
62
|
// So for the time being, the @ alias is configured here.
|
75
|
-
"@":
|
63
|
+
"@": _path.default.join(appContext.appDirectory, "src"),
|
76
64
|
"@modern-js/runtime/testing": testingExportsUtils.getPath()
|
77
65
|
}
|
78
66
|
}
|
79
67
|
};
|
80
68
|
},
|
81
69
|
addRuntimeExports() {
|
82
|
-
const testingPath =
|
70
|
+
const testingPath = _path.default.resolve(__dirname, "../");
|
83
71
|
testingExportsUtils.addExport(`export * from '${testingPath}'`);
|
84
72
|
},
|
85
73
|
jestConfig: async (utils, next) => {
|
86
74
|
const appContext = api.useAppContext();
|
87
75
|
const userConfig = api.useResolvedConfigContext();
|
88
|
-
const apiOnly = await (0,
|
76
|
+
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory);
|
89
77
|
if (apiOnly) {
|
90
78
|
return next(utils);
|
91
79
|
}
|
92
|
-
const alias = (0,
|
80
|
+
const alias = (0, _utils.mergeAlias)(userConfig.source.alias);
|
93
81
|
if (testingExportsUtils) {
|
94
82
|
alias["@modern-js/runtime/testing"] = [
|
95
83
|
testingExportsUtils.getPath()
|
@@ -97,11 +85,11 @@ var cli_default = () => {
|
|
97
85
|
}
|
98
86
|
utils.mergeJestConfig({
|
99
87
|
globals: {
|
100
|
-
[
|
88
|
+
[_constant.MODERNJS_CONFIG_KEY]: userConfig
|
101
89
|
},
|
102
|
-
moduleNameMapper: (0,
|
90
|
+
moduleNameMapper: (0, _base.getModuleNameMapper)(alias),
|
103
91
|
testEnvironment: "jsdom",
|
104
|
-
resolver:
|
92
|
+
resolver: _base.DEFAULT_RESOLVER_PATH,
|
105
93
|
rootDir: appContext.appDirectory || process.cwd(),
|
106
94
|
// testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
|
107
95
|
testMatch: [
|
@@ -116,7 +104,3 @@ var cli_default = () => {
|
|
116
104
|
}
|
117
105
|
};
|
118
106
|
};
|
119
|
-
// Annotate the CommonJS export names for ESM import in node:
|
120
|
-
0 && (module.exports = {
|
121
|
-
mergeUserJestConfig
|
122
|
-
});
|