@modern-js/plugin-testing 1.5.7-alpha.0 → 1.7.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +61 -22
  2. package/dist/js/modern/base/config/index.js +18 -0
  3. package/dist/js/modern/base/config/patches/assetsModule.js +11 -0
  4. package/dist/js/modern/base/config/patches/filemock.js +1 -0
  5. package/dist/js/modern/base/config/patches/index.js +13 -0
  6. package/dist/js/modern/base/config/patches/transformer.js +49 -0
  7. package/dist/js/modern/base/config/resolver.js +15 -0
  8. package/dist/js/modern/base/config/testConfigOperator.js +86 -0
  9. package/dist/js/modern/base/config/transformer/babelTransformer.js +12 -0
  10. package/dist/js/modern/base/hook.js +7 -0
  11. package/dist/js/modern/base/index.js +6 -0
  12. package/dist/js/modern/base/runJest.js +94 -0
  13. package/dist/js/modern/base/types/index.js +0 -0
  14. package/dist/js/modern/base/utils.js +59 -0
  15. package/dist/js/modern/cli/bff/app.js +22 -0
  16. package/dist/js/modern/cli/bff/constant.js +1 -0
  17. package/dist/js/modern/cli/bff/env.js +28 -0
  18. package/dist/js/modern/cli/bff/index.js +110 -0
  19. package/dist/js/modern/cli/bff/mockAPI.js +109 -0
  20. package/dist/js/modern/cli/bff/setup.js +33 -0
  21. package/dist/js/modern/cli/bff/utils/index.js +25 -0
  22. package/dist/js/modern/cli/index.js +2 -2
  23. package/dist/js/modern/cli/test.js +1 -1
  24. package/dist/js/modern/runtime-testing/base.js +1 -1
  25. package/dist/js/modern/runtime-testing/request.js +17 -0
  26. package/dist/js/node/base/config/index.js +31 -0
  27. package/dist/js/node/base/config/patches/assetsModule.js +20 -0
  28. package/dist/js/node/base/config/patches/filemock.js +8 -0
  29. package/dist/js/node/base/config/patches/index.js +24 -0
  30. package/dist/js/node/base/config/patches/transformer.js +58 -0
  31. package/dist/js/node/base/config/resolver.js +20 -0
  32. package/dist/js/node/base/config/testConfigOperator.js +93 -0
  33. package/dist/js/node/base/config/transformer/babelTransformer.js +23 -0
  34. package/dist/js/node/base/hook.js +18 -0
  35. package/dist/js/node/base/index.js +73 -0
  36. package/dist/js/node/base/runJest.js +109 -0
  37. package/dist/js/node/base/types/index.js +0 -0
  38. package/dist/js/node/base/utils.js +79 -0
  39. package/dist/js/node/cli/bff/app.js +34 -0
  40. package/dist/js/node/cli/bff/constant.js +8 -0
  41. package/dist/js/node/cli/bff/env.js +42 -0
  42. package/dist/js/node/cli/bff/index.js +129 -0
  43. package/dist/js/node/cli/bff/mockAPI.js +124 -0
  44. package/dist/js/node/cli/bff/setup.js +41 -0
  45. package/dist/js/node/cli/bff/utils/index.js +38 -0
  46. package/dist/js/node/cli/index.js +7 -7
  47. package/dist/js/node/cli/test.js +2 -2
  48. package/dist/js/node/runtime-testing/base.js +2 -2
  49. package/dist/js/node/runtime-testing/request.js +24 -0
  50. package/dist/js/treeshaking/base/config/index.js +40 -0
  51. package/dist/js/treeshaking/base/config/patches/assetsModule.js +11 -0
  52. package/dist/js/treeshaking/base/config/patches/filemock.js +1 -0
  53. package/dist/js/treeshaking/base/config/patches/index.js +85 -0
  54. package/dist/js/treeshaking/base/config/patches/transformer.js +45 -0
  55. package/dist/js/treeshaking/base/config/resolver.js +17 -0
  56. package/dist/js/treeshaking/base/config/testConfigOperator.js +91 -0
  57. package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +12 -0
  58. package/dist/js/treeshaking/base/hook.js +7 -0
  59. package/dist/js/treeshaking/base/index.js +6 -0
  60. package/dist/js/treeshaking/base/runJest.js +194 -0
  61. package/dist/js/treeshaking/base/types/index.js +0 -0
  62. package/dist/js/treeshaking/base/utils.js +60 -0
  63. package/dist/js/treeshaking/cli/bff/app.js +47 -0
  64. package/dist/js/treeshaking/cli/bff/constant.js +1 -0
  65. package/dist/js/treeshaking/cli/bff/env.js +98 -0
  66. package/dist/js/treeshaking/cli/bff/index.js +145 -0
  67. package/dist/js/treeshaking/cli/bff/mockAPI.js +113 -0
  68. package/dist/js/treeshaking/cli/bff/setup.js +33 -0
  69. package/dist/js/treeshaking/cli/bff/utils/index.js +22 -0
  70. package/dist/js/treeshaking/cli/index.js +2 -2
  71. package/dist/js/treeshaking/cli/test.js +1 -1
  72. package/dist/js/treeshaking/runtime-testing/base.js +1 -1
  73. package/dist/js/treeshaking/runtime-testing/request.js +24 -0
  74. package/dist/types/base/config/index.d.ts +124 -0
  75. package/dist/types/base/config/patches/assetsModule.d.ts +6 -0
  76. package/dist/types/base/config/patches/filemock.d.ts +3 -0
  77. package/dist/types/base/config/patches/index.d.ts +2 -0
  78. package/dist/types/base/config/patches/transformer.d.ts +6 -0
  79. package/dist/types/base/config/resolver.d.ts +1 -0
  80. package/dist/types/base/config/testConfigOperator.d.ts +248 -0
  81. package/dist/types/base/config/transformer/babelTransformer.d.ts +2 -0
  82. package/dist/types/base/hook.d.ts +13 -0
  83. package/dist/types/base/index.d.ts +6 -0
  84. package/dist/types/base/runJest.d.ts +22 -0
  85. package/dist/types/base/types/index.d.ts +1 -0
  86. package/dist/types/base/utils.d.ts +12 -0
  87. package/dist/types/cli/bff/app.d.ts +6 -0
  88. package/dist/types/cli/bff/constant.d.ts +1 -0
  89. package/dist/types/cli/bff/env.d.ts +6 -0
  90. package/dist/types/cli/bff/index.d.ts +19 -0
  91. package/dist/types/cli/bff/mockAPI.d.ts +3 -0
  92. package/dist/types/cli/bff/setup.d.ts +1 -0
  93. package/dist/types/cli/bff/utils/index.d.ts +1 -0
  94. package/dist/types/cli/index.d.ts +1 -1
  95. package/dist/types/runtime-testing/base.d.ts +1 -1
  96. package/dist/types/runtime-testing/request.d.ts +4 -0
  97. package/package.json +38 -11
