@modern-js/plugin-testing 2.0.0-beta.0 → 2.0.0-beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. package/CHANGELOG.md +109 -0
  2. package/dist/js/modern/base/config/index.js +1 -3
  3. package/dist/js/modern/base/config/patches/index.js +0 -2
  4. package/dist/js/modern/base/config/patches/transformer.js +1 -7
  5. package/dist/js/modern/base/config/resolver.js +0 -3
  6. package/dist/js/modern/base/config/testConfigOperator.js +0 -23
  7. package/dist/js/modern/base/config/transformer/babelTransformer.js +0 -1
  8. package/dist/js/modern/base/runJest.js +11 -14
  9. package/dist/js/modern/base/utils.js +2 -12
  10. package/dist/js/modern/cli/bff/app.js +0 -7
  11. package/dist/js/modern/cli/bff/index.js +4 -15
  12. package/dist/js/modern/cli/bff/mockAPI.js +4 -20
  13. package/dist/js/modern/cli/bff/setup.js +0 -5
  14. package/dist/js/modern/cli/bff/utils/index.js +0 -4
  15. package/dist/js/modern/cli/index.js +2 -9
  16. package/dist/js/modern/cli/test.js +0 -4
  17. package/dist/js/modern/runtime-testing/app.js +0 -15
  18. package/dist/js/modern/runtime-testing/customRender.js +0 -6
  19. package/dist/js/modern/runtime-testing/reduck.js +0 -10
  20. package/dist/js/modern/runtime-testing/request.js +1 -4
  21. package/dist/js/modern/runtime-testing/resolvePlugins.js +0 -6
  22. package/dist/js/node/base/config/index.js +0 -8
  23. package/dist/js/node/base/config/patches/assetsModule.js +0 -2
  24. package/dist/js/node/base/config/patches/index.js +0 -6
  25. package/dist/js/node/base/config/patches/transformer.js +1 -9
  26. package/dist/js/node/base/config/resolver.js +0 -5
  27. package/dist/js/node/base/config/testConfigOperator.js +0 -24
  28. package/dist/js/node/base/config/transformer/babelTransformer.js +0 -4
  29. package/dist/js/node/base/hook.js +0 -2
  30. package/dist/js/node/base/index.js +0 -7
  31. package/dist/js/node/base/runJest.js +11 -21
  32. package/dist/js/node/base/utils.js +2 -22
  33. package/dist/js/node/cli/bff/app.js +0 -14
  34. package/dist/js/node/cli/bff/index.js +4 -25
  35. package/dist/js/node/cli/bff/mockAPI.js +2 -25
  36. package/dist/js/node/cli/bff/setup.js +0 -11
  37. package/dist/js/node/cli/bff/utils/index.js +0 -9
  38. package/dist/js/node/cli/index.js +2 -21
  39. package/dist/js/node/cli/test.js +0 -10
  40. package/dist/js/node/index.js +0 -4
  41. package/dist/js/node/runtime-testing/app.js +0 -20
  42. package/dist/js/node/runtime-testing/base.js +0 -5
  43. package/dist/js/node/runtime-testing/customRender.js +0 -10
  44. package/dist/js/node/runtime-testing/index.js +0 -4
  45. package/dist/js/node/runtime-testing/reduck.js +0 -24
  46. package/dist/js/node/runtime-testing/request.js +1 -6
  47. package/dist/js/node/runtime-testing/resolvePlugins.js +0 -8
  48. package/dist/js/treeshaking/base/config/index.js +1 -6
  49. package/dist/js/treeshaking/base/config/patches/index.js +0 -17
  50. package/dist/js/treeshaking/base/config/patches/transformer.js +1 -7
  51. package/dist/js/treeshaking/base/config/resolver.js +0 -3
  52. package/dist/js/treeshaking/base/config/testConfigOperator.js +0 -15
  53. package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +0 -1
  54. package/dist/js/treeshaking/base/runJest.js +19 -38
  55. package/dist/js/treeshaking/base/utils.js +2 -10
  56. package/dist/js/treeshaking/cli/bff/app.js +0 -13
  57. package/dist/js/treeshaking/cli/bff/index.js +0 -16
  58. package/dist/js/treeshaking/cli/bff/mockAPI.js +8 -24
  59. package/dist/js/treeshaking/cli/bff/setup.js +0 -9
  60. package/dist/js/treeshaking/cli/bff/utils/index.js +1 -2
  61. package/dist/js/treeshaking/cli/index.js +2 -11
  62. package/dist/js/treeshaking/cli/test.js +0 -7
  63. package/dist/js/treeshaking/runtime-testing/app.js +2 -15
  64. package/dist/js/treeshaking/runtime-testing/customRender.js +0 -3
  65. package/dist/js/treeshaking/runtime-testing/reduck.js +0 -7
  66. package/dist/js/treeshaking/runtime-testing/request.js +2 -7
  67. package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +0 -3
  68. package/dist/types/base/config/index.d.ts +10 -1
  69. package/dist/types/base/config/patches/assetsModule.d.ts +0 -1
  70. package/dist/types/base/config/patches/filemock.d.ts +0 -1
  71. package/dist/types/base/config/patches/transformer.d.ts +0 -1
  72. package/dist/types/base/config/testConfigOperator.d.ts +1 -117
  73. package/dist/types/base/hook.d.ts +4 -6
  74. package/dist/types/base/runJest.d.ts +7 -3
  75. package/dist/types/base/utils.d.ts +0 -1
  76. package/dist/types/cli/bff/index.d.ts +7 -3
  77. package/dist/types/cli/bff/mockAPI.d.ts +0 -1
  78. package/dist/types/cli/index.d.ts +7 -3
  79. package/dist/types/cli/test.d.ts +7 -1
  80. package/dist/types/runtime-testing/app.d.ts +12 -5
  81. package/dist/types/runtime-testing/customRender.d.ts +0 -2
  82. package/dist/types/runtime-testing/resolvePlugins.d.ts +5 -1
  83. package/package.json +18 -18
