@modern-js/plugin-testing 2.0.0-beta.3 → 2.0.0-beta.6
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +159 -0
- package/dist/js/modern/base/config/index.js +29 -9
- package/dist/js/modern/base/config/patches/assetsModule.js +7 -7
- package/dist/js/modern/base/config/patches/filemock.js +4 -1
- package/dist/js/modern/base/config/patches/index.js +30 -7
- package/dist/js/modern/base/config/patches/transformer.js +13 -18
- package/dist/js/modern/base/config/resolver.js +20 -11
- package/dist/js/modern/base/config/testConfigOperator.js +29 -23
- package/dist/js/modern/base/config/transformer/babelTransformer.js +16 -8
- package/dist/js/modern/base/hook.js +10 -5
- package/dist/js/modern/base/index.js +14 -6
- package/dist/js/modern/base/runJest.js +73 -62
- package/dist/js/modern/base/utils.js +40 -23
- package/dist/js/modern/cli/bff/app.js +37 -12
- package/dist/js/modern/cli/bff/constant.js +4 -1
- package/dist/js/modern/cli/bff/index.js +95 -52
- package/dist/js/modern/cli/bff/mockAPI.js +79 -64
- package/dist/js/modern/cli/bff/setup.js +71 -34
- package/dist/js/modern/cli/bff/utils/index.js +31 -15
- package/dist/js/modern/cli/index.js +65 -30
- package/dist/js/modern/cli/test.js +53 -18
- package/dist/js/modern/constant.js +4 -1
- package/dist/js/modern/index.js +3 -3
- package/dist/js/modern/modern-app.env.d.js +0 -0
- package/dist/js/modern/runtime-testing/app.js +25 -14
- package/dist/js/modern/runtime-testing/base.js +7 -3
- package/dist/js/modern/runtime-testing/customRender.js +24 -10
- package/dist/js/modern/runtime-testing/index.js +1 -1
- package/dist/js/modern/runtime-testing/reduck.js +41 -19
- package/dist/js/modern/runtime-testing/request.js +4 -4
- package/dist/js/modern/runtime-testing/resolvePlugins.js +24 -8
- package/dist/js/node/base/config/index.js +62 -18
- package/dist/js/node/base/config/patches/assetsModule.js +34 -12
- package/dist/js/node/base/config/patches/filemock.js +24 -7
- package/dist/js/node/base/config/patches/index.js +54 -15
- package/dist/js/node/base/config/patches/transformer.js +42 -25
- package/dist/js/node/base/config/resolver.js +25 -10
- package/dist/js/node/base/config/testConfigOperator.js +51 -30
- package/dist/js/node/base/config/transformer/babelTransformer.js +42 -15
- package/dist/js/node/base/hook.js +34 -13
- package/dist/js/node/base/index.js +39 -62
- package/dist/js/node/base/runJest.js +104 -71
- package/dist/js/node/base/types/index.js +15 -0
- package/dist/js/node/base/utils.js +70 -34
- package/dist/js/node/cli/bff/app.js +64 -22
- package/dist/js/node/cli/bff/constant.js +26 -7
- package/dist/js/node/cli/bff/index.js +123 -65
- package/dist/js/node/cli/bff/mockAPI.js +103 -71
- package/dist/js/node/cli/bff/setup.js +71 -28
- package/dist/js/node/cli/bff/utils/index.js +57 -22
- package/dist/js/node/cli/index.js +92 -46
- package/dist/js/node/cli/test.js +81 -27
- package/dist/js/node/constant.js +26 -7
- package/dist/js/node/index.js +19 -18
- package/dist/js/node/modern-app.env.d.js +0 -0
- package/dist/js/node/runtime-testing/app.js +53 -25
- package/dist/js/node/runtime-testing/base.js +34 -32
- package/dist/js/node/runtime-testing/customRender.js +49 -18
- package/dist/js/node/runtime-testing/index.js +18 -27
- package/dist/js/node/runtime-testing/reduck.js +72 -31
- package/dist/js/node/runtime-testing/request.js +36 -13
- package/dist/js/node/runtime-testing/resolvePlugins.js +41 -12
- package/dist/js/treeshaking/base/config/index.js +150 -31
- package/dist/js/treeshaking/base/config/patches/assetsModule.js +9 -11
- package/dist/js/treeshaking/base/config/patches/filemock.js +2 -1
- package/dist/js/treeshaking/base/config/patches/index.js +221 -64
- package/dist/js/treeshaking/base/config/patches/transformer.js +34 -37
- package/dist/js/treeshaking/base/config/resolver.js +36 -13
- package/dist/js/treeshaking/base/config/testConfigOperator.js +120 -69
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +16 -10
- package/dist/js/treeshaking/base/hook.js +8 -7
- package/dist/js/treeshaking/base/index.js +7 -6
- package/dist/js/treeshaking/base/runJest.js +281 -164
- package/dist/js/treeshaking/base/types/index.js +1 -0
- package/dist/js/treeshaking/base/utils.js +72 -48
- package/dist/js/treeshaking/cli/bff/app.js +192 -68
- package/dist/js/treeshaking/cli/bff/constant.js +2 -1
- package/dist/js/treeshaking/cli/bff/index.js +291 -130
- package/dist/js/treeshaking/cli/bff/mockAPI.js +181 -91
- package/dist/js/treeshaking/cli/bff/setup.js +185 -59
- package/dist/js/treeshaking/cli/bff/utils/index.js +47 -21
- package/dist/js/treeshaking/cli/index.js +249 -108
- package/dist/js/treeshaking/cli/test.js +177 -44
- package/dist/js/treeshaking/constant.js +2 -1
- package/dist/js/treeshaking/index.js +3 -3
- package/dist/js/treeshaking/modern-app.env.d.js +1 -0
- package/dist/js/treeshaking/runtime-testing/app.js +85 -39
- package/dist/js/treeshaking/runtime-testing/base.js +4 -3
- package/dist/js/treeshaking/runtime-testing/customRender.js +38 -10
- package/dist/js/treeshaking/runtime-testing/index.js +1 -1
- package/dist/js/treeshaking/runtime-testing/reduck.js +85 -33
- package/dist/js/treeshaking/runtime-testing/request.js +49 -19
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +45 -14
- package/dist/types/base/config/index.d.ts +1 -0
- package/dist/types/base/config/patches/assetsModule.d.ts +1 -0
- package/dist/types/base/config/patches/filemock.d.ts +1 -0
- package/dist/types/base/config/patches/transformer.d.ts +1 -0
- package/dist/types/base/config/testConfigOperator.d.ts +2 -0
- package/dist/types/base/runJest.d.ts +2 -0
- package/dist/types/base/utils.d.ts +1 -0
- package/dist/types/cli/bff/index.d.ts +2 -0
- package/dist/types/cli/bff/mockAPI.d.ts +1 -0
- package/dist/types/cli/index.d.ts +2 -0
- package/dist/types/runtime-testing/app.d.ts +3 -0
- package/dist/types/runtime-testing/customRender.d.ts +2 -0
- package/package.json +21 -25
@@ -1,50 +1,81 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Object.
|
4
|
-
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
+
var __spreadValues = (a, b) => {
|
11
|
+
for (var prop in b || (b = {}))
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
14
|
+
if (__getOwnPropSymbols)
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
16
|
+
if (__propIsEnum.call(b, prop))
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
18
|
+
}
|
19
|
+
return a;
|
20
|
+
};
|
21
|
+
var __export = (target, all) => {
|
22
|
+
for (var name in all)
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
24
|
+
};
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
27
|
+
for (let key of __getOwnPropNames(from))
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
30
|
+
}
|
31
|
+
return to;
|
32
|
+
};
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
35
|
+
mod
|
36
|
+
));
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
38
|
+
var utils_exports = {};
|
39
|
+
__export(utils_exports, {
|
40
|
+
debug: () => debug,
|
41
|
+
getModuleNameMapper: () => getModuleNameMapper,
|
42
|
+
readCompilerOptions: () => readCompilerOptions
|
5
43
|
});
|
6
|
-
|
7
|
-
var
|
8
|
-
var
|
9
|
-
var
|
10
|
-
|
11
|
-
|
12
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
13
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
14
|
-
const debug = (0, _utils.createDebugger)('test');
|
15
|
-
exports.debug = debug;
|
16
|
-
/**
|
17
|
-
* Read `compilerOptions` in the current pwd's tsconfig.json file
|
18
|
-
*/
|
19
|
-
const readCompilerOptions = (pwd = process.cwd(), filename = 'tsconfig.json') => {
|
44
|
+
module.exports = __toCommonJS(utils_exports);
|
45
|
+
var import_fs = __toESM(require("fs"));
|
46
|
+
var import_path = __toESM(require("path"));
|
47
|
+
var import_utils = require("@modern-js/utils");
|
48
|
+
const debug = (0, import_utils.createDebugger)("test");
|
49
|
+
const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") => {
|
20
50
|
let tsConfig = {};
|
21
51
|
let extendedCompilerOptions = {};
|
22
|
-
let tsconfigFile =
|
52
|
+
let tsconfigFile = "";
|
23
53
|
try {
|
24
|
-
const maybeTsconfigFile =
|
25
|
-
if (
|
54
|
+
const maybeTsconfigFile = import_path.default.join(pwd, filename);
|
55
|
+
if (import_fs.default.existsSync(maybeTsconfigFile)) {
|
26
56
|
tsconfigFile = maybeTsconfigFile;
|
27
57
|
} else {
|
28
58
|
tsconfigFile = require.resolve(filename);
|
29
59
|
}
|
30
|
-
({
|
31
|
-
|
32
|
-
|
60
|
+
({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(
|
61
|
+
tsconfigFile,
|
62
|
+
import_fs.default.readFileSync(tsconfigFile, "utf8")
|
63
|
+
));
|
33
64
|
} catch (e) {
|
34
65
|
return {};
|
35
66
|
}
|
36
67
|
if (tsConfig.extends) {
|
37
|
-
extendedCompilerOptions = readCompilerOptions(
|
68
|
+
extendedCompilerOptions = readCompilerOptions(
|
69
|
+
import_path.default.dirname(tsconfigFile),
|
70
|
+
tsConfig.extends
|
71
|
+
);
|
38
72
|
}
|
39
|
-
return
|
73
|
+
return __spreadValues(__spreadValues({}, extendedCompilerOptions), tsConfig.compilerOptions);
|
40
74
|
};
|
41
|
-
|
42
|
-
const getModuleNameMapper = alias => Object.keys(alias).reduce((memo, cur) => {
|
75
|
+
const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
|
43
76
|
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
|
44
|
-
const isFile = aliasValue.some(s => s.endsWith(
|
45
|
-
|
46
|
-
// It's special for if using @modern-js/runtime alias other module @modern-js/runtime/model would not work.
|
47
|
-
if (cur === '@modern-js/runtime$') {
|
77
|
+
const isFile = aliasValue.some((s) => s.endsWith(".js"));
|
78
|
+
if (cur === "@modern-js/runtime$") {
|
48
79
|
memo[`.+${cur}`] = aliasValue[0];
|
49
80
|
return memo;
|
50
81
|
}
|
@@ -52,8 +83,13 @@ const getModuleNameMapper = alias => Object.keys(alias).reduce((memo, cur) => {
|
|
52
83
|
memo[cur] = aliasValue[0];
|
53
84
|
}
|
54
85
|
const key = `^${cur}/(.*)$`;
|
55
|
-
const value =
|
86
|
+
const value = import_path.default.normalize(`${aliasValue}/$1`);
|
56
87
|
memo[key] = value;
|
57
88
|
return memo;
|
58
89
|
}, {});
|
59
|
-
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
91
|
+
0 && (module.exports = {
|
92
|
+
debug,
|
93
|
+
getModuleNameMapper,
|
94
|
+
readCompilerOptions
|
95
|
+
});
|
@@ -1,42 +1,84 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Object.
|
4
|
-
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __export = (target, all) => {
|
6
|
+
for (var name in all)
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
+
};
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
19
|
+
return new Promise((resolve, reject) => {
|
20
|
+
var fulfilled = (value) => {
|
21
|
+
try {
|
22
|
+
step(generator.next(value));
|
23
|
+
} catch (e) {
|
24
|
+
reject(e);
|
25
|
+
}
|
26
|
+
};
|
27
|
+
var rejected = (value) => {
|
28
|
+
try {
|
29
|
+
step(generator.throw(value));
|
30
|
+
} catch (e) {
|
31
|
+
reject(e);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
36
|
+
});
|
37
|
+
};
|
38
|
+
var app_exports = {};
|
39
|
+
__export(app_exports, {
|
40
|
+
closeServer: () => closeServer,
|
41
|
+
createApp: () => createApp,
|
42
|
+
getApp: () => getApp,
|
43
|
+
isInHandler: () => isInHandler
|
5
44
|
});
|
6
|
-
|
7
|
-
var
|
8
|
-
var
|
9
|
-
const store = new
|
45
|
+
module.exports = __toCommonJS(app_exports);
|
46
|
+
var import_async_hooks = require("async_hooks");
|
47
|
+
var import_prod_server = require("@modern-js/prod-server");
|
48
|
+
const store = new import_async_hooks.AsyncLocalStorage();
|
10
49
|
const isInHandler = () => Boolean(store.getStore());
|
11
|
-
exports.isInHandler = isInHandler;
|
12
50
|
let server = null;
|
13
|
-
const createApp =
|
51
|
+
const createApp = (pwd, config, plugins, routes) => __async(void 0, null, function* () {
|
14
52
|
if (!server) {
|
15
|
-
config.output.path =
|
16
|
-
server = new
|
53
|
+
config.output.path = "./";
|
54
|
+
server = new import_prod_server.Server({
|
17
55
|
apiOnly: true,
|
18
56
|
pwd,
|
19
57
|
config,
|
20
58
|
internalPlugins: plugins,
|
21
59
|
routes
|
22
60
|
});
|
23
|
-
|
61
|
+
yield server.init();
|
24
62
|
}
|
25
63
|
const app = server.getRequestHandler();
|
26
64
|
return app;
|
27
|
-
};
|
28
|
-
exports.createApp = createApp;
|
65
|
+
});
|
29
66
|
const getApp = () => {
|
30
67
|
if (!server) {
|
31
|
-
throw new Error(
|
68
|
+
throw new Error("please createApp first");
|
32
69
|
}
|
33
70
|
return server.getRequestHandler();
|
34
71
|
};
|
35
|
-
|
36
|
-
const closeServer = async () => {
|
72
|
+
const closeServer = () => __async(void 0, null, function* () {
|
37
73
|
if (!server) {
|
38
|
-
throw new Error(
|
74
|
+
throw new Error("please createApp first");
|
39
75
|
}
|
40
|
-
|
41
|
-
};
|
42
|
-
|
76
|
+
yield server.close();
|
77
|
+
});
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
79
|
+
0 && (module.exports = {
|
80
|
+
closeServer,
|
81
|
+
createApp,
|
82
|
+
getApp,
|
83
|
+
isInHandler
|
84
|
+
});
|
@@ -1,8 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Object.
|
4
|
-
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __export = (target, all) => {
|
6
|
+
for (var name in all)
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
+
};
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
+
var constant_exports = {};
|
19
|
+
__export(constant_exports, {
|
20
|
+
bff_info_key: () => bff_info_key
|
21
|
+
});
|
22
|
+
module.exports = __toCommonJS(constant_exports);
|
23
|
+
const bff_info_key = "modern_bff_info";
|
24
|
+
// Annotate the CommonJS export names for ESM import in node:
|
25
|
+
0 && (module.exports = {
|
26
|
+
bff_info_key
|
5
27
|
});
|
6
|
-
exports.bff_info_key = void 0;
|
7
|
-
const bff_info_key = 'modern_bff_info';
|
8
|
-
exports.bff_info_key = bff_info_key;
|
@@ -1,38 +1,91 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Object.
|
4
|
-
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
+
var __spreadValues = (a, b) => {
|
11
|
+
for (var prop in b || (b = {}))
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
14
|
+
if (__getOwnPropSymbols)
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
16
|
+
if (__propIsEnum.call(b, prop))
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
18
|
+
}
|
19
|
+
return a;
|
20
|
+
};
|
21
|
+
var __export = (target, all) => {
|
22
|
+
for (var name in all)
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
24
|
+
};
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
27
|
+
for (let key of __getOwnPropNames(from))
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
30
|
+
}
|
31
|
+
return to;
|
32
|
+
};
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
35
|
+
mod
|
36
|
+
));
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
38
|
+
var __async = (__this, __arguments, generator) => {
|
39
|
+
return new Promise((resolve, reject) => {
|
40
|
+
var fulfilled = (value) => {
|
41
|
+
try {
|
42
|
+
step(generator.next(value));
|
43
|
+
} catch (e) {
|
44
|
+
reject(e);
|
45
|
+
}
|
46
|
+
};
|
47
|
+
var rejected = (value) => {
|
48
|
+
try {
|
49
|
+
step(generator.throw(value));
|
50
|
+
} catch (e) {
|
51
|
+
reject(e);
|
52
|
+
}
|
53
|
+
};
|
54
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
55
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
56
|
+
});
|
57
|
+
};
|
58
|
+
var bff_exports = {};
|
59
|
+
__export(bff_exports, {
|
60
|
+
default: () => bff_default,
|
61
|
+
setJestConfigForBFF: () => setJestConfigForBFF
|
5
62
|
});
|
6
|
-
|
7
|
-
var
|
8
|
-
var
|
9
|
-
var
|
10
|
-
var
|
11
|
-
var
|
12
|
-
|
13
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
15
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
16
|
-
const setJestConfigForBFF = async ({
|
63
|
+
module.exports = __toCommonJS(bff_exports);
|
64
|
+
var import_path = __toESM(require("path"));
|
65
|
+
var import_utils = require("@modern-js/utils");
|
66
|
+
var import_base = require("../../base");
|
67
|
+
var import_constant = require("./constant");
|
68
|
+
var import_utils2 = require("./utils");
|
69
|
+
const setJestConfigForBFF = (_0) => __async(void 0, [_0], function* ({
|
17
70
|
pwd,
|
18
71
|
userConfig,
|
19
72
|
plugins,
|
20
73
|
routes,
|
21
74
|
utils
|
22
|
-
})
|
23
|
-
var
|
75
|
+
}) {
|
76
|
+
var _a;
|
24
77
|
const bffConfig = {
|
25
|
-
rootDir:
|
78
|
+
rootDir: import_path.default.join(pwd, "./api"),
|
26
79
|
setupFilesAfterEnv: [require.resolve("./setup")],
|
27
|
-
testEnvironment:
|
80
|
+
testEnvironment: "node",
|
28
81
|
testMatch: [`**/api/**/*.test.[jt]s`],
|
29
82
|
globals: {
|
30
|
-
|
83
|
+
"ts-jest": {
|
31
84
|
diagnostics: {
|
32
85
|
warnOnly: true
|
33
86
|
}
|
34
87
|
},
|
35
|
-
[
|
88
|
+
[import_constant.bff_info_key]: {
|
36
89
|
appDir: pwd,
|
37
90
|
modernUserConfig: userConfig,
|
38
91
|
plugins,
|
@@ -40,25 +93,17 @@ const setJestConfigForBFF = async ({
|
|
40
93
|
}
|
41
94
|
}
|
42
95
|
};
|
43
|
-
const {
|
44
|
-
|
45
|
-
|
46
|
-
const
|
47
|
-
const aliasMapper = (0, _base.getModuleNameMapper)(alias);
|
48
|
-
const {
|
49
|
-
moduleNameMapper
|
50
|
-
} = jestConfig;
|
51
|
-
|
52
|
-
// 服务端统一使用 ts-jest
|
96
|
+
const { jestConfig } = utils;
|
97
|
+
const alias = ((_a = userConfig == null ? void 0 : userConfig.source) == null ? void 0 : _a.alias) || {};
|
98
|
+
const aliasMapper = (0, import_base.getModuleNameMapper)(alias);
|
99
|
+
const { moduleNameMapper } = jestConfig;
|
53
100
|
const transform = {
|
54
|
-
|
101
|
+
"\\.[jt]sx?$": require.resolve("ts-jest")
|
55
102
|
};
|
56
|
-
const apiOnly =
|
57
|
-
const mergedModuleNameMapper =
|
58
|
-
const resolver = jestConfig.resolver ||
|
59
|
-
|
60
|
-
// 这三个配置不能设置在 projects 中,需要设置在外层(https://github.com/facebook/jest/issues/9696)
|
61
|
-
const configFields = ['coverage', 'collectCoverage', 'testTimeout'];
|
103
|
+
const apiOnly = yield (0, import_utils.isApiOnly)(pwd);
|
104
|
+
const mergedModuleNameMapper = __spreadValues(__spreadValues({}, moduleNameMapper), aliasMapper);
|
105
|
+
const resolver = jestConfig.resolver || import_base.DEFAULT_RESOLVER_PATH;
|
106
|
+
const configFields = ["coverage", "collectCoverage", "testTimeout"];
|
62
107
|
const commonConfig = configFields.reduce((obj, field) => {
|
63
108
|
if (jestConfig.hasOwnProperty(field)) {
|
64
109
|
obj[field] = jestConfig[field];
|
@@ -66,41 +111,51 @@ const setJestConfigForBFF = async ({
|
|
66
111
|
return obj;
|
67
112
|
}, {});
|
68
113
|
if (!apiOnly) {
|
69
|
-
utils.setJestConfig(
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
114
|
+
utils.setJestConfig(
|
115
|
+
{
|
116
|
+
projects: [
|
117
|
+
__spreadValues({}, jestConfig),
|
118
|
+
__spreadValues({
|
119
|
+
transform,
|
120
|
+
moduleNameMapper: mergedModuleNameMapper,
|
121
|
+
resolver
|
122
|
+
}, bffConfig)
|
123
|
+
]
|
124
|
+
},
|
125
|
+
{
|
126
|
+
force: true
|
127
|
+
}
|
128
|
+
);
|
78
129
|
} else {
|
79
|
-
utils.setJestConfig(
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
130
|
+
utils.setJestConfig(
|
131
|
+
{
|
132
|
+
projects: [
|
133
|
+
__spreadValues({
|
134
|
+
transform,
|
135
|
+
moduleNameMapper: mergedModuleNameMapper,
|
136
|
+
resolver
|
137
|
+
}, bffConfig)
|
138
|
+
]
|
139
|
+
},
|
140
|
+
{
|
141
|
+
force: true
|
142
|
+
}
|
143
|
+
);
|
88
144
|
}
|
89
145
|
utils.setJestConfig(commonConfig);
|
90
|
-
};
|
91
|
-
|
92
|
-
|
93
|
-
name: '@modern-js/testing-plugin-bff',
|
146
|
+
});
|
147
|
+
var bff_default = () => ({
|
148
|
+
name: "@modern-js/testing-plugin-bff",
|
94
149
|
setup(api) {
|
95
150
|
return {
|
96
|
-
jestConfig:
|
151
|
+
jestConfig: (utils, next) => __async(this, null, function* () {
|
97
152
|
const appContext = api.useAppContext();
|
98
153
|
const pwd = appContext.appDirectory;
|
99
|
-
if (!(0,
|
154
|
+
if (!(0, import_utils2.isBFFProject)(pwd)) {
|
100
155
|
return next(utils);
|
101
156
|
}
|
102
157
|
const userConfig = api.useResolvedConfigContext();
|
103
|
-
|
158
|
+
yield setJestConfigForBFF({
|
104
159
|
pwd,
|
105
160
|
userConfig,
|
106
161
|
routes: appContext.serverRoutes,
|
@@ -108,8 +163,11 @@ var _default = () => ({
|
|
108
163
|
utils
|
109
164
|
});
|
110
165
|
return next(utils);
|
111
|
-
}
|
166
|
+
})
|
112
167
|
};
|
113
168
|
}
|
114
169
|
});
|
115
|
-
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
171
|
+
0 && (module.exports = {
|
172
|
+
setJestConfigForBFF
|
173
|
+
});
|