@modern-js/plugin-testing 1.5.7 → 1.7.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/dist/js/modern/base/config/index.js +18 -0
- package/dist/js/modern/base/config/patches/assetsModule.js +11 -0
- package/dist/js/modern/base/config/patches/filemock.js +1 -0
- package/dist/js/modern/base/config/patches/index.js +13 -0
- package/dist/js/modern/base/config/patches/transformer.js +49 -0
- package/dist/js/modern/base/config/resolver.js +15 -0
- package/dist/js/modern/base/config/testConfigOperator.js +86 -0
- package/dist/js/modern/base/config/transformer/babelTransformer.js +12 -0
- package/dist/js/modern/base/hook.js +7 -0
- package/dist/js/modern/base/index.js +6 -0
- package/dist/js/modern/base/runJest.js +94 -0
- package/dist/js/modern/base/types/index.js +0 -0
- package/dist/js/modern/base/utils.js +59 -0
- package/dist/js/modern/cli/bff/app.js +43 -0
- package/dist/js/modern/cli/bff/constant.js +1 -0
- package/dist/js/modern/cli/bff/env.js +28 -0
- package/dist/js/modern/cli/bff/index.js +113 -0
- package/dist/js/modern/cli/bff/mockAPI.js +111 -0
- package/dist/js/modern/cli/bff/setup.js +44 -0
- package/dist/js/modern/cli/bff/utils/index.js +25 -0
- package/dist/js/modern/cli/index.js +2 -2
- package/dist/js/modern/cli/test.js +1 -1
- package/dist/js/modern/runtime-testing/app.js +1 -1
- package/dist/js/modern/runtime-testing/base.js +1 -1
- package/dist/js/modern/runtime-testing/request.js +17 -0
- package/dist/js/node/base/config/index.js +31 -0
- package/dist/js/node/base/config/patches/assetsModule.js +20 -0
- package/dist/js/node/base/config/patches/filemock.js +8 -0
- package/dist/js/node/base/config/patches/index.js +24 -0
- package/dist/js/node/base/config/patches/transformer.js +58 -0
- package/dist/js/node/base/config/resolver.js +20 -0
- package/dist/js/node/base/config/testConfigOperator.js +93 -0
- package/dist/js/node/base/config/transformer/babelTransformer.js +23 -0
- package/dist/js/node/base/hook.js +18 -0
- package/dist/js/node/base/index.js +73 -0
- package/dist/js/node/base/runJest.js +109 -0
- package/dist/js/node/base/types/index.js +0 -0
- package/dist/js/node/base/utils.js +79 -0
- package/dist/js/node/cli/bff/app.js +59 -0
- package/dist/js/node/cli/bff/constant.js +8 -0
- package/dist/js/node/cli/bff/env.js +42 -0
- package/dist/js/node/cli/bff/index.js +132 -0
- package/dist/js/node/cli/bff/mockAPI.js +126 -0
- package/dist/js/node/cli/bff/setup.js +53 -0
- package/dist/js/node/cli/bff/utils/index.js +38 -0
- package/dist/js/node/cli/index.js +7 -7
- package/dist/js/node/cli/test.js +2 -2
- package/dist/js/node/runtime-testing/app.js +2 -2
- package/dist/js/node/runtime-testing/base.js +2 -2
- package/dist/js/node/runtime-testing/request.js +24 -0
- package/dist/js/treeshaking/base/config/index.js +40 -0
- package/dist/js/treeshaking/base/config/patches/assetsModule.js +11 -0
- package/dist/js/treeshaking/base/config/patches/filemock.js +1 -0
- package/dist/js/treeshaking/base/config/patches/index.js +85 -0
- package/dist/js/treeshaking/base/config/patches/transformer.js +45 -0
- package/dist/js/treeshaking/base/config/resolver.js +17 -0
- package/dist/js/treeshaking/base/config/testConfigOperator.js +91 -0
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +12 -0
- package/dist/js/treeshaking/base/hook.js +7 -0
- package/dist/js/treeshaking/base/index.js +6 -0
- package/dist/js/treeshaking/base/runJest.js +194 -0
- package/dist/js/treeshaking/base/types/index.js +0 -0
- package/dist/js/treeshaking/base/utils.js +60 -0
- package/dist/js/treeshaking/cli/bff/app.js +92 -0
- package/dist/js/treeshaking/cli/bff/constant.js +1 -0
- package/dist/js/treeshaking/cli/bff/env.js +98 -0
- package/dist/js/treeshaking/cli/bff/index.js +149 -0
- package/dist/js/treeshaking/cli/bff/mockAPI.js +115 -0
- package/dist/js/treeshaking/cli/bff/setup.js +76 -0
- package/dist/js/treeshaking/cli/bff/utils/index.js +22 -0
- package/dist/js/treeshaking/cli/index.js +2 -2
- package/dist/js/treeshaking/cli/test.js +1 -1
- package/dist/js/treeshaking/runtime-testing/app.js +1 -1
- package/dist/js/treeshaking/runtime-testing/base.js +1 -1
- package/dist/js/treeshaking/runtime-testing/request.js +24 -0
- package/dist/types/base/config/index.d.ts +124 -0
- package/dist/types/base/config/patches/assetsModule.d.ts +6 -0
- package/dist/types/base/config/patches/filemock.d.ts +3 -0
- package/dist/types/base/config/patches/index.d.ts +2 -0
- package/dist/types/base/config/patches/transformer.d.ts +6 -0
- package/dist/types/base/config/resolver.d.ts +1 -0
- package/dist/types/base/config/testConfigOperator.d.ts +248 -0
- package/dist/types/base/config/transformer/babelTransformer.d.ts +2 -0
- package/dist/types/base/hook.d.ts +13 -0
- package/dist/types/base/index.d.ts +6 -0
- package/dist/types/base/runJest.d.ts +22 -0
- package/dist/types/base/types/index.d.ts +1 -0
- package/dist/types/base/utils.d.ts +12 -0
- package/dist/types/cli/bff/app.d.ts +8 -0
- package/dist/types/cli/bff/constant.d.ts +1 -0
- package/dist/types/cli/bff/env.d.ts +6 -0
- package/dist/types/cli/bff/index.d.ts +19 -0
- package/dist/types/cli/bff/mockAPI.d.ts +3 -0
- package/dist/types/cli/bff/setup.d.ts +1 -0
- package/dist/types/cli/bff/utils/index.d.ts +1 -0
- package/dist/types/cli/index.d.ts +1 -1
- package/dist/types/runtime-testing/base.d.ts +1 -1
- package/dist/types/runtime-testing/request.d.ts +4 -0
- package/package.json +47 -11
@@ -0,0 +1,111 @@
|
|
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
|
+
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
|
+
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
|
+
import * as ptr from 'path-to-regexp';
|
8
|
+
import * as mockAppModule from "./app"; // eslint-disable-next-line @typescript-eslint/naming-convention
|
9
|
+
|
10
|
+
const mock_replaceUrlWithParams = (url, paramValues, payload) => {
|
11
|
+
const keys = [];
|
12
|
+
ptr.pathToRegexp(url, keys);
|
13
|
+
const params = keys.reduce((cur, key, index) => {
|
14
|
+
if (paramValues[index]) {
|
15
|
+
cur[key.name] = paramValues[index];
|
16
|
+
}
|
17
|
+
|
18
|
+
return cur;
|
19
|
+
}, {});
|
20
|
+
const getFinalPath = ptr.compile(url, {
|
21
|
+
encode: encodeURIComponent
|
22
|
+
});
|
23
|
+
return getFinalPath(_objectSpread(_objectSpread({}, params), payload));
|
24
|
+
}; // eslint-disable-next-line @typescript-eslint/naming-convention
|
25
|
+
|
26
|
+
|
27
|
+
const mock_getParamsAndPayload = args => {
|
28
|
+
if (args.length === 0) {
|
29
|
+
return [[], {}];
|
30
|
+
}
|
31
|
+
|
32
|
+
const head = args[0];
|
33
|
+
|
34
|
+
if (typeof head === 'object') {
|
35
|
+
return [[], head];
|
36
|
+
} else {
|
37
|
+
const latest = args[args.length - 1];
|
38
|
+
|
39
|
+
if (typeof latest === 'object') {
|
40
|
+
return [args.slice(0, args.length - 1), latest];
|
41
|
+
} else {
|
42
|
+
return [args, {}];
|
43
|
+
}
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
export default (mockApiInfosByFile => {
|
48
|
+
const files = Object.keys(mockApiInfosByFile);
|
49
|
+
files.forEach(mockedFile => {
|
50
|
+
jest.mock(mockedFile, () => {
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
52
|
+
const supertest = require('supertest');
|
53
|
+
|
54
|
+
return mockApiInfosByFile[mockedFile].reduce((res, info) => {
|
55
|
+
const module = {
|
56
|
+
[info.name]: (...args) => {
|
57
|
+
if (mockAppModule.isInHandler()) {
|
58
|
+
return info.handler(...args);
|
59
|
+
}
|
60
|
+
|
61
|
+
const [params, payload] = mock_getParamsAndPayload(args);
|
62
|
+
const {
|
63
|
+
returnHttp
|
64
|
+
} = module[info.name];
|
65
|
+
const url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
|
66
|
+
const app = mockAppModule.getApp();
|
67
|
+
let test = supertest(app)[info.httpMethod.toLowerCase()](url);
|
68
|
+
|
69
|
+
if (payload.query) {
|
70
|
+
test = test.query(payload.query);
|
71
|
+
}
|
72
|
+
|
73
|
+
if (payload.body) {
|
74
|
+
test = test.send(payload.body);
|
75
|
+
}
|
76
|
+
|
77
|
+
if (payload.data) {
|
78
|
+
test = test.send(payload.data);
|
79
|
+
}
|
80
|
+
|
81
|
+
if (payload.headers) {
|
82
|
+
for (const name in payload.headers) {
|
83
|
+
test = test.set(name, payload.headers[name]);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
if (payload.cookies) {
|
88
|
+
test = test.set('Cookie', [payload.cookies]);
|
89
|
+
}
|
90
|
+
|
91
|
+
if (returnHttp) {
|
92
|
+
return test;
|
93
|
+
}
|
94
|
+
|
95
|
+
return test.then(value => {
|
96
|
+
try {
|
97
|
+
return JSON.parse(value.text);
|
98
|
+
} catch (_unused) {
|
99
|
+
return value.text;
|
100
|
+
}
|
101
|
+
});
|
102
|
+
}
|
103
|
+
};
|
104
|
+
res[info.name] = module[info.name];
|
105
|
+
Object.assign(res[info.name], info.handler);
|
106
|
+
res.__esModule = true;
|
107
|
+
return res;
|
108
|
+
}, {});
|
109
|
+
});
|
110
|
+
});
|
111
|
+
});
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import path from 'path';
|
2
|
+
import { ApiRouter } from '@modern-js/bff-core';
|
3
|
+
import { bff_info_key } from "./constant";
|
4
|
+
import mockAPI from "./mockAPI";
|
5
|
+
import { createApp, closeServer } from "./app";
|
6
|
+
let uped = false;
|
7
|
+
const BEFORE_ALL_TIMEOUT = 30000;
|
8
|
+
|
9
|
+
const setup = () => {
|
10
|
+
var _bff_info$modernUserC, _bff_info$modernUserC2;
|
11
|
+
|
12
|
+
if (uped) {
|
13
|
+
return;
|
14
|
+
}
|
15
|
+
|
16
|
+
uped = true;
|
17
|
+
const bff_info = global[bff_info_key];
|
18
|
+
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;
|
19
|
+
const apiRouter = new ApiRouter({
|
20
|
+
apiDir: path.join(bff_info.appDir, './api'),
|
21
|
+
prefix
|
22
|
+
});
|
23
|
+
const apiInfos = apiRouter.getApiHandlers();
|
24
|
+
const apiInfosByFile = apiInfos.reduce((res, apiInfo) => {
|
25
|
+
if (!res[apiInfo.filename]) {
|
26
|
+
res[apiInfo.filename] = [];
|
27
|
+
}
|
28
|
+
|
29
|
+
res[apiInfo.filename].push(apiInfo);
|
30
|
+
return res;
|
31
|
+
}, {});
|
32
|
+
let app = null;
|
33
|
+
beforeAll(async () => {
|
34
|
+
if (!app) {
|
35
|
+
app = await createApp(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes);
|
36
|
+
}
|
37
|
+
}, BEFORE_ALL_TIMEOUT);
|
38
|
+
afterAll(async () => {
|
39
|
+
await closeServer();
|
40
|
+
});
|
41
|
+
mockAPI(apiInfosByFile);
|
42
|
+
};
|
43
|
+
|
44
|
+
setup();
|
@@ -0,0 +1,25 @@
|
|
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
|
+
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
|
+
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
|
+
import path from 'path';
|
8
|
+
import { chalk } from '@modern-js/utils';
|
9
|
+
export const isBFFProject = pwd => {
|
10
|
+
try {
|
11
|
+
const packageJson = require(path.join(pwd, './package.json'));
|
12
|
+
|
13
|
+
const {
|
14
|
+
dependencies,
|
15
|
+
devDependencies
|
16
|
+
} = packageJson;
|
17
|
+
const isBFF = Object.keys(_objectSpread(_objectSpread({}, dependencies), devDependencies)).some(dependency => dependency.includes('plugin-bff'));
|
18
|
+
const isMWA = Object.keys(devDependencies).some(devDependency => devDependency.includes('app-tools'));
|
19
|
+
return isMWA && isBFF;
|
20
|
+
} catch (error) {
|
21
|
+
// eslint-disable-next-line no-console
|
22
|
+
console.log(chalk.red(error));
|
23
|
+
return false;
|
24
|
+
}
|
25
|
+
};
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import path from 'path';
|
2
2
|
import { PLUGIN_SCHEMAS, createRuntimeExportsUtils, isApiOnly } from '@modern-js/utils';
|
3
|
-
import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from '@modern-js/testing';
|
4
3
|
import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
|
5
|
-
import
|
4
|
+
import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../base";
|
6
5
|
import { MODERNJS_CONFIG_KEY } from "../constant";
|
6
|
+
import TestingBffPlugin from "./bff";
|
7
7
|
import test from "./test";
|
8
8
|
export const mergeUserJestConfig = testUtils => {
|
9
9
|
const resolveJestConfig = testUtils.testConfig.jest; // resolveJestConfig 如果是函数类型,在所有测试插件 jestConfig 都执行后,再执行生成最终配置
|
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
4
4
|
|
5
5
|
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
6
|
|
7
|
-
import { createApp } from '@modern-js/runtime
|
7
|
+
import { createApp } from '@modern-js/runtime';
|
8
8
|
import { MODERNJS_CONFIG_KEY } from "../constant";
|
9
9
|
import resolvePlugins from "./resolvePlugins";
|
10
10
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/* eslint-disable eslint-comments/disable-enable-pair */
|
2
|
+
import supertest from 'supertest';
|
3
|
+
|
4
|
+
function request(...args) {
|
5
|
+
const [fn, ...extraArgs] = args;
|
6
|
+
|
7
|
+
if (!fn) {
|
8
|
+
return supertest(global.app);
|
9
|
+
}
|
10
|
+
|
11
|
+
fn.returnHttp = true;
|
12
|
+
const res = fn(...extraArgs);
|
13
|
+
fn.returnHttp = false;
|
14
|
+
return res;
|
15
|
+
}
|
16
|
+
|
17
|
+
export { request };
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.patchConfig = exports.getJestUtils = exports.DEFAULT_RESOLVER_PATH = void 0;
|
7
|
+
|
8
|
+
var _patches = require("./patches");
|
9
|
+
|
10
|
+
var _testConfigOperator = require("./testConfigOperator");
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Parse jest config
|
14
|
+
*/
|
15
|
+
const getJestUtils = testConfig => {
|
16
|
+
const testOperator = new _testConfigOperator.TestConfigOperator(testConfig);
|
17
|
+
return testOperator;
|
18
|
+
};
|
19
|
+
|
20
|
+
exports.getJestUtils = getJestUtils;
|
21
|
+
|
22
|
+
const patchConfig = async testOperator => {
|
23
|
+
await (0, _patches.applyPatches)(testOperator);
|
24
|
+
return testOperator.jestConfig;
|
25
|
+
};
|
26
|
+
|
27
|
+
exports.patchConfig = patchConfig;
|
28
|
+
|
29
|
+
const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
30
|
+
|
31
|
+
exports.DEFAULT_RESOLVER_PATH = DEFAULT_RESOLVER_PATH;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.patchAssetsModule = void 0;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Merge config from testConfig.jest
|
10
|
+
*/
|
11
|
+
const patchAssetsModule = testOperator => {
|
12
|
+
testOperator.mergeJestConfig({
|
13
|
+
moduleNameMapper: {
|
14
|
+
'\\.(css|less|scss|sass)$': require.resolve('identity-obj-proxy'),
|
15
|
+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': require.resolve("./filemock.js")
|
16
|
+
}
|
17
|
+
});
|
18
|
+
};
|
19
|
+
|
20
|
+
exports.patchAssetsModule = patchAssetsModule;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.applyPatches = void 0;
|
7
|
+
|
8
|
+
var _transformer = require("./transformer");
|
9
|
+
|
10
|
+
var _assetsModule = require("./assetsModule");
|
11
|
+
|
12
|
+
const _applyPatches = async (patches, testOperator) => {
|
13
|
+
for (const patch of patches) {
|
14
|
+
await patch(testOperator);
|
15
|
+
}
|
16
|
+
};
|
17
|
+
|
18
|
+
const patches = [_transformer.patchTransformer, _assetsModule.patchAssetsModule];
|
19
|
+
|
20
|
+
const applyPatches = async testConfig => {
|
21
|
+
await _applyPatches(patches, testConfig);
|
22
|
+
};
|
23
|
+
|
24
|
+
exports.applyPatches = applyPatches;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.patchTransformer = void 0;
|
7
|
+
|
8
|
+
var _utils = require("../../utils");
|
9
|
+
|
10
|
+
const resolveTsCompilerOptions = () => {
|
11
|
+
const tsCompilerOptions = (0, _utils.readCompilerOptions)() || {};
|
12
|
+
const {
|
13
|
+
jsx
|
14
|
+
} = tsCompilerOptions;
|
15
|
+
|
16
|
+
if (!jsx) {
|
17
|
+
return null;
|
18
|
+
}
|
19
|
+
|
20
|
+
tsCompilerOptions.jsx = 'react-jsx';
|
21
|
+
return tsCompilerOptions;
|
22
|
+
};
|
23
|
+
/**
|
24
|
+
* Map `TestConfig.transformer` to jest config
|
25
|
+
*/
|
26
|
+
|
27
|
+
|
28
|
+
const patchTransformer = testOperator => {
|
29
|
+
const {
|
30
|
+
transformer
|
31
|
+
} = testOperator.testConfig;
|
32
|
+
|
33
|
+
if (transformer === 'babel-jest') {
|
34
|
+
testOperator.mergeJestConfig({
|
35
|
+
transform: {
|
36
|
+
'\\.[jt]sx?$': require.resolve("../transformer/babelTransformer")
|
37
|
+
}
|
38
|
+
});
|
39
|
+
}
|
40
|
+
|
41
|
+
if (transformer === 'ts-jest') {
|
42
|
+
testOperator.mergeJestConfig({
|
43
|
+
transform: {
|
44
|
+
'\\.[jt]sx?$': require.resolve('ts-jest')
|
45
|
+
}
|
46
|
+
});
|
47
|
+
const compilerOptions = resolveTsCompilerOptions();
|
48
|
+
compilerOptions && testOperator.mergeJestConfig({
|
49
|
+
globals: {
|
50
|
+
'ts-jest': {
|
51
|
+
tsconfig: compilerOptions
|
52
|
+
}
|
53
|
+
}
|
54
|
+
});
|
55
|
+
}
|
56
|
+
};
|
57
|
+
|
58
|
+
exports.patchTransformer = patchTransformer;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _enhancedResolve = _interopRequireDefault(require("enhanced-resolve"));
|
4
|
+
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
+
|
7
|
+
const resolver = _enhancedResolve.default.create.sync({
|
8
|
+
conditionNames: ['require', 'node', 'default'],
|
9
|
+
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
10
|
+
});
|
11
|
+
|
12
|
+
const shouldResolveByEnhance = url => /^@[^/]+\/[^/]+\/.*/.test(url);
|
13
|
+
|
14
|
+
module.exports = function (request, options) {
|
15
|
+
if (shouldResolveByEnhance(request)) {
|
16
|
+
return resolver(options.basedir, request);
|
17
|
+
}
|
18
|
+
|
19
|
+
return options.defaultResolver(request, options);
|
20
|
+
};
|
@@ -0,0 +1,93 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.TestConfigOperator = void 0;
|
7
|
+
|
8
|
+
var _lodash = require("@modern-js/utils/lodash");
|
9
|
+
|
10
|
+
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
|
+
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
|
+
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
|
+
class TestConfigOperator {
|
17
|
+
constructor(testConfig) {
|
18
|
+
_defineProperty(this, "_testConfig", void 0);
|
19
|
+
|
20
|
+
_defineProperty(this, "_jestConfig", void 0);
|
21
|
+
|
22
|
+
_defineProperty(this, "userJestConfig", void 0);
|
23
|
+
|
24
|
+
_defineProperty(this, "defaultTestConfig", {
|
25
|
+
transformer: 'babel-jest'
|
26
|
+
});
|
27
|
+
|
28
|
+
this._testConfig = testConfig;
|
29
|
+
this._jestConfig = {};
|
30
|
+
this.userJestConfig = testConfig.jest;
|
31
|
+
this.initial();
|
32
|
+
}
|
33
|
+
|
34
|
+
initial() {
|
35
|
+
this._testConfig = (0, _lodash.merge)({}, this.defaultTestConfig, this.testConfig);
|
36
|
+
}
|
37
|
+
|
38
|
+
get jestConfig() {
|
39
|
+
return this._jestConfig;
|
40
|
+
}
|
41
|
+
|
42
|
+
get testConfig() {
|
43
|
+
return this._testConfig;
|
44
|
+
}
|
45
|
+
|
46
|
+
mergeJestConfig(sourceConfig) {
|
47
|
+
this._jestConfig = (0, _lodash.merge)({}, this._jestConfig, sourceConfig);
|
48
|
+
}
|
49
|
+
|
50
|
+
setJestUserConfig() {
|
51
|
+
const {
|
52
|
+
userJestConfig
|
53
|
+
} = this;
|
54
|
+
|
55
|
+
if (typeof userJestConfig === 'object') {
|
56
|
+
this.setJestConfig(userJestConfig);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
setJestConfig(sourceConfig, options) {
|
61
|
+
if (options) {
|
62
|
+
const {
|
63
|
+
force
|
64
|
+
} = options;
|
65
|
+
|
66
|
+
if (force) {
|
67
|
+
this._jestConfig = sourceConfig;
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
this._jestConfig = _objectSpread(_objectSpread({}, this._jestConfig), sourceConfig);
|
73
|
+
}
|
74
|
+
|
75
|
+
getFinalConfig() {
|
76
|
+
const {
|
77
|
+
userJestConfig
|
78
|
+
} = this;
|
79
|
+
|
80
|
+
if (!userJestConfig) {
|
81
|
+
return this._jestConfig;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (typeof userJestConfig === 'function') {
|
85
|
+
return userJestConfig(this._jestConfig);
|
86
|
+
}
|
87
|
+
|
88
|
+
return this.jestConfig;
|
89
|
+
}
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
exports.TestConfigOperator = TestConfigOperator;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _babelJest = _interopRequireDefault(require("babel-jest"));
|
9
|
+
|
10
|
+
var _babelJest$createTran;
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
14
|
+
const babelTransformer = (_babelJest$createTran = _babelJest.default.createTransformer) === null || _babelJest$createTran === void 0 ? void 0 : _babelJest$createTran.call(_babelJest.default, {
|
15
|
+
presets: [[require.resolve('@modern-js/babel-preset-app'), {
|
16
|
+
appDirectory: process.cwd(),
|
17
|
+
modules: 'cjs'
|
18
|
+
}]],
|
19
|
+
configFile: false,
|
20
|
+
babelrc: false
|
21
|
+
});
|
22
|
+
var _default = babelTransformer;
|
23
|
+
exports.default = _default;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.testingHooks = exports.jestConfigHook = exports.afterTestHook = void 0;
|
7
|
+
|
8
|
+
var _plugin = require("@modern-js/plugin");
|
9
|
+
|
10
|
+
const jestConfigHook = (0, _plugin.createAsyncPipeline)();
|
11
|
+
exports.jestConfigHook = jestConfigHook;
|
12
|
+
const afterTestHook = (0, _plugin.createParallelWorkflow)();
|
13
|
+
exports.afterTestHook = afterTestHook;
|
14
|
+
const testingHooks = {
|
15
|
+
jestConfig: (0, _plugin.createAsyncPipeline)(),
|
16
|
+
afterTest: (0, _plugin.createParallelWorkflow)()
|
17
|
+
};
|
18
|
+
exports.testingHooks = testingHooks;
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
var _exportNames = {
|
7
|
+
runTest: true,
|
8
|
+
runJest: true,
|
9
|
+
getModuleNameMapper: true,
|
10
|
+
DEFAULT_RESOLVER_PATH: true,
|
11
|
+
TestConfigOperator: true,
|
12
|
+
testingHooks: true
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "DEFAULT_RESOLVER_PATH", {
|
15
|
+
enumerable: true,
|
16
|
+
get: function () {
|
17
|
+
return _config.DEFAULT_RESOLVER_PATH;
|
18
|
+
}
|
19
|
+
});
|
20
|
+
Object.defineProperty(exports, "TestConfigOperator", {
|
21
|
+
enumerable: true,
|
22
|
+
get: function () {
|
23
|
+
return _testConfigOperator.TestConfigOperator;
|
24
|
+
}
|
25
|
+
});
|
26
|
+
Object.defineProperty(exports, "getModuleNameMapper", {
|
27
|
+
enumerable: true,
|
28
|
+
get: function () {
|
29
|
+
return _utils.getModuleNameMapper;
|
30
|
+
}
|
31
|
+
});
|
32
|
+
Object.defineProperty(exports, "runJest", {
|
33
|
+
enumerable: true,
|
34
|
+
get: function () {
|
35
|
+
return _runJest.runJest;
|
36
|
+
}
|
37
|
+
});
|
38
|
+
Object.defineProperty(exports, "runTest", {
|
39
|
+
enumerable: true,
|
40
|
+
get: function () {
|
41
|
+
return _runJest.runTest;
|
42
|
+
}
|
43
|
+
});
|
44
|
+
Object.defineProperty(exports, "testingHooks", {
|
45
|
+
enumerable: true,
|
46
|
+
get: function () {
|
47
|
+
return _hook.testingHooks;
|
48
|
+
}
|
49
|
+
});
|
50
|
+
|
51
|
+
var _runJest = require("./runJest");
|
52
|
+
|
53
|
+
var _utils = require("./utils");
|
54
|
+
|
55
|
+
var _config = require("./config");
|
56
|
+
|
57
|
+
var _testConfigOperator = require("./config/testConfigOperator");
|
58
|
+
|
59
|
+
var _hook = require("./hook");
|
60
|
+
|
61
|
+
var _types = require("./types");
|
62
|
+
|
63
|
+
Object.keys(_types).forEach(function (key) {
|
64
|
+
if (key === "default" || key === "__esModule") return;
|
65
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
66
|
+
if (key in exports && exports[key] === _types[key]) return;
|
67
|
+
Object.defineProperty(exports, key, {
|
68
|
+
enumerable: true,
|
69
|
+
get: function () {
|
70
|
+
return _types[key];
|
71
|
+
}
|
72
|
+
});
|
73
|
+
});
|