@@ -4,65 +4,41 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.immer = exports.effects = exports.createStore = exports.autoActions = void 0;
7
-
8
7
  var _store = require("@modern-js-reduck/store");
9
-
10
8
  var _pluginEffects = _interopRequireDefault(require("@modern-js-reduck/plugin-effects"));
11
-
12
9
  var _pluginAutoActions = _interopRequireDefault(require("@modern-js-reduck/plugin-auto-actions"));
13
-
14
10
  var _pluginImmutable = _interopRequireDefault(require("@modern-js-reduck/plugin-immutable"));
15
-
16
11
  var _constant = require("../constant");
17
-
18
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
13
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
-
22
14
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
-
24
15
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
-
26
16
  const effects = () => _pluginEffects.default;
27
-
28
17
  exports.effects = effects;
29
-
30
18
  const immer = () => _pluginImmutable.default;
31
-
32
19
  exports.immer = immer;
33
-
34
20
  const autoActions = () => _pluginAutoActions.default;
35
-
36
21
  exports.autoActions = autoActions;
37
-
38
22
  const createStore = props => {
39
23
  const createStatePlugins = () => {
40
24
  var _modernConfig$runtime;
41
-
42
25
  const modernConfig = global[_constant.MODERNJS_CONFIG_KEY];
43
26
  const stateConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig$runtime = modernConfig.runtime) === null || _modernConfig$runtime === void 0 ? void 0 : _modernConfig$runtime.state;
44
27
  const plugins = [];
45
-
46
28
  if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.effects) !== false) {
47
29
  plugins.push(effects());
48
30
  }
49
-
50
31
  if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.autoActions) !== false) {
51
32
  plugins.push(autoActions());
52
33
  }
53
-
54
34
  if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.immer) !== false) {
55
35
  plugins.push(immer());
56
36
  }
57
-
58
37
  return ((props === null || props === void 0 ? void 0 : props.plugins) || []).concat(plugins);
59
38
  };
60
-
61
39
  const config = _objectSpread(_objectSpread({}, props || {}), {}, {
62
40
  plugins: createStatePlugins()
63
41
  });
64
-
65
42
  return (0, _store.createStore)(config);
66
43
  };
67
-
68
44
  exports.createStore = createStore;
@@ -4,22 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.request = request;
7
-
8
7
  var _supertest = _interopRequireDefault(require("supertest"));
