@modern-js/plugin-testing 0.0.0-nightly-20230918160602 → 0.0.0-nightly-20230922160540
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/dist/cjs/base/config/index.js +41 -22
- package/dist/cjs/base/config/patches/assetsModule.js +34 -7
- package/dist/cjs/base/config/patches/filemock.js +21 -8
- package/dist/cjs/base/config/patches/index.js +28 -11
- package/dist/cjs/base/config/patches/transformer.js +36 -9
- package/dist/cjs/base/config/resolver.js +24 -6
- package/dist/cjs/base/config/testConfigOperator.js +32 -15
- package/dist/cjs/base/config/transformer/babelTransformer.js +34 -12
- package/dist/cjs/base/hook.js +32 -23
- package/dist/cjs/base/index.js +41 -34
- package/dist/cjs/base/runJest.js +48 -30
- package/dist/cjs/base/types/index.js +15 -3
- package/dist/cjs/base/utils.js +46 -28
- package/dist/cjs/cli/bff/app.js +33 -25
- package/dist/cjs/cli/bff/constant.js +24 -7
- package/dist/cjs/cli/bff/index.js +48 -29
- package/dist/cjs/cli/bff/mockAPI.js +40 -18
- package/dist/cjs/cli/bff/setup.js +36 -18
- package/dist/cjs/cli/bff/utils/index.js +38 -12
- package/dist/cjs/cli/index.js +56 -40
- package/dist/cjs/cli/test.js +40 -18
- package/dist/cjs/constant.js +24 -7
- package/dist/cjs/index.js +22 -6
- package/dist/cjs/runtime-testing/app.js +38 -17
- package/dist/cjs/runtime-testing/base.js +38 -11
- package/dist/cjs/runtime-testing/bff.js +38 -12
- package/dist/cjs/runtime-testing/customRender.js +36 -14
- package/dist/cjs/runtime-testing/index.js +22 -5
- package/dist/cjs/runtime-testing/reduck.js +55 -38
- package/dist/cjs/runtime-testing/resolvePlugins.js +21 -8
- package/dist/esm/base/config/index.js +6 -2
- package/dist/esm/base/config/patches/assetsModule.js +4 -1
- package/dist/esm/base/config/patches/filemock.js +4 -1
- package/dist/esm/base/config/patches/index.js +4 -1
- package/dist/esm/base/config/patches/transformer.js +4 -1
- package/dist/esm/base/config/resolver.js +31 -22
- package/dist/esm/base/config/testConfigOperator.js +3 -1
- package/dist/esm/base/config/transformer/babelTransformer.js +6 -3
- package/dist/esm/base/hook.js +8 -3
- package/dist/esm/base/index.js +13 -5
- package/dist/esm/base/runJest.js +8 -4
- package/dist/esm/base/types/index.js +0 -1
- package/dist/esm/base/utils.js +8 -3
- package/dist/esm/cli/bff/app.js +10 -5
- package/dist/esm/cli/bff/constant.js +4 -1
- package/dist/esm/cli/bff/index.js +17 -13
- package/dist/esm/cli/bff/mockAPI.js +4 -1
- package/dist/esm/cli/bff/setup.js +5 -5
- package/dist/esm/cli/bff/utils/index.js +4 -1
- package/dist/esm/cli/index.js +10 -4
- package/dist/esm/cli/test.js +7 -4
- package/dist/esm/constant.js +4 -1
- package/dist/esm/runtime-testing/app.js +4 -1
- package/dist/esm/runtime-testing/base.js +4 -1
- package/dist/esm/runtime-testing/bff.js +3 -1
- package/dist/esm/runtime-testing/customRender.js +4 -1
- package/dist/esm/runtime-testing/reduck.js +16 -10
- package/dist/esm/runtime-testing/resolvePlugins.js +4 -1
- package/dist/esm-node/base/config/index.js +6 -2
- package/dist/esm-node/base/config/patches/assetsModule.js +4 -1
- package/dist/esm-node/base/config/patches/filemock.js +4 -1
- package/dist/esm-node/base/config/patches/index.js +4 -1
- package/dist/esm-node/base/config/patches/transformer.js +4 -1
- package/dist/esm-node/base/config/resolver.js +29 -20
- package/dist/esm-node/base/config/testConfigOperator.js +3 -1
- package/dist/esm-node/base/config/transformer/babelTransformer.js +6 -3
- package/dist/esm-node/base/hook.js +8 -3
- package/dist/esm-node/base/index.js +13 -5
- package/dist/esm-node/base/runJest.js +7 -4
- package/dist/esm-node/base/types/index.js +0 -1
- package/dist/esm-node/base/utils.js +8 -3
- package/dist/esm-node/cli/bff/app.js +7 -2
- package/dist/esm-node/cli/bff/constant.js +4 -1
- package/dist/esm-node/cli/bff/index.js +8 -4
- package/dist/esm-node/cli/bff/mockAPI.js +4 -1
- package/dist/esm-node/cli/bff/setup.js +3 -3
- package/dist/esm-node/cli/bff/utils/index.js +4 -1
- package/dist/esm-node/cli/index.js +10 -4
- package/dist/esm-node/cli/test.js +7 -4
- package/dist/esm-node/constant.js +4 -1
- package/dist/esm-node/runtime-testing/app.js +4 -1
- package/dist/esm-node/runtime-testing/base.js +4 -1
- package/dist/esm-node/runtime-testing/bff.js +3 -1
- package/dist/esm-node/runtime-testing/customRender.js +4 -1
- package/dist/esm-node/runtime-testing/reduck.js +16 -10
- package/dist/esm-node/runtime-testing/resolvePlugins.js +5 -2
- package/package.json +13 -13
package/dist/esm/cli/test.js
CHANGED
@@ -5,18 +5,18 @@ import { compiler } from "@modern-js/babel-compiler";
|
|
5
5
|
import { runTest } from "../base";
|
6
6
|
var test = function() {
|
7
7
|
var _ref = _async_to_generator(function(api) {
|
8
|
-
var _userConfig_tools,
|
8
|
+
var _userConfig_tools, _userConfig_tools1, userConfig, appContext, jest, runtimeExportsPath;
|
9
9
|
return _ts_generator(this, function(_state) {
|
10
10
|
switch (_state.label) {
|
11
11
|
case 0:
|
12
12
|
userConfig = api.useResolvedConfigContext();
|
13
13
|
appContext = api.useAppContext();
|
14
14
|
userConfig.testing = userConfig.testing || {};
|
15
|
-
jest = userConfig.testing.jest || (
|
15
|
+
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);
|
16
16
|
if (Array.isArray(jest)) {
|
17
17
|
userConfig.testing.jest = jest[0];
|
18
18
|
}
|
19
|
-
userConfig.testing.jest = userConfig.testing.jest || (
|
19
|
+
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);
|
20
20
|
runtimeExportsPath = path.join(appContext.internalDirectory, ".runtime-exports");
|
21
21
|
return [
|
22
22
|
4,
|
@@ -54,4 +54,7 @@ var test = function() {
|
|
54
54
|
return _ref.apply(this, arguments);
|
55
55
|
};
|
56
56
|
}();
|
57
|
-
|
57
|
+
var test_default = test;
|
58
|
+
export {
|
59
|
+
test_default as default
|
60
|
+
};
|
package/dist/esm/constant.js
CHANGED
@@ -43,4 +43,7 @@ var ModernRuntime = /* @__PURE__ */ function() {
|
|
43
43
|
]);
|
44
44
|
return ModernRuntime2;
|
45
45
|
}();
|
46
|
-
|
46
|
+
var app_default = new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
|
47
|
+
export {
|
48
|
+
app_default as default
|
49
|
+
};
|
@@ -5,34 +5,40 @@ import effectsPlugin from "@modern-js-reduck/plugin-effects";
|
|
5
5
|
import autoActionsPlugin from "@modern-js-reduck/plugin-auto-actions";
|
6
6
|
import immerPlugin from "@modern-js-reduck/plugin-immutable";
|
7
7
|
import { MODERNJS_CONFIG_KEY } from "../constant";
|
8
|
-
|
8
|
+
var effects = function() {
|
9
9
|
return effectsPlugin;
|
10
10
|
};
|
11
|
-
|
11
|
+
var immer = function() {
|
12
12
|
return immerPlugin;
|
13
13
|
};
|
14
|
-
|
14
|
+
var autoActions = function() {
|
15
15
|
return autoActionsPlugin;
|
16
16
|
};
|
17
|
-
|
17
|
+
var createStore = function(props) {
|
18
18
|
var createStatePlugins = function() {
|
19
|
-
var _modernConfig_runtime
|
19
|
+
var _modernConfig_runtime;
|
20
20
|
var modernConfig = global[MODERNJS_CONFIG_KEY];
|
21
|
-
var stateConfig =
|
21
|
+
var stateConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_runtime = modernConfig.runtime) === null || _modernConfig_runtime === void 0 ? void 0 : _modernConfig_runtime.state;
|
22
22
|
var plugins = [];
|
23
|
-
if ((
|
23
|
+
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.effects) !== false) {
|
24
24
|
plugins.push(effects());
|
25
25
|
}
|
26
|
-
if ((
|
26
|
+
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.autoActions) !== false) {
|
27
27
|
plugins.push(autoActions());
|
28
28
|
}
|
29
|
-
if ((
|
29
|
+
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.immer) !== false) {
|
30
30
|
plugins.push(immer());
|
31
31
|
}
|
32
|
-
return ((
|
32
|
+
return ((props === null || props === void 0 ? void 0 : props.plugins) || []).concat(plugins);
|
33
33
|
};
|
34
34
|
var config = _object_spread_props(_object_spread({}, props || {}), {
|
35
35
|
plugins: createStatePlugins()
|
36
36
|
});
|
37
37
|
return originCreateStore(config);
|
38
38
|
};
|
39
|
+
export {
|
40
|
+
autoActions,
|
41
|
+
createStore,
|
42
|
+
effects,
|
43
|
+
immer
|
44
|
+
};
|
@@ -3,7 +3,7 @@ var allowedFeatures = [
|
|
3
3
|
"router",
|
4
4
|
"state"
|
5
5
|
];
|
6
|
-
|
6
|
+
function resolvePlugins(features) {
|
7
7
|
var plugins = [];
|
8
8
|
if (!features) {
|
9
9
|
return plugins;
|
@@ -16,3 +16,6 @@ export default function resolvePlugins(features) {
|
|
16
16
|
});
|
17
17
|
return plugins;
|
18
18
|
}
|
19
|
+
export {
|
20
|
+
resolvePlugins as default
|
21
|
+
};
|
@@ -8,5 +8,9 @@ const patchConfig = async (testOperator) => {
|
|
8
8
|
await applyPatches(testOperator);
|
9
9
|
return testOperator.jestConfig;
|
10
10
|
};
|
11
|
-
|
12
|
-
export {
|
11
|
+
const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
12
|
+
export {
|
13
|
+
DEFAULT_RESOLVER_PATH,
|
14
|
+
getJestUtils,
|
15
|
+
patchConfig
|
16
|
+
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
const patchAssetsModule = (testOperator) => {
|
2
2
|
testOperator.mergeJestConfig({
|
3
3
|
moduleNameMapper: {
|
4
4
|
"\\.(css|less|scss|sass)$": require.resolve("identity-obj-proxy"),
|
@@ -6,3 +6,6 @@ export const patchAssetsModule = (testOperator) => {
|
|
6
6
|
}
|
7
7
|
});
|
8
8
|
};
|
9
|
+
export {
|
10
|
+
patchAssetsModule
|
11
|
+
};
|
@@ -8,7 +8,7 @@ const resolveTsCompilerOptions = () => {
|
|
8
8
|
tsCompilerOptions.jsx = "react-jsx";
|
9
9
|
return tsCompilerOptions;
|
10
10
|
};
|
11
|
-
|
11
|
+
const patchTransformer = (testOperator) => {
|
12
12
|
const { transformer } = testOperator.testConfig;
|
13
13
|
if (transformer === "babel-jest") {
|
14
14
|
testOperator.mergeJestConfig({
|
@@ -29,3 +29,6 @@ export const patchTransformer = (testOperator) => {
|
|
29
29
|
});
|
30
30
|
}
|
31
31
|
};
|
32
|
+
export {
|
33
|
+
patchTransformer
|
34
|
+
};
|
@@ -1,22 +1,31 @@
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
4
|
+
};
|
1
5
|
import enhanceResolve from "enhanced-resolve";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
var require_resolver = __commonJS({
|
7
|
+
"src/base/config/resolver.ts"(exports, module) {
|
8
|
+
const resolver = enhanceResolve.create.sync({
|
9
|
+
conditionNames: [
|
10
|
+
"require",
|
11
|
+
"node",
|
12
|
+
"default"
|
13
|
+
],
|
14
|
+
extensions: [
|
15
|
+
".js",
|
16
|
+
".json",
|
17
|
+
".node",
|
18
|
+
".ts",
|
19
|
+
".tsx"
|
20
|
+
]
|
21
|
+
});
|
22
|
+
const shouldResolveByEnhance = (url) => /^@[^/]+\/[^/]+\/.*/.test(url);
|
23
|
+
module.exports = function(request, options) {
|
24
|
+
if (shouldResolveByEnhance(request)) {
|
25
|
+
return resolver(options.basedir, request);
|
26
|
+
}
|
27
|
+
return options.defaultResolver(request, options);
|
28
|
+
};
|
20
29
|
}
|
21
|
-
|
22
|
-
|
30
|
+
});
|
31
|
+
export default require_resolver();
|
@@ -1,6 +1,6 @@
|
|
1
|
-
var _babelJest_createTransformer
|
1
|
+
var _babelJest_createTransformer;
|
2
2
|
import babelJest from "babel-jest";
|
3
|
-
const babelTransformer = (_babelJest_createTransformer =
|
3
|
+
const babelTransformer = (_babelJest_createTransformer = babelJest.createTransformer) === null || _babelJest_createTransformer === void 0 ? void 0 : _babelJest_createTransformer.call(babelJest, {
|
4
4
|
presets: [
|
5
5
|
[
|
6
6
|
require.resolve("@modern-js/babel-preset-app"),
|
@@ -13,4 +13,7 @@ const babelTransformer = (_babelJest_createTransformer = (_babelJest = babelJest
|
|
13
13
|
configFile: false,
|
14
14
|
babelrc: false
|
15
15
|
});
|
16
|
-
|
16
|
+
var babelTransformer_default = babelTransformer;
|
17
|
+
export {
|
18
|
+
babelTransformer_default as default
|
19
|
+
};
|
@@ -1,7 +1,12 @@
|
|
1
1
|
import { createAsyncPipeline, createParallelWorkflow } from "@modern-js/plugin";
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
const jestConfigHook = createAsyncPipeline();
|
3
|
+
const afterTestHook = createParallelWorkflow();
|
4
|
+
const testingHooks = {
|
5
5
|
jestConfig: createAsyncPipeline(),
|
6
6
|
afterTest: createParallelWorkflow()
|
7
7
|
};
|
8
|
+
export {
|
9
|
+
afterTestHook,
|
10
|
+
jestConfigHook,
|
11
|
+
testingHooks
|
12
|
+
};
|
@@ -1,6 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
import { runTest, runJest } from "./runJest";
|
2
|
+
import { getModuleNameMapper } from "./utils";
|
3
|
+
import { DEFAULT_RESOLVER_PATH } from "./config";
|
4
|
+
import { TestConfigOperator } from "./config/testConfigOperator";
|
5
|
+
import { testingHooks } from "./hook";
|
6
6
|
export * from "./types";
|
7
|
+
export {
|
8
|
+
DEFAULT_RESOLVER_PATH,
|
9
|
+
TestConfigOperator,
|
10
|
+
getModuleNameMapper,
|
11
|
+
runJest,
|
12
|
+
runTest,
|
13
|
+
testingHooks
|
14
|
+
};
|
@@ -38,7 +38,7 @@ const readResultsAndExit = (result, globalConfig) => {
|
|
38
38
|
}, 1e3).unref();
|
39
39
|
}
|
40
40
|
};
|
41
|
-
|
41
|
+
async function runJest(config, pwd = process.cwd()) {
|
42
42
|
try {
|
43
43
|
const argvConfig = await buildArgv(process.argv.slice(2), config);
|
44
44
|
const { results, globalConfig } = await runCLI(argvConfig, [
|
@@ -46,12 +46,11 @@ export async function runJest(config, pwd = process.cwd()) {
|
|
46
46
|
]);
|
47
47
|
readResultsAndExit(results, globalConfig);
|
48
48
|
} catch (e) {
|
49
|
-
|
50
|
-
console.error(chalk.red(((_e = e) === null || _e === void 0 ? void 0 : _e.stack) || e));
|
49
|
+
console.error(chalk.red((e === null || e === void 0 ? void 0 : e.stack) || e));
|
51
50
|
process.exit(1);
|
52
51
|
}
|
53
52
|
}
|
54
|
-
|
53
|
+
async function runTest(api, config, pwd = process.cwd()) {
|
55
54
|
process.env.NODE_ENV = "test";
|
56
55
|
const jestUtils = getJestUtils(config);
|
57
56
|
await patchConfig(jestUtils);
|
@@ -65,3 +64,7 @@ export async function runTest(api, config, pwd = process.cwd()) {
|
|
65
64
|
await runJest(finalConfig, pwd);
|
66
65
|
await hookRunners.afterTest();
|
67
66
|
}
|
67
|
+
export {
|
68
|
+
runJest,
|
69
|
+
runTest
|
70
|
+
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -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
|
-
|
5
|
-
|
4
|
+
const debug = createDebugger("test");
|
5
|
+
const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") => {
|
6
6
|
let tsConfig = {};
|
7
7
|
let extendedCompilerOptions = {};
|
8
8
|
let tsconfigFile = "";
|
@@ -25,7 +25,7 @@ export const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.js
|
|
25
25
|
...tsConfig.compilerOptions
|
26
26
|
};
|
27
27
|
};
|
28
|
-
|
28
|
+
const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
|
29
29
|
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [
|
30
30
|
alias[cur]
|
31
31
|
];
|
@@ -42,3 +42,8 @@ export const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, c
|
|
42
42
|
memo[key] = value;
|
43
43
|
return memo;
|
44
44
|
}, {});
|
45
|
+
export {
|
46
|
+
debug,
|
47
|
+
getModuleNameMapper,
|
48
|
+
readCompilerOptions
|
49
|
+
};
|
@@ -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
|
-
|
4
|
+
const isInHandler = () => Boolean(store.getStore());
|
5
5
|
let server = null;
|
6
6
|
const createApp = async (pwd, config, plugins, routes) => {
|
7
7
|
if (!server) {
|
@@ -30,4 +30,9 @@ const closeServer = async () => {
|
|
30
30
|
}
|
31
31
|
await server.close();
|
32
32
|
};
|
33
|
-
export {
|
33
|
+
export {
|
34
|
+
closeServer,
|
35
|
+
createApp,
|
36
|
+
getApp,
|
37
|
+
isInHandler
|
38
|
+
};
|
@@ -3,8 +3,8 @@ import { isApiOnly } from "@modern-js/utils";
|
|
3
3
|
import { getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../../base";
|
4
4
|
import { bff_info_key } from "./constant";
|
5
5
|
import { isBFFProject } from "./utils";
|
6
|
-
|
7
|
-
var _userConfig_source
|
6
|
+
const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils }) => {
|
7
|
+
var _userConfig_source;
|
8
8
|
const bffConfig = {
|
9
9
|
rootDir: path.join(pwd, "./api"),
|
10
10
|
setupFilesAfterEnv: [
|
@@ -27,7 +27,7 @@ export const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, ut
|
|
27
27
|
}
|
28
28
|
};
|
29
29
|
const { jestConfig } = utils;
|
30
|
-
const alias = (
|
30
|
+
const alias = (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.alias) || {};
|
31
31
|
const aliasMapper = getModuleNameMapper(alias);
|
32
32
|
const { moduleNameMapper } = jestConfig;
|
33
33
|
const transform = {
|
@@ -89,7 +89,7 @@ export const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, ut
|
|
89
89
|
}
|
90
90
|
utils.setJestConfig(commonConfig);
|
91
91
|
};
|
92
|
-
|
92
|
+
const testingBffPlugin = () => ({
|
93
93
|
name: "@modern-js/testing-plugin-bff",
|
94
94
|
setup(api) {
|
95
95
|
return {
|
@@ -112,3 +112,7 @@ export const testingBffPlugin = () => ({
|
|
112
112
|
};
|
113
113
|
}
|
114
114
|
});
|
115
|
+
export {
|
116
|
+
setJestConfigForBFF,
|
117
|
+
testingBffPlugin
|
118
|
+
};
|
@@ -45,7 +45,7 @@ const mock_getParamsAndPayload = (args) => {
|
|
45
45
|
}
|
46
46
|
}
|
47
47
|
};
|
48
|
-
|
48
|
+
var mockAPI_default = (mockApiInfosByFile) => {
|
49
49
|
const files = Object.keys(mockApiInfosByFile);
|
50
50
|
files.forEach((mockedFile) => {
|
51
51
|
jest.mock(mockedFile, () => {
|
@@ -100,3 +100,6 @@ export default (mockApiInfosByFile) => {
|
|
100
100
|
});
|
101
101
|
});
|
102
102
|
};
|
103
|
+
export {
|
104
|
+
mockAPI_default as default
|
105
|
+
};
|
@@ -5,14 +5,14 @@ import mockAPI from "./mockAPI";
|
|
5
5
|
import { createApp, closeServer } from "./app";
|
6
6
|
let uped = false;
|
7
7
|
const setup = () => {
|
8
|
-
var _bff_info_modernUserConfig_bff, _bff_info_modernUserConfig,
|
8
|
+
var _bff_info_modernUserConfig_bff, _bff_info_modernUserConfig, _bff_info_modernUserConfig_bff1, _bff_info_modernUserConfig1;
|
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
|
let app = null;
|
17
17
|
beforeAll(async () => {
|
18
18
|
const apiRouter = new ApiRouter({
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import { chalk } from "@modern-js/utils";
|
3
|
-
|
3
|
+
const isBFFProject = (pwd) => {
|
4
4
|
try {
|
5
5
|
const packageJson = require(path.join(pwd, "./package.json"));
|
6
6
|
const { dependencies, devDependencies } = packageJson;
|
@@ -15,3 +15,6 @@ export const isBFFProject = (pwd) => {
|
|
15
15
|
return false;
|
16
16
|
}
|
17
17
|
};
|
18
|
+
export {
|
19
|
+
isBFFProject
|
20
|
+
};
|
@@ -4,13 +4,13 @@ import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../bas
|
|
4
4
|
import { MODERNJS_CONFIG_KEY } from "../constant";
|
5
5
|
import { testingBffPlugin } from "./bff";
|
6
6
|
import test from "./test";
|
7
|
-
|
7
|
+
const mergeUserJestConfig = (testUtils) => {
|
8
8
|
const resolveJestConfig = testUtils.testConfig.jest;
|
9
9
|
if (resolveJestConfig && typeof resolveJestConfig !== "function") {
|
10
10
|
testUtils.mergeJestConfig(resolveJestConfig);
|
11
11
|
}
|
12
12
|
};
|
13
|
-
|
13
|
+
const getJestTransformEsModulesRegStr = () => {
|
14
14
|
const esmModulesInPnpm = [
|
15
15
|
"@modern-js\\+runtime@",
|
16
16
|
"@modern-js\\+plugin@",
|
@@ -26,7 +26,7 @@ export const getJestTransformEsModulesRegStr = () => {
|
|
26
26
|
];
|
27
27
|
return `node_modules/(?!(\\.pnpm/(${esmModulesInPnpm.join("|")}))|(${esmModules.join("|")}))`;
|
28
28
|
};
|
29
|
-
|
29
|
+
const testingPlugin = () => {
|
30
30
|
const bffPlugin = testingBffPlugin();
|
31
31
|
return {
|
32
32
|
name: "@modern-js/plugin-testing",
|
@@ -136,4 +136,10 @@ export const testingPlugin = () => {
|
|
136
136
|
}
|
137
137
|
};
|
138
138
|
};
|
139
|
-
|
139
|
+
var cli_default = testingPlugin;
|
140
|
+
export {
|
141
|
+
cli_default as default,
|
142
|
+
getJestTransformEsModulesRegStr,
|
143
|
+
mergeUserJestConfig,
|
144
|
+
testingPlugin
|
145
|
+
};
|
@@ -2,15 +2,15 @@ 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 _userConfig_tools,
|
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 || (
|
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
14
|
const runtimeExportsPath = path.join(appContext.internalDirectory, ".runtime-exports");
|
15
15
|
await compiler({
|
16
16
|
sourceDir: runtimeExportsPath,
|
@@ -29,4 +29,7 @@ const test = async (api) => {
|
|
29
29
|
});
|
30
30
|
await runTest(api, userConfig.testing);
|
31
31
|
};
|
32
|
-
|
32
|
+
var test_default = test;
|
33
|
+
export {
|
34
|
+
test_default as default
|
35
|
+
};
|