@@ -16,7 +16,7 @@ Object.defineProperty(exports, "renderApp", {
16
16
  Object.defineProperty(exports, "testBff", {
17
17
  enumerable: true,
18
18
  get: function () {
19
- return _testingPluginBff.testBff;
19
+ return _request.request;
20
20
  }
21
21
  });
22
22
 
@@ -36,6 +36,6 @@ Object.keys(_react).forEach(function (key) {
36
36
  });
37
37
  });
38
38
 
39
- var _testingPluginBff = require("@modern-js/testing-plugin-bff");
39
+ var _request = require("./request");
40
40
 
41
41
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.request = request;
7
+
8
+ var _supertest = _interopRequireDefault(require("supertest"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ /* eslint-disable eslint-comments/disable-enable-pair */
13
+ function request(...args) {
14
+ const [fn, ...extraArgs] = args;
15
+
16
+ if (!fn) {
17
+ return (0, _supertest.default)(global.app);
18
+ }
19
+
20
+ fn.returnHttp = true;
21
+ const res = fn(...extraArgs);
22
+ fn.returnHttp = false;
23
+ return res;
24
+ }
@@ -0,0 +1,40 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import { applyPatches } from "./patches";
4
+ import { TestConfigOperator } from "./testConfigOperator";
5
+ /**
6
+ * Parse jest config
7
+ */
8
+
9
+ var getJestUtils = function getJestUtils(testConfig) {
10
+ var testOperator = new TestConfigOperator(testConfig);
11
+ return testOperator;
12
+ };
13
+
14
+ var patchConfig = /*#__PURE__*/function () {
15
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(testOperator) {
16
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
17
+ while (1) {
18
+ switch (_context.prev = _context.next) {
19
+ case 0:
20
+ _context.next = 2;
21
+ return applyPatches(testOperator);
22
+
23
+ case 2:
24
+ return _context.abrupt("return", testOperator.jestConfig);
25
+
26
+ case 3:
27
+ case "end":
28
+ return _context.stop();
29
+ }
30
+ }
31
+ }, _callee);
32
+ }));
33
+
34
+ return function patchConfig(_x) {
35
+ return _ref.apply(this, arguments);
36
+ };
37
+ }();
38
+
39
+ export var DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
40
+ export { getJestUtils, patchConfig };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Merge config from testConfig.jest
3
+ */
4
+ export var patchAssetsModule = function patchAssetsModule(testOperator) {
5
+ testOperator.mergeJestConfig({
6
+ moduleNameMapper: {
7
+ '\\.(css|less|scss|sass)$': require.resolve('identity-obj-proxy'),
8
+ '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': require.resolve("./filemock.js")
9
+ }
10
+ });
11
+ };
@@ -0,0 +1 @@
1
+ export default 'test-file-stub';
@@ -0,0 +1,85 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
+ import { patchTransformer } from "./transformer";
5
+ import { patchAssetsModule } from "./assetsModule";
6
+
7
+ var _applyPatches = /*#__PURE__*/function () {
8
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(patches, testOperator) {
9
+ var _iterator, _step, patch;
10
+
11
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
12
+ while (1) {
13
+ switch (_context.prev = _context.next) {
14
+ case 0:
15
+ _iterator = _createForOfIteratorHelper(patches);
16
+ _context.prev = 1;
17
+
18
+ _iterator.s();
19
+
20
+ case 3:
21
+ if ((_step = _iterator.n()).done) {
22
+ _context.next = 9;
23
+ break;
24
+ }
25
+
26
+ patch = _step.value;
27
+ _context.next = 7;
28
+ return patch(testOperator);
29
+
30
+ case 7:
31
+ _context.next = 3;
32
+ break;
33
+
34
+ case 9:
35
+ _context.next = 14;
36
+ break;
37
+
38
+ case 11:
39
+ _context.prev = 11;
40
+ _context.t0 = _context["catch"](1);
41
+
42
+ _iterator.e(_context.t0);
43
+
44
+ case 14:
45
+ _context.prev = 14;
46
+
47
+ _iterator.f();
48
+
49
+ return _context.finish(14);
50
+
51
+ case 17:
52
+ case "end":
53
+ return _context.stop();
54
+ }
55
+ }
56
+ }, _callee, null, [[1, 11, 14, 17]]);
57
+ }));
58
+
59
+ return function _applyPatches(_x, _x2) {
60
+ return _ref.apply(this, arguments);
61
+ };
62
+ }();
63
+
64
+ var patches = [patchTransformer, patchAssetsModule];
65
+ export var applyPatches = /*#__PURE__*/function () {
66
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(testConfig) {
67
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
68
+ while (1) {
69
+ switch (_context2.prev = _context2.next) {
70
+ case 0:
71
+ _context2.next = 2;
72
+ return _applyPatches(patches, testConfig);
73
+
74
+ case 2:
75
+ case "end":
76
+ return _context2.stop();
77
+ }
78
+ }
79
+ }, _callee2);
80
+ }));
81
+
82
+ return function applyPatches(_x3) {
83
+ return _ref2.apply(this, arguments);
84
+ };
85
+ }();
@@ -0,0 +1,45 @@
1
+ import { readCompilerOptions } from "../../utils";
2
+
3
+ var resolveTsCompilerOptions = function resolveTsCompilerOptions() {
4
+ var tsCompilerOptions = readCompilerOptions() || {};
5
+ var jsx = tsCompilerOptions.jsx;
6
+
7
+ if (!jsx) {
8
+ return null;
9
+ }
10
+
11
+ tsCompilerOptions.jsx = 'react-jsx';
12
+ return tsCompilerOptions;
13
+ };
14
+ /**
15
+ * Map `TestConfig.transformer` to jest config
16
+ */
17
+
18
+
19
+ export var patchTransformer = function patchTransformer(testOperator) {
20
+ var transformer = testOperator.testConfig.transformer;
21
+
22
+ if (transformer === 'babel-jest') {
23
+ testOperator.mergeJestConfig({
24
+ transform: {
25
+ '\\.[jt]sx?$': require.resolve("../transformer/babelTransformer")
26
+ }
27
+ });
28
+ }
29
+
30
+ if (transformer === 'ts-jest') {
31
+ testOperator.mergeJestConfig({
32
+ transform: {
33
+ '\\.[jt]sx?$': require.resolve('ts-jest')
34
+ }
35
+ });
36
+ var compilerOptions = resolveTsCompilerOptions();
37
+ compilerOptions && testOperator.mergeJestConfig({
38
+ globals: {
39
+ 'ts-jest': {
40
+ tsconfig: compilerOptions
41
+ }
42
+ }
43
+ });
44
+ }
45
+ };
@@ -0,0 +1,17 @@
1
+ import enhanceResolve from 'enhanced-resolve';
2
+ var resolver = enhanceResolve.create.sync({
3
+ conditionNames: ['require', 'node', 'default'],
4
+ extensions: ['.js', '.json', '.node', '.ts', '.tsx']
5
+ });
6
+
7
+ var shouldResolveByEnhance = function shouldResolveByEnhance(url) {
8
+ return /^@[^/]+\/[^/]+\/.*/.test(url);
9
+ };
10
+
11
+ module.exports = function (request, options) {
12
+ if (shouldResolveByEnhance(request)) {
13
+ return resolver(options.basedir, request);
14
+ }
15
+
16
+ return options.defaultResolver(request, options);
17
+ };
@@ -0,0 +1,91 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
3
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
5
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
+ import { merge } from '@modern-js/utils/lodash';
7
+
8
+ var TestConfigOperator = /*#__PURE__*/function () {
9
+ function TestConfigOperator(testConfig) {
10
+ _classCallCheck(this, TestConfigOperator);
11
+
12
+ _defineProperty(this, "_testConfig", void 0);
13
+
14
+ _defineProperty(this, "_jestConfig", void 0);
15
+
16
+ _defineProperty(this, "userJestConfig", void 0);
17
+
18
+ _defineProperty(this, "defaultTestConfig", {
19
+ transformer: 'babel-jest'
20
+ });
21
+
22
+ this._testConfig = testConfig;
23
+ this._jestConfig = {};
24
+ this.userJestConfig = testConfig.jest;
25
+ this.initial();
26
+ }
27
+
28
+ _createClass(TestConfigOperator, [{
29
+ key: "initial",
30
+ value: function initial() {
31
+ this._testConfig = merge({}, this.defaultTestConfig, this.testConfig);
32
+ }
33
+ }, {
34
+ key: "jestConfig",
35
+ get: function get() {
36
+ return this._jestConfig;
37
+ }
38
+ }, {
39
+ key: "testConfig",
40
+ get: function get() {
41
+ return this._testConfig;
42
+ }
43
+ }, {
44
+ key: "mergeJestConfig",
45
+ value: function mergeJestConfig(sourceConfig) {
46
+ this._jestConfig = merge({}, this._jestConfig, sourceConfig);
47
+ }
48
+ }, {
49
+ key: "setJestUserConfig",
50
+ value: function setJestUserConfig() {
51
+ var userJestConfig = this.userJestConfig;
52
+
53
+ if (_typeof(userJestConfig) === 'object') {
54
+ this.setJestConfig(userJestConfig);
55
+ }
56
+ }
57
+ }, {
58
+ key: "setJestConfig",
59
+ value: function setJestConfig(sourceConfig, options) {
60
+ if (options) {
61
+ var force = options.force;
62
+
63
+ if (force) {
64
+ this._jestConfig = sourceConfig;
65
+ return;
66
+ }
67
+ }
68
+
69
+ this._jestConfig = _objectSpread(_objectSpread({}, this._jestConfig), sourceConfig);
70
+ }
71
+ }, {
72
+ key: "getFinalConfig",
73
+ value: function getFinalConfig() {
74
+ var userJestConfig = this.userJestConfig;
75
+
76
+ if (!userJestConfig) {
77
+ return this._jestConfig;
78
+ }
79
+
80
+ if (typeof userJestConfig === 'function') {
81
+ return userJestConfig(this._jestConfig);
82
+ }
83
+
84
+ return this.jestConfig;
85
+ }
86
+ }]);
87
+
88
+ return TestConfigOperator;
89
+ }();
90
+
91
+ export { TestConfigOperator };
@@ -0,0 +1,12 @@
1
+ var _babelJest$createTran;
2
+
3
+ import babelJest from 'babel-jest';
4
+ var babelTransformer = (_babelJest$createTran = babelJest.createTransformer) === null || _babelJest$createTran === void 0 ? void 0 : _babelJest$createTran.call(babelJest, {
5
+ presets: [[require.resolve('@modern-js/babel-preset-app'), {
6
+ appDirectory: process.cwd(),
7
+ modules: 'cjs'
8
+ }]],
9
+ configFile: false,
10
+ babelrc: false
11
+ });
12
+ export default babelTransformer;
@@ -0,0 +1,7 @@
1
+ import { createAsyncPipeline, createParallelWorkflow } from '@modern-js/plugin';
2
+ export var jestConfigHook = createAsyncPipeline();
3
+ export var afterTestHook = createParallelWorkflow();
4
+ export var testingHooks = {
5
+ jestConfig: createAsyncPipeline(),
6
+ afterTest: createParallelWorkflow()
7
+ };
@@ -0,0 +1,6 @@
1
+ export { runTest, runJest } from "./runJest";
2
+ export { getModuleNameMapper } from "./utils";
3
+ export { DEFAULT_RESOLVER_PATH } from "./config";
4
+ export { TestConfigOperator } from "./config/testConfigOperator";
5
+ export { testingHooks } from "./hook";
6
+ export * from "./types";
@@ -0,0 +1,194 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+
4
+ /**
5
+ * @file run jest by nodejs API
6
+ * @description
7
+ * Jest does not provide node API to run jest.
8
+ * The followed code is inspired by
9
+ * https://github.com/facebook/jest/blob/fdc74af37235354e077edeeee8aa2d1a4a863032/packages/jest-cli/src/cli/index.ts#L21
10
+ */
11
+ import yargs from 'yargs/yargs';
12
+ import { runCLI } from 'jest';
13
+ import { chalk } from '@modern-js/utils';
14
+ import { getJestUtils, patchConfig } from "./config";
15
+ import { debug } from "./utils";
16
+
17
+ var buildArgv = /*#__PURE__*/function () {
18
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(rawArgv, config) {
19
+ var argv, result;
20
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
21
+ while (1) {
22
+ switch (_context.prev = _context.next) {
23
+ case 0:
24
+ _context.next = 2;
25
+ return yargs(rawArgv).argv;
26
+
27
+ case 2:
28
+ argv = _context.sent;
29
+ result = {
30
+ $0: argv.$0,
31
+ _: argv._.slice(1)
32
+ };
33
+ Object.keys(argv).forEach(function (key) {
34
+ if (key.includes('-') || key === '_') {
35
+ return;
36
+ }
37
+
38
+ result[key] = argv[key];
39
+ });
40
+
41
+ if (config) {
42
+ result.config = JSON.stringify(config);
43
+ }
44
+
45
+ return _context.abrupt("return", result);
46
+
47
+ case 7:
48
+ case "end":
49
+ return _context.stop();
50
+ }
51
+ }
52
+ }, _callee);
53
+ }));
54
+
55
+ return function buildArgv(_x, _x2) {
56
+ return _ref.apply(this, arguments);
57
+ };
58
+ }();
59
+
60
+ var readResultsAndExit = function readResultsAndExit(result, globalConfig) {
61
+ var code = !result || result.success ? 0 : globalConfig.testFailureExitCode; // Only exit if needed
62
+
63
+ process.on('exit', function () {
64
+ if (typeof code === 'number' && code !== 0) {
65
+ process.exitCode = code;
66
+ }
67
+ });
68
+
69
+ if (globalConfig.forceExit) {
70
+ if (!globalConfig.detectOpenHandles) {
71
+ console.warn("".concat(chalk.bold('Force exiting Jest: '), "Have you considered using `--detectOpenHandles` to detect ") + "async operations that kept running after all tests finished?");
72
+ } // eslint-disable-next-line no-process-exit
73
+
74
+
75
+ process.exit(code);
76
+ } else if (!globalConfig.detectOpenHandles) {
77
+ setTimeout(function () {
78
+ console.warn(chalk.yellow.bold('Jest did not exit one second after the test run has completed.\n\n') + chalk.yellow('This usually means that there are asynchronous operations that ' + "weren't stopped in your tests. Consider running Jest with " + '`--detectOpenHandles` to troubleshoot this issue.'));
79
+ }, 1000).unref();
80
+ }
81
+ };
82
+ /**
83
+ * Node API: execute jest
84
+ */
85
+
86
+
87
+ export function runJest(_x3) {
88
+ return _runJest.apply(this, arguments);
89
+ }
90
+ /**
91
+ * Node API: run test
92
+ */
93
+
94
+ function _runJest() {
95
+ _runJest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(config) {
96
+ var pwd,
97
+ argvConfig,
98
+ _yield$runCLI,
99
+ results,
100
+ globalConfig,
101
+ _args2 = arguments;
102
+
103
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
104
+ while (1) {
105
+ switch (_context2.prev = _context2.next) {
106
+ case 0:
107
+ pwd = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : process.cwd();
108
+ _context2.prev = 1;
109
+ _context2.next = 4;
110
+ return buildArgv(process.argv.slice(2), config);
111
+
112
+ case 4:
113
+ argvConfig = _context2.sent;
114
+ _context2.next = 7;
115
+ return runCLI(argvConfig, [pwd]);
116
+
117
+ case 7:
118
+ _yield$runCLI = _context2.sent;
119
+ results = _yield$runCLI.results;
120
+ globalConfig = _yield$runCLI.globalConfig;
121
+ readResultsAndExit(results, globalConfig);
122
+ _context2.next = 17;
123
+ break;
124
+
125
+ case 13:
126
+ _context2.prev = 13;
127
+ _context2.t0 = _context2["catch"](1);
128
+ console.error(chalk.red((_context2.t0 === null || _context2.t0 === void 0 ? void 0 : _context2.t0.stack) || _context2.t0)); // eslint-disable-next-line no-process-exit
129
+
130
+ process.exit(1);
131
+
132
+ case 17:
133
+ case "end":
134
+ return _context2.stop();
135
+ }
136
+ }
137
+ }, _callee2, null, [[1, 13]]);
138
+ }));
139
+ return _runJest.apply(this, arguments);
140
+ }
141
+
142
+ export function runTest(_x4, _x5) {
143
+ return _runTest.apply(this, arguments);
144
+ }
145
+
146
+ function _runTest() {
147
+ _runTest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(api, config) {
148
+ var pwd,
149
+ jestUtils,
150
+ hookRunners,
151
+ testConfigOperator,
152
+ finalConfig,
153
+ _args3 = arguments;
154
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
155
+ while (1) {
156
+ switch (_context3.prev = _context3.next) {
157
+ case 0:
158
+ pwd = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : process.cwd();
159
+ process.env.NODE_ENV = 'test';
160
+ jestUtils = getJestUtils(config);
161
+ _context3.next = 5;
162
+ return patchConfig(jestUtils);
163
+
164
+ case 5:
165
+ // 确保用户设置的配置可以被插件处理,比如设置在 projects 中
166
+ jestUtils.setJestUserConfig();
167
+ hookRunners = api.useHookRunners();
168
+ _context3.next = 9;
169
+ return hookRunners.jestConfig(jestUtils, {
170
+ onLast: function onLast(input) {
171
+ return input;
172
+ }
173
+ });
174
+
175
+ case 9:
176
+ testConfigOperator = _context3.sent;
177
+ finalConfig = testConfigOperator.getFinalConfig();
178
+ debug('Jest config:', finalConfig);
179
+ _context3.next = 14;
180
+ return runJest(finalConfig, pwd);
181
+
182
+ case 14:
183
+ _context3.next = 16;
184
+ return hookRunners.afterTest();
185
+
186
+ case 16:
187
+ case "end":
188
+ return _context3.stop();
189
+ }
190
+ }
191
+ }, _callee3);
192
+ }));
193
+ return _runTest.apply(this, arguments);
194
+ }
File without changes
@@ -0,0 +1,60 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { createDebugger } from '@modern-js/utils';
5
+ export var debug = createDebugger('test');
6
+
7
+ /**
8
+ * Read `compilerOptions` in the current pwd's tsconfig.json file
9
+ */
10
+ export var readCompilerOptions = function readCompilerOptions() {
11
+ var pwd = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : process.cwd();
12
+ var filename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'tsconfig.json';
13
+ var tsConfig = {};
14
+ var extendedCompilerOptions = {};
15
+ var tsconfigFile = '';
16
+
17
+ try {
18
+ var maybeTsconfigFile = path.join(pwd, filename);
19
+
20
+ if (fs.existsSync(maybeTsconfigFile)) {
21
+ tsconfigFile = maybeTsconfigFile;
22
+ } else {
23
+ tsconfigFile = require.resolve(filename);
24
+ }
25
+
26
+ var _require$parseConfigF = require('typescript').parseConfigFileTextToJson(tsconfigFile, fs.readFileSync(tsconfigFile, 'utf8'));
27
+
28
+ tsConfig = _require$parseConfigF.config;
29
+ } catch (e) {
30
+ return {};
31
+ }
32
+
33
+ if (tsConfig["extends"]) {
34
+ extendedCompilerOptions = readCompilerOptions(path.dirname(tsconfigFile), tsConfig["extends"]);
35
+ }
36
+
37
+ return _objectSpread(_objectSpread({}, extendedCompilerOptions), tsConfig.compilerOptions);
38
+ };
39
+ export var getModuleNameMapper = function getModuleNameMapper(alias) {
40
+ return Object.keys(alias).reduce(function (memo, cur) {
41
+ var aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
42
+ var isFile = aliasValue.some(function (s) {
43
+ return s.endsWith('.js');
44
+ }); // It's special for if using @modern-js/runtime alias other module @modern-js/runtime/model would not work.
45
+
46
+ if (cur === '@modern-js/runtime$') {
47
+ memo[".+".concat(cur)] = aliasValue[0];
48
+ return memo;
49
+ }
50
+
51
+ if (isFile) {
52
+ memo[cur] = aliasValue[0];
53
+ }
54
+
55
+ var key = "^".concat(cur, "/(.*)$");
56
+ var value = path.normalize("".concat(aliasValue, "/$1"));
57
+ memo[key] = value;
58
+ return memo;
59
+ }, {});
60
+ };
@@ -0,0 +1,47 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import { AsyncLocalStorage } from 'async_hooks';
4
+ import { Server } from '@modern-js/server';
5
+ var store = new AsyncLocalStorage();
6
+ export var isInHandler = function isInHandler() {
7
+ return Boolean(store.getStore());
8
+ };
9
+
10
+ var createApp = /*#__PURE__*/function () {
11
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(pwd, config, plugins, routes) {
12
+ var server;
13
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
14
+ while (1) {
15
+ switch (_context.prev = _context.next) {
16
+ case 0:
17
+ config.output.path = './';
18
+ server = new Server({
19
+ apiOnly: true,
20
+ dev: {
21
+ watch: false
22
+ },
23
+ pwd: pwd,
24
+ config: config,
25
+ plugins: plugins,
26
+ routes: routes
27
+ });
28
+ _context.next = 4;
29
+ return server.init();
30
+
31
+ case 4:
32
+ return _context.abrupt("return", server.getRequestHandler());
33
+
34
+ case 5:
35
+ case "end":
36
+ return _context.stop();
37
+ }
38
+ }
39
+ }, _callee);
40
+ }));
41
+
42
+ return function createApp(_x, _x2, _x3, _x4) {
43
+ return _ref.apply(this, arguments);
44
+ };
45
+ }();
46
+
47
+ export { createApp };
@@ -0,0 +1 @@
1
+ export var bff_info_key = 'modern_bff_info';