9
-
10
8
  var _app = require("../cli/bff/app");
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  /* eslint-disable eslint-comments/disable-enable-pair */
11
+
15
12
  function request(...args) {
16
13
  const [fn, ...extraArgs] = args;
17
14
  const app = (0, _app.getApp)();
18
-
19
15
  if (!fn) {
20
16
  return (0, _supertest.default)(app);
21
17
  }
22
-
23
18
  fn.returnHttp = true;
24
19
  const res = fn(...extraArgs);
25
20
  fn.returnHttp = false;
@@ -4,26 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = resolvePlugins;
7
-
8
7
  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; }
9
-
10
8
  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; }
11
-
12
9
  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; }
13
-
14
10
  const allowedFeatures = ['router', 'state'];
15
-
16
11
  function resolvePlugins(features) {
17
12
  const plugins = [];
18
-
19
13
  if (!features) {
20
14
  return plugins;
21
15
  }
22
-
23
16
  Object.keys(features).forEach(feature => {
24
17
  if (allowedFeatures.includes(feature)) {
25
18
  const curPluginRes = require(`@modern-js/runtime/plugins`)[feature](_objectSpread({}, features[feature]));
26
-
27
19
  plugins.push(curPluginRes);
28
20
  }
29
21
  });
@@ -2,15 +2,14 @@ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import { applyPatches } from "./patches";
4
4
  import { TestConfigOperator } from "./testConfigOperator";
5
+
5
6
  /**
6
7
  * Parse jest config
7
8
  */
8
-
9
9
  var getJestUtils = function getJestUtils(testConfig) {
10
10
  var testOperator = new TestConfigOperator(testConfig);
11
11
  return testOperator;
12
12
  };
13
-
14
13
  var patchConfig = /*#__PURE__*/function () {
15
14
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(testOperator) {
16
15
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -19,10 +18,8 @@ var patchConfig = /*#__PURE__*/function () {
19
18
  case 0:
20
19
  _context.next = 2;
21
20
  return applyPatches(testOperator);
22
-
23
21
  case 2:
24
22
  return _context.abrupt("return", testOperator.jestConfig);
25
-
26
23
  case 3:
27
24
  case "end":
28
25
  return _context.stop();
@@ -30,11 +27,9 @@ var patchConfig = /*#__PURE__*/function () {
30
27
  }
31
28
  }, _callee);
32
29
  }));
33
-
34
30
  return function patchConfig(_x) {
35
31
  return _ref.apply(this, arguments);
36
32
  };
37
33
  }();
38
-
39
34
  export var DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
40
35
  export { getJestUtils, patchConfig };
@@ -3,51 +3,38 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
3
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
4
  import { patchTransformer } from "./transformer";
5
5
  import { patchAssetsModule } from "./assetsModule";
6
-
7
6
  var _applyPatches = /*#__PURE__*/function () {
8
7
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(patches, testOperator) {
9
8
  var _iterator, _step, patch;
10
-
11
9
  return _regeneratorRuntime().wrap(function _callee$(_context) {
12
10
  while (1) {
13
11
  switch (_context.prev = _context.next) {
14
12
  case 0:
15
13
  _iterator = _createForOfIteratorHelper(patches);
16
14
  _context.prev = 1;
17
-
18
15
  _iterator.s();
19
-
20
16
  case 3:
21
17
  if ((_step = _iterator.n()).done) {
22
18
  _context.next = 9;
23
19
  break;
24
20
  }
25
-
26
21
  patch = _step.value;
27
22
  _context.next = 7;
28
23
  return patch(testOperator);
29
-
30
24
  case 7:
31
25
  _context.next = 3;
32
26
  break;
33
-
34
27
  case 9:
35
28
  _context.next = 14;
36
29
  break;
37
-
38
30
  case 11:
39
31
  _context.prev = 11;
40
32
  _context.t0 = _context["catch"](1);
41
-
42
33
  _iterator.e(_context.t0);
43
-
44
34
  case 14:
45
35
  _context.prev = 14;
46
-
47
36
  _iterator.f();
48
-
49
37
  return _context.finish(14);
50
-
51
38
  case 17:
52
39
  case "end":
53
40
  return _context.stop();
@@ -55,12 +42,10 @@ var _applyPatches = /*#__PURE__*/function () {
55
42
  }
56
43
  }, _callee, null, [[1, 11, 14, 17]]);
57
44
  }));
58
-
59
45
  return function _applyPatches(_x, _x2) {
60
46
  return _ref.apply(this, arguments);
61
47
  };
62
48
  }();
63
-
64
49
  var patches = [patchTransformer, patchAssetsModule];
