@modern-js/plugin-testing 1.21.5 → 2.0.0-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +88 -29
- package/dist/js/modern/base/config/index.js +1 -3
- package/dist/js/modern/base/config/patches/index.js +0 -2
- package/dist/js/modern/base/config/patches/transformer.js +1 -7
- package/dist/js/modern/base/config/resolver.js +0 -3
- package/dist/js/modern/base/config/testConfigOperator.js +0 -23
- package/dist/js/modern/base/config/transformer/babelTransformer.js +0 -1
- package/dist/js/modern/base/runJest.js +11 -14
- package/dist/js/modern/base/utils.js +2 -12
- package/dist/js/modern/cli/bff/app.js +1 -8
- package/dist/js/modern/cli/bff/index.js +5 -17
- package/dist/js/modern/cli/bff/mockAPI.js +4 -20
- package/dist/js/modern/cli/bff/setup.js +0 -5
- package/dist/js/modern/cli/bff/utils/index.js +0 -4
- package/dist/js/modern/cli/index.js +7 -15
- package/dist/js/modern/cli/test.js +0 -4
- package/dist/js/modern/runtime-testing/app.js +0 -15
- package/dist/js/modern/runtime-testing/customRender.js +0 -6
- package/dist/js/modern/runtime-testing/reduck.js +0 -10
- package/dist/js/modern/runtime-testing/request.js +1 -4
- package/dist/js/modern/runtime-testing/resolvePlugins.js +0 -6
- package/dist/js/node/base/config/index.js +0 -8
- package/dist/js/node/base/config/patches/assetsModule.js +0 -2
- package/dist/js/node/base/config/patches/index.js +0 -6
- package/dist/js/node/base/config/patches/transformer.js +1 -9
- package/dist/js/node/base/config/resolver.js +0 -5
- package/dist/js/node/base/config/testConfigOperator.js +0 -24
- package/dist/js/node/base/config/transformer/babelTransformer.js +0 -4
- package/dist/js/node/base/hook.js +0 -2
- package/dist/js/node/base/index.js +0 -7
- package/dist/js/node/base/runJest.js +11 -21
- package/dist/js/node/base/utils.js +2 -22
- package/dist/js/node/cli/bff/app.js +1 -15
- package/dist/js/node/cli/bff/index.js +5 -27
- package/dist/js/node/cli/bff/mockAPI.js +2 -25
- package/dist/js/node/cli/bff/setup.js +0 -11
- package/dist/js/node/cli/bff/utils/index.js +0 -9
- package/dist/js/node/cli/index.js +6 -27
- package/dist/js/node/cli/test.js +0 -10
- package/dist/js/node/index.js +0 -4
- package/dist/js/node/runtime-testing/app.js +0 -20
- package/dist/js/node/runtime-testing/base.js +0 -5
- package/dist/js/node/runtime-testing/customRender.js +0 -10
- package/dist/js/node/runtime-testing/index.js +0 -4
- package/dist/js/node/runtime-testing/reduck.js +0 -24
- package/dist/js/node/runtime-testing/request.js +1 -6
- package/dist/js/node/runtime-testing/resolvePlugins.js +0 -8
- package/dist/js/treeshaking/base/config/index.js +1 -6
- package/dist/js/treeshaking/base/config/patches/index.js +0 -17
- package/dist/js/treeshaking/base/config/patches/transformer.js +1 -7
- package/dist/js/treeshaking/base/config/resolver.js +0 -3
- package/dist/js/treeshaking/base/config/testConfigOperator.js +0 -15
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +0 -1
- package/dist/js/treeshaking/base/runJest.js +19 -38
- package/dist/js/treeshaking/base/utils.js +2 -10
- package/dist/js/treeshaking/cli/bff/app.js +1 -14
- package/dist/js/treeshaking/cli/bff/index.js +5 -24
- package/dist/js/treeshaking/cli/bff/mockAPI.js +8 -24
- package/dist/js/treeshaking/cli/bff/setup.js +0 -9
- package/dist/js/treeshaking/cli/bff/utils/index.js +1 -2
- package/dist/js/treeshaking/cli/index.js +8 -15
- package/dist/js/treeshaking/cli/test.js +0 -7
- package/dist/js/treeshaking/runtime-testing/app.js +2 -15
- package/dist/js/treeshaking/runtime-testing/customRender.js +0 -3
- package/dist/js/treeshaking/runtime-testing/reduck.js +0 -7
- package/dist/js/treeshaking/runtime-testing/request.js +2 -7
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +0 -3
- package/dist/types/base/config/index.d.ts +0 -1
- package/dist/types/base/config/patches/assetsModule.d.ts +0 -1
- package/dist/types/base/config/patches/filemock.d.ts +0 -1
- package/dist/types/base/config/patches/transformer.d.ts +0 -1
- package/dist/types/base/config/testConfigOperator.d.ts +0 -2
- package/dist/types/base/runJest.d.ts +0 -2
- package/dist/types/base/utils.d.ts +0 -1
- package/dist/types/cli/bff/app.d.ts +2 -1
- package/dist/types/cli/bff/index.d.ts +2 -3
- package/dist/types/cli/bff/mockAPI.d.ts +0 -1
- package/dist/types/cli/index.d.ts +0 -2
- package/dist/types/runtime-testing/app.d.ts +0 -3
- package/dist/types/runtime-testing/customRender.d.ts +0 -2
- package/package.json +18 -41
@@ -4,14 +4,11 @@ import { bff_info_key } from "./constant";
|
|
4
4
|
import mockAPI from "./mockAPI";
|
5
5
|
import { createApp, closeServer } from "./app";
|
6
6
|
let uped = false;
|
7
|
-
|
8
7
|
const setup = () => {
|
9
8
|
var _bff_info$modernUserC, _bff_info$modernUserC2;
|
10
|
-
|
11
9
|
if (uped) {
|
12
10
|
return;
|
13
11
|
}
|
14
|
-
|
15
12
|
uped = true;
|
16
13
|
const bff_info = global[bff_info_key];
|
17
14
|
const prefix = bff_info === null || bff_info === void 0 ? void 0 : (_bff_info$modernUserC = bff_info.modernUserConfig) === null || _bff_info$modernUserC === void 0 ? void 0 : (_bff_info$modernUserC2 = _bff_info$modernUserC.bff) === null || _bff_info$modernUserC2 === void 0 ? void 0 : _bff_info$modernUserC2.prefix;
|
@@ -24,7 +21,6 @@ const setup = () => {
|
|
24
21
|
if (!res[apiInfo.filename]) {
|
25
22
|
res[apiInfo.filename] = [];
|
26
23
|
}
|
27
|
-
|
28
24
|
res[apiInfo.filename].push(apiInfo);
|
29
25
|
return res;
|
30
26
|
}, {});
|
@@ -39,5 +35,4 @@ const setup = () => {
|
|
39
35
|
});
|
40
36
|
mockAPI(apiInfosByFile);
|
41
37
|
};
|
42
|
-
|
43
38
|
setup();
|
@@ -1,15 +1,11 @@
|
|
1
1
|
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; }
|
2
|
-
|
3
2
|
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; }
|
4
|
-
|
5
3
|
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; }
|
6
|
-
|
7
4
|
import path from 'path';
|
8
5
|
import { chalk } from '@modern-js/utils';
|
9
6
|
export const isBFFProject = pwd => {
|
10
7
|
try {
|
11
8
|
const packageJson = require(path.join(pwd, './package.json'));
|
12
|
-
|
13
9
|
const {
|
14
10
|
dependencies,
|
15
11
|
devDependencies
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import path from 'path';
|
2
|
-
import { PLUGIN_SCHEMAS, createRuntimeExportsUtils
|
3
|
-
import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
|
2
|
+
import { isApiOnly, mergeAlias, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from '@modern-js/utils';
|
4
3
|
import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../base";
|
5
4
|
import { MODERNJS_CONFIG_KEY } from "../constant";
|
6
5
|
import TestingBffPlugin from "./bff";
|
7
6
|
import test from "./test";
|
8
7
|
export const mergeUserJestConfig = testUtils => {
|
9
|
-
const resolveJestConfig = testUtils.testConfig.jest;
|
8
|
+
const resolveJestConfig = testUtils.testConfig.jest;
|
10
9
|
|
10
|
+
// resolveJestConfig 如果是函数类型,在所有测试插件 jestConfig 都执行后,再执行生成最终配置
|
11
11
|
if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
|
12
12
|
testUtils.mergeJestConfig(resolveJestConfig);
|
13
13
|
}
|
@@ -29,11 +29,9 @@ export default (() => {
|
|
29
29
|
await test(api);
|
30
30
|
});
|
31
31
|
},
|
32
|
-
|
33
32
|
validateSchema() {
|
34
33
|
return PLUGIN_SCHEMAS['@modern-js/plugin-testing'];
|
35
34
|
},
|
36
|
-
|
37
35
|
config() {
|
38
36
|
const appContext = api.useAppContext();
|
39
37
|
testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'testing');
|
@@ -45,27 +43,21 @@ export default (() => {
|
|
45
43
|
}
|
46
44
|
};
|
47
45
|
},
|
48
|
-
|
49
46
|
addRuntimeExports() {
|
50
47
|
const testingPath = path.resolve(__dirname, '../');
|
51
48
|
testingExportsUtils.addExport(`export * from '${testingPath}'`);
|
52
49
|
},
|
53
|
-
|
54
50
|
jestConfig: async (utils, next) => {
|
55
51
|
const appContext = api.useAppContext();
|
56
52
|
const userConfig = api.useResolvedConfigContext();
|
57
53
|
const apiOnly = await isApiOnly(appContext.appDirectory);
|
58
|
-
|
59
54
|
if (apiOnly) {
|
60
55
|
return next(utils);
|
61
56
|
}
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
alias = {}
|
67
|
-
}
|
68
|
-
} = webpackConfig;
|
57
|
+
const alias = mergeAlias(userConfig.source.alias);
|
58
|
+
if (testingExportsUtils) {
|
59
|
+
alias['@modern-js/runtime/testing'] = [testingExportsUtils.getPath()];
|
60
|
+
}
|
69
61
|
utils.mergeJestConfig({
|
70
62
|
globals: {
|
71
63
|
[MODERNJS_CONFIG_KEY]: userConfig
|
@@ -1,17 +1,14 @@
|
|
1
1
|
import path from 'path';
|
2
2
|
import { compiler } from '@modern-js/babel-compiler';
|
3
3
|
import { runTest } from "../base";
|
4
|
-
|
5
4
|
const test = async api => {
|
6
5
|
const userConfig = api.useResolvedConfigContext();
|
7
6
|
const appContext = api.useAppContext();
|
8
7
|
userConfig.testing = userConfig.testing || {};
|
9
8
|
const jest = userConfig.testing.jest || userConfig.tools.jest;
|
10
|
-
|
11
9
|
if (Array.isArray(jest)) {
|
12
10
|
userConfig.testing.jest = jest[0];
|
13
11
|
}
|
14
|
-
|
15
12
|
userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
|
16
13
|
const runtimeExportsPath = path.join(appContext.internalDirectory, '.runtime-exports');
|
17
14
|
await compiler({
|
@@ -26,5 +23,4 @@ const test = async api => {
|
|
26
23
|
});
|
27
24
|
await runTest(api, userConfig.testing);
|
28
25
|
};
|
29
|
-
|
30
26
|
export default test;
|
@@ -1,52 +1,37 @@
|
|
1
1
|
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; }
|
2
|
-
|
3
2
|
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; }
|
4
|
-
|
5
3
|
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; }
|
6
|
-
|
7
4
|
import { createApp } from '@modern-js/runtime';
|
8
5
|
import { MODERNJS_CONFIG_KEY } from "../constant";
|
9
6
|
import resolvePlugins from "./resolvePlugins";
|
10
|
-
|
11
7
|
class ModernRuntime {
|
12
8
|
constructor(options) {
|
13
9
|
_defineProperty(this, "options", void 0);
|
14
|
-
|
15
10
|
this.options = options;
|
16
11
|
}
|
17
|
-
|
18
12
|
init(options) {
|
19
13
|
this.options = options;
|
20
14
|
}
|
21
|
-
|
22
15
|
createApp(props) {
|
23
16
|
var _this$options;
|
24
|
-
|
25
17
|
const {
|
26
18
|
entry,
|
27
19
|
children
|
28
20
|
} = props || {};
|
29
21
|
let runtimeFeatures = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.runtime;
|
30
|
-
|
31
22
|
if (entry) {
|
32
23
|
var _this$options$runtime;
|
33
|
-
|
34
24
|
runtimeFeatures = _objectSpread(_objectSpread({}, runtimeFeatures || {}), (_this$options$runtime = this.options.runtimeByEntries) === null || _this$options$runtime === void 0 ? void 0 : _this$options$runtime[entry]);
|
35
25
|
}
|
36
|
-
|
37
26
|
const Component = () => {
|
38
27
|
if (!children) {
|
39
28
|
return null;
|
40
29
|
}
|
41
|
-
|
42
30
|
return children;
|
43
31
|
};
|
44
|
-
|
45
32
|
return createApp({
|
46
33
|
plugins: resolvePlugins(runtimeFeatures || {})
|
47
34
|
})(Component);
|
48
35
|
}
|
49
|
-
|
50
36
|
}
|
51
|
-
|
52
37
|
export default new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
|
@@ -1,17 +1,11 @@
|
|
1
1
|
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; }
|
2
|
-
|
3
2
|
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; }
|
4
|
-
|
5
3
|
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; }
|
6
|
-
|
7
4
|
import React from 'react';
|
8
5
|
import { render } from '@testing-library/react';
|
9
6
|
import app from "./app";
|
10
|
-
|
11
7
|
const WrapModernProviders = props => /*#__PURE__*/React.createElement(app.createApp(props));
|
12
|
-
|
13
8
|
const customRender = (ui, options) => render(ui, _objectSpread({
|
14
9
|
wrapper: WrapModernProviders
|
15
10
|
}, options));
|
16
|
-
|
17
11
|
export default customRender;
|
@@ -1,9 +1,6 @@
|
|
1
1
|
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; }
|
2
|
-
|
3
2
|
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; }
|
4
|
-
|
5
3
|
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; }
|
6
|
-
|
7
4
|
import { createStore as originCreateStore } from '@modern-js-reduck/store';
|
8
5
|
import effectsPlugin from '@modern-js-reduck/plugin-effects';
|
9
6
|
import autoActionsPlugin from '@modern-js-reduck/plugin-auto-actions';
|
@@ -15,29 +12,22 @@ export const autoActions = () => autoActionsPlugin;
|
|
15
12
|
export const createStore = props => {
|
16
13
|
const createStatePlugins = () => {
|
17
14
|
var _modernConfig$runtime;
|
18
|
-
|
19
15
|
const modernConfig = global[MODERNJS_CONFIG_KEY];
|
20
16
|
const stateConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig$runtime = modernConfig.runtime) === null || _modernConfig$runtime === void 0 ? void 0 : _modernConfig$runtime.state;
|
21
17
|
const plugins = [];
|
22
|
-
|
23
18
|
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.effects) !== false) {
|
24
19
|
plugins.push(effects());
|
25
20
|
}
|
26
|
-
|
27
21
|
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.autoActions) !== false) {
|
28
22
|
plugins.push(autoActions());
|
29
23
|
}
|
30
|
-
|
31
24
|
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.immer) !== false) {
|
32
25
|
plugins.push(immer());
|
33
26
|
}
|
34
|
-
|
35
27
|
return ((props === null || props === void 0 ? void 0 : props.plugins) || []).concat(plugins);
|
36
28
|
};
|
37
|
-
|
38
29
|
const config = _objectSpread(_objectSpread({}, props || {}), {}, {
|
39
30
|
plugins: createStatePlugins()
|
40
31
|
});
|
41
|
-
|
42
32
|
return originCreateStore(config);
|
43
33
|
};
|
@@ -1,19 +1,16 @@
|
|
1
1
|
/* eslint-disable eslint-comments/disable-enable-pair */
|
2
|
+
|
2
3
|
import supertest from 'supertest';
|
3
4
|
import { getApp } from "../cli/bff/app";
|
4
|
-
|
5
5
|
function request(...args) {
|
6
6
|
const [fn, ...extraArgs] = args;
|
7
7
|
const app = getApp();
|
8
|
-
|
9
8
|
if (!fn) {
|
10
9
|
return supertest(app);
|
11
10
|
}
|
12
|
-
|
13
11
|
fn.returnHttp = true;
|
14
12
|
const res = fn(...extraArgs);
|
15
13
|
fn.returnHttp = false;
|
16
14
|
return res;
|
17
15
|
}
|
18
|
-
|
19
16
|
export { request };
|
@@ -1,21 +1,15 @@
|
|
1
1
|
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; }
|
2
|
-
|
3
2
|
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; }
|
4
|
-
|
5
3
|
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; }
|
6
|
-
|
7
4
|
const allowedFeatures = ['router', 'state'];
|
8
5
|
export default function resolvePlugins(features) {
|
9
6
|
const plugins = [];
|
10
|
-
|
11
7
|
if (!features) {
|
12
8
|
return plugins;
|
13
9
|
}
|
14
|
-
|
15
10
|
Object.keys(features).forEach(feature => {
|
16
11
|
if (allowedFeatures.includes(feature)) {
|
17
12
|
const curPluginRes = require(`@modern-js/runtime/plugins`)[feature](_objectSpread({}, features[feature]));
|
18
|
-
|
19
13
|
plugins.push(curPluginRes);
|
20
14
|
}
|
21
15
|
});
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.patchConfig = exports.getJestUtils = exports.DEFAULT_RESOLVER_PATH = void 0;
|
7
|
-
|
8
7
|
var _patches = require("./patches");
|
9
|
-
|
10
8
|
var _testConfigOperator = require("./testConfigOperator");
|
11
|
-
|
12
9
|
/**
|
13
10
|
* Parse jest config
|
14
11
|
*/
|
@@ -16,16 +13,11 @@ const getJestUtils = testConfig => {
|
|
16
13
|
const testOperator = new _testConfigOperator.TestConfigOperator(testConfig);
|
17
14
|
return testOperator;
|
18
15
|
};
|
19
|
-
|
20
16
|
exports.getJestUtils = getJestUtils;
|
21
|
-
|
22
17
|
const patchConfig = async testOperator => {
|
23
18
|
await (0, _patches.applyPatches)(testOperator);
|
24
19
|
return testOperator.jestConfig;
|
25
20
|
};
|
26
|
-
|
27
21
|
exports.patchConfig = patchConfig;
|
28
|
-
|
29
22
|
const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
30
|
-
|
31
23
|
exports.DEFAULT_RESOLVER_PATH = DEFAULT_RESOLVER_PATH;
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.patchAssetsModule = void 0;
|
7
|
-
|
8
7
|
/**
|
9
8
|
* Merge config from testConfig.jest
|
10
9
|
*/
|
@@ -16,5 +15,4 @@ const patchAssetsModule = testOperator => {
|
|
16
15
|
}
|
17
16
|
});
|
18
17
|
};
|
19
|
-
|
20
18
|
exports.patchAssetsModule = patchAssetsModule;
|
@@ -4,21 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.applyPatches = void 0;
|
7
|
-
|
8
7
|
var _transformer = require("./transformer");
|
9
|
-
|
10
8
|
var _assetsModule = require("./assetsModule");
|
11
|
-
|
12
9
|
const _applyPatches = async (patches, testOperator) => {
|
13
10
|
for (const patch of patches) {
|
14
11
|
await patch(testOperator);
|
15
12
|
}
|
16
13
|
};
|
17
|
-
|
18
14
|
const patches = [_transformer.patchTransformer, _assetsModule.patchAssetsModule];
|
19
|
-
|
20
15
|
const applyPatches = async testConfig => {
|
21
16
|
await _applyPatches(patches, testConfig);
|
22
17
|
};
|
23
|
-
|
24
18
|
exports.applyPatches = applyPatches;
|
@@ -4,32 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.patchTransformer = void 0;
|
7
|
-
|
8
7
|
var _utils = require("../../utils");
|
9
|
-
|
10
8
|
const resolveTsCompilerOptions = () => {
|
11
9
|
const tsCompilerOptions = (0, _utils.readCompilerOptions)() || {};
|
12
10
|
const {
|
13
11
|
jsx
|
14
12
|
} = tsCompilerOptions;
|
15
|
-
|
16
13
|
if (!jsx) {
|
17
14
|
return null;
|
18
15
|
}
|
19
|
-
|
20
16
|
tsCompilerOptions.jsx = 'react-jsx';
|
21
17
|
return tsCompilerOptions;
|
22
18
|
};
|
19
|
+
|
23
20
|
/**
|
24
21
|
* Map `TestConfig.transformer` to jest config
|
25
22
|
*/
|
26
|
-
|
27
|
-
|
28
23
|
const patchTransformer = testOperator => {
|
29
24
|
const {
|
30
25
|
transformer
|
31
26
|
} = testOperator.testConfig;
|
32
|
-
|
33
27
|
if (transformer === 'babel-jest') {
|
34
28
|
testOperator.mergeJestConfig({
|
35
29
|
transform: {
|
@@ -37,7 +31,6 @@ const patchTransformer = testOperator => {
|
|
37
31
|
}
|
38
32
|
});
|
39
33
|
}
|
40
|
-
|
41
34
|
if (transformer === 'ts-jest') {
|
42
35
|
testOperator.mergeJestConfig({
|
43
36
|
transform: {
|
@@ -54,5 +47,4 @@ const patchTransformer = testOperator => {
|
|
54
47
|
});
|
55
48
|
}
|
56
49
|
};
|
57
|
-
|
58
50
|
exports.patchTransformer = patchTransformer;
|
@@ -1,20 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _enhancedResolve = _interopRequireDefault(require("enhanced-resolve"));
|
4
|
-
|
5
4
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
-
|
7
5
|
const resolver = _enhancedResolve.default.create.sync({
|
8
6
|
conditionNames: ['require', 'node', 'default'],
|
9
7
|
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
10
8
|
});
|
11
|
-
|
12
9
|
const shouldResolveByEnhance = url => /^@[^/]+\/[^/]+\/.*/.test(url);
|
13
|
-
|
14
10
|
module.exports = function (request, options) {
|
15
11
|
if (shouldResolveByEnhance(request)) {
|
16
12
|
return resolver(options.basedir, request);
|
17
13
|
}
|
18
|
-
|
19
14
|
return options.defaultResolver(request, options);
|
20
15
|
};
|
@@ -4,90 +4,66 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.TestConfigOperator = void 0;
|
7
|
-
|
8
7
|
var _lodash = require("@modern-js/utils/lodash");
|
9
|
-
|
10
8
|
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; }
|
11
|
-
|
12
9
|
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
|
-
|
14
10
|
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; }
|
15
|
-
|
16
11
|
class TestConfigOperator {
|
17
12
|
constructor(testConfig) {
|
18
13
|
_defineProperty(this, "_testConfig", void 0);
|
19
|
-
|
20
14
|
_defineProperty(this, "_jestConfig", void 0);
|
21
|
-
|
22
15
|
_defineProperty(this, "userJestConfig", void 0);
|
23
|
-
|
24
16
|
_defineProperty(this, "defaultTestConfig", {
|
25
17
|
transformer: 'babel-jest'
|
26
18
|
});
|
27
|
-
|
28
19
|
this._testConfig = testConfig;
|
29
20
|
this._jestConfig = {};
|
30
21
|
this.userJestConfig = testConfig.jest;
|
31
22
|
this.initial();
|
32
23
|
}
|
33
|
-
|
34
24
|
initial() {
|
35
25
|
this._testConfig = (0, _lodash.merge)({}, this.defaultTestConfig, this.testConfig);
|
36
26
|
}
|
37
|
-
|
38
27
|
get jestConfig() {
|
39
28
|
return this._jestConfig;
|
40
29
|
}
|
41
|
-
|
42
30
|
get testConfig() {
|
43
31
|
return this._testConfig;
|
44
32
|
}
|
45
|
-
|
46
33
|
mergeJestConfig(sourceConfig) {
|
47
34
|
this._jestConfig = (0, _lodash.merge)({}, this._jestConfig, sourceConfig);
|
48
35
|
}
|
49
|
-
|
50
36
|
setJestUserConfig() {
|
51
37
|
const {
|
52
38
|
userJestConfig
|
53
39
|
} = this;
|
54
|
-
|
55
40
|
if (typeof userJestConfig === 'object') {
|
56
41
|
this.setJestConfig(userJestConfig);
|
57
42
|
}
|
58
43
|
}
|
59
|
-
|
60
44
|
setJestConfig(sourceConfig, options) {
|
61
45
|
if (options) {
|
62
46
|
const {
|
63
47
|
force
|
64
48
|
} = options;
|
65
|
-
|
66
49
|
if (force) {
|
67
50
|
this._jestConfig = sourceConfig;
|
68
51
|
return;
|
69
52
|
}
|
70
53
|
}
|
71
|
-
|
72
54
|
this._jestConfig = _objectSpread(_objectSpread({}, this._jestConfig), sourceConfig);
|
73
55
|
}
|
74
|
-
|
75
56
|
getFinalConfig() {
|
76
57
|
const {
|
77
58
|
userJestConfig
|
78
59
|
} = this;
|
79
|
-
|
80
60
|
if (!userJestConfig) {
|
81
61
|
return this._jestConfig;
|
82
62
|
}
|
83
|
-
|
84
63
|
if (typeof userJestConfig === 'function') {
|
85
64
|
return userJestConfig(this._jestConfig);
|
86
65
|
}
|
87
|
-
|
88
66
|
return this.jestConfig;
|
89
67
|
}
|
90
|
-
|
91
68
|
}
|
92
|
-
|
93
69
|
exports.TestConfigOperator = TestConfigOperator;
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
-
|
8
7
|
var _babelJest = _interopRequireDefault(require("babel-jest"));
|
9
|
-
|
10
8
|
var _babelJest$createTran;
|
11
|
-
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
-
|
14
10
|
const babelTransformer = (_babelJest$createTran = _babelJest.default.createTransformer) === null || _babelJest$createTran === void 0 ? void 0 : _babelJest$createTran.call(_babelJest.default, {
|
15
11
|
presets: [[require.resolve('@modern-js/babel-preset-app'), {
|
16
12
|
appDirectory: process.cwd(),
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.testingHooks = exports.jestConfigHook = exports.afterTestHook = void 0;
|
7
|
-
|
8
7
|
var _plugin = require("@modern-js/plugin");
|
9
|
-
|
10
8
|
const jestConfigHook = (0, _plugin.createAsyncPipeline)();
|
11
9
|
exports.jestConfigHook = jestConfigHook;
|
12
10
|
const afterTestHook = (0, _plugin.createParallelWorkflow)();
|
@@ -47,19 +47,12 @@ Object.defineProperty(exports, "testingHooks", {
|
|
47
47
|
return _hook.testingHooks;
|
48
48
|
}
|
49
49
|
});
|
50
|
-
|
51
50
|
var _runJest = require("./runJest");
|
52
|
-
|
53
51
|
var _utils = require("./utils");
|
54
|
-
|
55
52
|
var _config = require("./config");
|
56
|
-
|
57
53
|
var _testConfigOperator = require("./config/testConfigOperator");
|
58
|
-
|
59
54
|
var _hook = require("./hook");
|
60
|
-
|
61
55
|
var _types = require("./types");
|
62
|
-
|
63
56
|
Object.keys(_types).forEach(function (key) {
|
64
57
|
if (key === "default" || key === "__esModule") return;
|
65
58
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
@@ -5,19 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.runJest = runJest;
|
7
7
|
exports.runTest = runTest;
|
8
|
-
|
9
8
|
var _yargs = _interopRequireDefault(require("yargs/yargs"));
|
10
|
-
|
11
9
|
var _jest = require("jest");
|
12
|
-
|
13
10
|
var _utils = require("@modern-js/utils");
|
14
|
-
|
15
11
|
var _config = require("./config");
|
16
|
-
|
17
12
|
var _utils2 = require("./utils");
|
18
|
-
|
19
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20
|
-
|
21
14
|
/**
|
22
15
|
* @file run jest by nodejs API
|
23
16
|
* @description
|
@@ -25,6 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
25
18
|
* The followed code is inspired by
|
26
19
|
* https://github.com/facebook/jest/blob/fdc74af37235354e077edeeee8aa2d1a4a863032/packages/jest-cli/src/cli/index.ts#L21
|
27
20
|
*/
|
21
|
+
|
28
22
|
const buildArgv = async (rawArgv, config) => {
|
29
23
|
const argv = await (0, _yargs.default)(rawArgv).argv;
|
30
24
|
const result = {
|
@@ -35,32 +29,28 @@ const buildArgv = async (rawArgv, config) => {
|
|
35
29
|
if (key.includes('-') || key === '_') {
|
36
30
|
return;
|
37
31
|
}
|
38
|
-
|
39
32
|
result[key] = argv[key];
|
40
33
|
});
|
41
|
-
|
42
34
|
if (config) {
|
43
35
|
result.config = JSON.stringify(config);
|
44
36
|
}
|
45
|
-
|
46
37
|
return result;
|
47
38
|
};
|
48
|
-
|
49
39
|
const readResultsAndExit = (result, globalConfig) => {
|
50
|
-
const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
|
40
|
+
const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
|
51
41
|
|
42
|
+
// Only exit if needed
|
52
43
|
process.on('exit', () => {
|
53
44
|
if (typeof code === 'number' && code !== 0) {
|
54
45
|
process.exitCode = code;
|
55
46
|
}
|
56
47
|
});
|
57
|
-
|
58
48
|
if (globalConfig.forceExit) {
|
59
49
|
if (!globalConfig.detectOpenHandles) {
|
60
50
|
console.warn(`${_utils.chalk.bold('Force exiting Jest: ')}Have you considered using \`--detectOpenHandles\` to detect ` + `async operations that kept running after all tests finished?`);
|
61
|
-
}
|
62
|
-
|
51
|
+
}
|
63
52
|
|
53
|
+
// eslint-disable-next-line no-process-exit
|
64
54
|
process.exit(code);
|
65
55
|
} else if (!globalConfig.detectOpenHandles) {
|
66
56
|
setTimeout(() => {
|
@@ -68,11 +58,10 @@ const readResultsAndExit = (result, globalConfig) => {
|
|
68
58
|
}, 1000).unref();
|
69
59
|
}
|
70
60
|
};
|
61
|
+
|
71
62
|
/**
|
72
63
|
* Node API: execute jest
|
73
64
|
*/
|
74
|
-
|
75
|
-
|
76
65
|
async function runJest(config, pwd = process.cwd()) {
|
77
66
|
try {
|
78
67
|
const argvConfig = await buildArgv(process.argv.slice(2), config);
|
@@ -82,21 +71,22 @@ async function runJest(config, pwd = process.cwd()) {
|
|
82
71
|
} = await (0, _jest.runCLI)(argvConfig, [pwd]);
|
83
72
|
readResultsAndExit(results, globalConfig);
|
84
73
|
} catch (e) {
|
85
|
-
console.error(_utils.chalk.red((e === null || e === void 0 ? void 0 : e.stack) || e));
|
74
|
+
console.error(_utils.chalk.red((e === null || e === void 0 ? void 0 : e.stack) || e));
|
86
75
|
|
76
|
+
// eslint-disable-next-line no-process-exit
|
87
77
|
process.exit(1);
|
88
78
|
}
|
89
79
|
}
|
80
|
+
|
90
81
|
/**
|
91
82
|
* Node API: run test
|
92
83
|
*/
|
93
|
-
|
94
|
-
|
95
84
|
async function runTest(api, config, pwd = process.cwd()) {
|
96
85
|
process.env.NODE_ENV = 'test';
|
97
86
|
const jestUtils = (0, _config.getJestUtils)(config);
|
98
|
-
await (0, _config.patchConfig)(jestUtils);
|
87
|
+
await (0, _config.patchConfig)(jestUtils);
|
99
88
|
|
89
|
+
// 确保用户设置的配置可以被插件处理,比如设置在 projects 中
|
100
90
|
jestUtils.setJestUserConfig();
|
101
91
|
const hookRunners = api.useHookRunners();
|
102
92
|
const testConfigOperator = await hookRunners.jestConfig(jestUtils, {
|