65
50
  export var applyPatches = /*#__PURE__*/function () {
66
51
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(testConfig) {
@@ -70,7 +55,6 @@ export var applyPatches = /*#__PURE__*/function () {
70
55
  case 0:
71
56
  _context2.next = 2;
72
57
  return _applyPatches(patches, testConfig);
73
-
74
58
  case 2:
75
59
  case "end":
76
60
  return _context2.stop();
@@ -78,7 +62,6 @@ export var applyPatches = /*#__PURE__*/function () {
78
62
  }
79
63
  }, _callee2);
80
64
  }));
81
-
82
65
  return function applyPatches(_x3) {
83
66
  return _ref2.apply(this, arguments);
84
67
  };
@@ -1,24 +1,19 @@
1
1
  import { readCompilerOptions } from "../../utils";
2
-
3
2
  var resolveTsCompilerOptions = function resolveTsCompilerOptions() {
4
3
  var tsCompilerOptions = readCompilerOptions() || {};
5
4
  var jsx = tsCompilerOptions.jsx;
6
-
7
5
  if (!jsx) {
8
6
  return null;
9
7
  }
10
-
11
8
  tsCompilerOptions.jsx = 'react-jsx';
12
9
  return tsCompilerOptions;
13
10
  };
11
+
14
12
  /**
15
13
  * Map `TestConfig.transformer` to jest config
16
14
  */
17
-
18
-
19
15
  export var patchTransformer = function patchTransformer(testOperator) {
20
16
  var transformer = testOperator.testConfig.transformer;
21
-
22
17
  if (transformer === 'babel-jest') {
23
18
  testOperator.mergeJestConfig({
24
19
  transform: {
@@ -26,7 +21,6 @@ export var patchTransformer = function patchTransformer(testOperator) {
26
21
  }
27
22
  });
28
23
  }
29
-
30
24
  if (transformer === 'ts-jest') {
31
25
  testOperator.mergeJestConfig({
32
26
  transform: {
@@ -3,15 +3,12 @@ var resolver = enhanceResolve.create.sync({
3
3
  conditionNames: ['require', 'node', 'default'],
4
4
  extensions: ['.js', '.json', '.node', '.ts', '.tsx']
5
5
  });
6
-
7
6
  var shouldResolveByEnhance = function shouldResolveByEnhance(url) {
8
7
  return /^@[^/]+\/[^/]+\/.*/.test(url);
9
8
  };
10
-
11
9
  module.exports = function (request, options) {
12
10
  if (shouldResolveByEnhance(request)) {
13
11
  return resolver(options.basedir, request);
14
12
  }
15
-
16
13
  return options.defaultResolver(request, options);
17
14
  };
@@ -4,27 +4,20 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
4
  import _createClass from "@babel/runtime/helpers/esm/createClass";
5
5
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
6
  import { merge } from '@modern-js/utils/lodash';
7
-
8
7
  var TestConfigOperator = /*#__PURE__*/function () {
9
8
  function TestConfigOperator(testConfig) {
10
9
  _classCallCheck(this, TestConfigOperator);
11
-
12
10
  _defineProperty(this, "_testConfig", void 0);
13
-
14
11
  _defineProperty(this, "_jestConfig", void 0);
15
-
16
12
  _defineProperty(this, "userJestConfig", void 0);
17
-
18
13
  _defineProperty(this, "defaultTestConfig", {
19
14
  transformer: 'babel-jest'
20
15
  });
21
-
22
16
  this._testConfig = testConfig;
23
17
  this._jestConfig = {};
24
18
  this.userJestConfig = testConfig.jest;
25
19
  this.initial();
26
20
  }
27
-
28
21
  _createClass(TestConfigOperator, [{
29
22
  key: "initial",
30
23
  value: function initial() {
@@ -49,7 +42,6 @@ var TestConfigOperator = /*#__PURE__*/function () {
49
42
  key: "setJestUserConfig",
50
43
  value: function setJestUserConfig() {
51
44
  var userJestConfig = this.userJestConfig;
52
-
53
45
  if (_typeof(userJestConfig) === 'object') {
54
46
  this.setJestConfig(userJestConfig);
55
47
  }
@@ -59,33 +51,26 @@ var TestConfigOperator = /*#__PURE__*/function () {
59
51
  value: function setJestConfig(sourceConfig, options) {
60
52
  if (options) {
61
53
  var force = options.force;
62
-
63
54
  if (force) {
64
55
  this._jestConfig = sourceConfig;
65
56
  return;
66
57
  }
67
58
  }
68
-
69
59
  this._jestConfig = _objectSpread(_objectSpread({}, this._jestConfig), sourceConfig);
70
60
  }
71
61
  }, {
72
62
  key: "getFinalConfig",
73
63
  value: function getFinalConfig() {
74
64
  var userJestConfig = this.userJestConfig;
75
-
76
65
  if (!userJestConfig) {
77
66
  return this._jestConfig;
78
67
  }
79
-
80
68
  if (typeof userJestConfig === 'function') {
81
69
  return userJestConfig(this._jestConfig);
82
70
  }
83
-
84
71
  return this.jestConfig;
85
72
  }
86
73
  }]);
87
-
88
74
  return TestConfigOperator;
89
75
  }();
90
-
91
76
  export { TestConfigOperator };
@@ -1,5 +1,4 @@
1
1
  var _babelJest$createTran;
2
-
3
2
  import babelJest from 'babel-jest';
4
3
  var babelTransformer = (_babelJest$createTran = babelJest.createTransformer) === null || _babelJest$createTran === void 0 ? void 0 : _babelJest$createTran.call(babelJest, {
5
4
  presets: [[require.resolve('@modern-js/babel-preset-app'), {
@@ -1,6 +1,5 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
-
4
3
  /**
5
4
  * @file run jest by nodejs API
6
5
  * @description
@@ -8,12 +7,12 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
8
7
  * The followed code is inspired by
9
8
  * https://github.com/facebook/jest/blob/fdc74af37235354e077edeeee8aa2d1a4a863032/packages/jest-cli/src/cli/index.ts#L21
10
9
  */
10
+
11
11
  import yargs from 'yargs/yargs';
12
12
  import { runCLI } from 'jest';
13
13
  import { chalk } from '@modern-js/utils';
14
14
  import { getJestUtils, patchConfig } from "./config";
15
15
  import { debug } from "./utils";
16
-
17
16
  var buildArgv = /*#__PURE__*/function () {
18
17
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(rawArgv, config) {
19
18
  var argv, result;
@@ -23,7 +22,6 @@ var buildArgv = /*#__PURE__*/function () {
23
22
  case 0:
24
23
  _context.next = 2;
25
24
  return yargs(rawArgv).argv;
26
-
27
25
  case 2:
28
26
  argv = _context.sent;
29
27
  result = {
@@ -34,16 +32,12 @@ var buildArgv = /*#__PURE__*/function () {
34
32
  if (key.includes('-') || key === '_') {
35
33
  return;
36
34
  }
37
-
38
35
  result[key] = argv[key];
39
36
  });
40
-
41
37
  if (config) {
42
38
  result.config = JSON.stringify(config);
43
39
  }
44
-
45
40
  return _context.abrupt("return", result);
46
-
47
41
  case 7:
48
42
  case "end":
49
43
  return _context.stop();
@@ -51,27 +45,25 @@ var buildArgv = /*#__PURE__*/function () {
51
45
  }
52
46
  }, _callee);
53
47
  }));
54
-
55
48
  return function buildArgv(_x, _x2) {
56
49
  return _ref.apply(this, arguments);
57
50
  };
58
51
  }();
59
-
60
52
  var readResultsAndExit = function readResultsAndExit(result, globalConfig) {
61
- var code = !result || result.success ? 0 : globalConfig.testFailureExitCode; // Only exit if needed
53
+ var code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
62
54
 
55
+ // Only exit if needed
63
56
  process.on('exit', function () {
64
57
  if (typeof code === 'number' && code !== 0) {
65
58
  process.exitCode = code;
66
59
  }
67
60
  });
68
-
69
61
  if (globalConfig.forceExit) {
70
62
  if (!globalConfig.detectOpenHandles) {
71
63
  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
-
64
+ }
74
65
 
66
+ // eslint-disable-next-line no-process-exit
75
67
  process.exit(code);
76
68
  } else if (!globalConfig.detectOpenHandles) {
77
69
  setTimeout(function () {
@@ -79,27 +71,25 @@ var readResultsAndExit = function readResultsAndExit(result, globalConfig) {
79
71
  }, 1000).unref();
80
72
  }
81
73
  };
74
+
82
75
  /**
83
76
  * Node API: execute jest
84
77
  */
85
-
86
-
87
78
  export function runJest(_x3) {
88
79
  return _runJest.apply(this, arguments);
89
80
  }
81
+
90
82
  /**
91
83
  * Node API: run test
92
84
  */
93
-
94
85
  function _runJest() {
95
86
  _runJest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(config) {
96
87
  var pwd,
97
- argvConfig,
98
- _yield$runCLI,
99
- results,
100
- globalConfig,
101
- _args2 = arguments;
102
-
88
+ argvConfig,
89
+ _yield$runCLI,
90
+ results,
91
+ globalConfig,
92
+ _args2 = arguments;
103
93
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
104
94
  while (1) {
105
95
  switch (_context2.prev = _context2.next) {
@@ -108,12 +98,10 @@ function _runJest() {
108
98
  _context2.prev = 1;
109
99
  _context2.next = 4;
110
100
  return buildArgv(process.argv.slice(2), config);
111
-
112
101
  case 4:
113
102
  argvConfig = _context2.sent;
114
103
  _context2.next = 7;
115
104
  return runCLI(argvConfig, [pwd]);
116
-
117
105
  case 7:
118
106
  _yield$runCLI = _context2.sent;
119
107
  results = _yield$runCLI.results;
@@ -121,14 +109,13 @@ function _runJest() {
121
109
  readResultsAndExit(results, globalConfig);
122
110
  _context2.next = 17;
123
111
  break;
124
-
125
112
  case 13:
126
113
  _context2.prev = 13;
127
114
  _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
115
+ console.error(chalk.red((_context2.t0 === null || _context2.t0 === void 0 ? void 0 : _context2.t0.stack) || _context2.t0));
129
116
 
117
+ // eslint-disable-next-line no-process-exit
130
118
  process.exit(1);
131
-
132
119
  case 17:
133
120
  case "end":
134
121
  return _context2.stop();
@@ -138,19 +125,17 @@ function _runJest() {
138
125
  }));
139
126
  return _runJest.apply(this, arguments);
140
127
  }
141
-
142
128
  export function runTest(_x4, _x5) {
143
129
  return _runTest.apply(this, arguments);
144
130
  }
145
-
146
131
  function _runTest() {
147
132
  _runTest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(api, config) {
148
133
  var pwd,
149
- jestUtils,
150
- hookRunners,
151
- testConfigOperator,
152
- finalConfig,
153
- _args3 = arguments;
134
+ jestUtils,
135
+ hookRunners,
136
+ testConfigOperator,
137
+ finalConfig,
138
+ _args3 = arguments;
154
139
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
155
140
  while (1) {
156
141
  switch (_context3.prev = _context3.next) {
@@ -160,7 +145,6 @@ function _runTest() {
160
145
  jestUtils = getJestUtils(config);
161
146
  _context3.next = 5;
162
147
  return patchConfig(jestUtils);
163
-
164
148
  case 5:
165
149
  // 确保用户设置的配置可以被插件处理,比如设置在 projects 中
166
150
  jestUtils.setJestUserConfig();
@@ -171,18 +155,15 @@ function _runTest() {
171
155
  return input;
172
156
  }
173
157
  });
174
-
175
158
  case 9:
176
159
  testConfigOperator = _context3.sent;
177
160
  finalConfig = testConfigOperator.getFinalConfig();
178
161
  debug('Jest config:', finalConfig);
179
162
  _context3.next = 14;
180
163
  return runJest(finalConfig, pwd);
181
-
182
164
  case 14:
183
165
  _context3.next = 16;
184
166
  return hookRunners.afterTest();
185
-
186
167
  case 16:
187
168
  case "end":
188
169
  return _context3.stop();
@@ -3,7 +3,6 @@ import fs from 'fs';
3
3
  import path from 'path';
4
4
  import { createDebugger } from '@modern-js/utils';
5
5
  export var debug = createDebugger('test');
6
-
7
6
  /**
8
7
  * Read `compilerOptions` in the current pwd's tsconfig.json file
9
8
  */
@@ -13,27 +12,21 @@ export var readCompilerOptions = function readCompilerOptions() {
13
12
  var tsConfig = {};
14
13
  var extendedCompilerOptions = {};
15
14
  var tsconfigFile = '';
16
-
17
15
  try {
18
16
  var maybeTsconfigFile = path.join(pwd, filename);
19
-
20
17
  if (fs.existsSync(maybeTsconfigFile)) {
21
18
  tsconfigFile = maybeTsconfigFile;
22
19
  } else {
23
20
  tsconfigFile = require.resolve(filename);
24
21
  }
25
-
26
22
  var _require$parseConfigF = require('typescript').parseConfigFileTextToJson(tsconfigFile, fs.readFileSync(tsconfigFile, 'utf8'));
27
-
28
23
  tsConfig = _require$parseConfigF.config;
29
24
  } catch (e) {
30
25
  return {};
31
26
  }
32
-
33
27
  if (tsConfig["extends"]) {
34
28
  extendedCompilerOptions = readCompilerOptions(path.dirname(tsconfigFile), tsConfig["extends"]);
35
29
  }
36
-
37
30
  return _objectSpread(_objectSpread({}, extendedCompilerOptions), tsConfig.compilerOptions);
38
31
  };
39
32
  export var getModuleNameMapper = function getModuleNameMapper(alias) {
@@ -41,17 +34,16 @@ export var getModuleNameMapper = function getModuleNameMapper(alias) {
41
34
  var aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
42
35
  var isFile = aliasValue.some(function (s) {
43
36
  return s.endsWith('.js');
44
- }); // It's special for if using @modern-js/runtime alias other module @modern-js/runtime/model would not work.
37
+ });
45
38
 
39
+ // It's special for if using @modern-js/runtime alias other module @modern-js/runtime/model would not work.
46
40
  if (cur === '@modern-js/runtime$') {
47
41
  memo[".+".concat(cur)] = aliasValue[0];
48
42
  return memo;
49
43
  }
50
-
51
44
  if (isFile) {
52
45
  memo[cur] = aliasValue[0];
53
46
  }
54
-
55
47
  var key = "^".concat(cur, "/(.*)$");
56
48
  var value = path.normalize("".concat(aliasValue, "/$1"));
57
49
  memo[key] = value;
@@ -7,7 +7,6 @@ export var isInHandler = function isInHandler() {
7
7
  return Boolean(store.getStore());
8
8
  };
9
9
  var server = null;
10
-
11
10
  var createApp = /*#__PURE__*/function () {
12
11
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(pwd, config, plugins, routes) {
13
12
  var app;
@@ -19,7 +18,6 @@ var createApp = /*#__PURE__*/function () {
19
18
  _context.next = 5;
20
19
  break;
21
20
  }
22
-
23
21
  config.output.path = './';
24
22
  server = new Server({
25
23
  apiOnly: true,
@@ -30,11 +28,9 @@ var createApp = /*#__PURE__*/function () {
30
28
  });
31
29
  _context.next = 5;
32
30
  return server.init();
33
-
34
31
  case 5:
35
32
  app = server.getRequestHandler();
36
33
  return _context.abrupt("return", app);
37
-
38
34
  case 7:
39
35
  case "end":
40
36
  return _context.stop();
@@ -42,20 +38,16 @@ var createApp = /*#__PURE__*/function () {
42
38
  }
43
39
  }, _callee);
44
40
  }));
45
-
46
41
  return function createApp(_x, _x2, _x3, _x4) {
47
42
  return _ref.apply(this, arguments);
48
43
  };
49
44
  }();
50
-
51
45
  var getApp = function getApp() {
52
46
  if (!server) {
53
47
  throw new Error('please createApp first');
54
48
  }
55
-
56
49
  return server.getRequestHandler();
57
50
  };
58
-
59
51
  var closeServer = /*#__PURE__*/function () {
60
52
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
61
53
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
@@ -66,13 +58,10 @@ var closeServer = /*#__PURE__*/function () {
66
58
  _context2.next = 2;
67
59
  break;
68
60
  }
69
-
70
61
  throw new Error('please createApp first');
71
-
72
62
  case 2:
73
63
  _context2.next = 4;
74
64
  return server.close();
75
-
76
65
  case 4:
77
66
  case "end":
78
67
  return _context2.stop();
@@ -80,10 +69,8 @@ var closeServer = /*#__PURE__*/function () {
80
69
  }
81
70
  }, _callee2);
82
71
  }));
83
-
84
72
  return function closeServer() {
85
73
  return _ref2.apply(this, arguments);
86
74
  };
87
75
  }();
88
-
89
76
  export { createApp, getApp, closeServer };