@modern-js/plugin-testing 2.0.0-beta.3 → 2.0.0-beta.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. package/CHANGELOG.md +159 -0
  2. package/dist/js/modern/base/config/index.js +29 -9
  3. package/dist/js/modern/base/config/patches/assetsModule.js +7 -7
  4. package/dist/js/modern/base/config/patches/filemock.js +4 -1
  5. package/dist/js/modern/base/config/patches/index.js +30 -7
  6. package/dist/js/modern/base/config/patches/transformer.js +13 -18
  7. package/dist/js/modern/base/config/resolver.js +20 -11
  8. package/dist/js/modern/base/config/testConfigOperator.js +29 -23
  9. package/dist/js/modern/base/config/transformer/babelTransformer.js +16 -8
  10. package/dist/js/modern/base/hook.js +10 -5
  11. package/dist/js/modern/base/index.js +14 -6
  12. package/dist/js/modern/base/runJest.js +73 -62
  13. package/dist/js/modern/base/utils.js +40 -23
  14. package/dist/js/modern/cli/bff/app.js +37 -12
  15. package/dist/js/modern/cli/bff/constant.js +4 -1
  16. package/dist/js/modern/cli/bff/index.js +95 -52
  17. package/dist/js/modern/cli/bff/mockAPI.js +79 -64
  18. package/dist/js/modern/cli/bff/setup.js +71 -34
  19. package/dist/js/modern/cli/bff/utils/index.js +31 -15
  20. package/dist/js/modern/cli/index.js +65 -30
  21. package/dist/js/modern/cli/test.js +53 -18
  22. package/dist/js/modern/constant.js +4 -1
  23. package/dist/js/modern/index.js +3 -3
  24. package/dist/js/modern/modern-app.env.d.js +0 -0
  25. package/dist/js/modern/runtime-testing/app.js +25 -14
  26. package/dist/js/modern/runtime-testing/base.js +7 -3
  27. package/dist/js/modern/runtime-testing/customRender.js +24 -10
  28. package/dist/js/modern/runtime-testing/index.js +1 -1
  29. package/dist/js/modern/runtime-testing/reduck.js +41 -19
  30. package/dist/js/modern/runtime-testing/request.js +4 -4
  31. package/dist/js/modern/runtime-testing/resolvePlugins.js +24 -8
  32. package/dist/js/node/base/config/index.js +62 -18
  33. package/dist/js/node/base/config/patches/assetsModule.js +34 -12
  34. package/dist/js/node/base/config/patches/filemock.js +24 -7
  35. package/dist/js/node/base/config/patches/index.js +54 -15
  36. package/dist/js/node/base/config/patches/transformer.js +42 -25
  37. package/dist/js/node/base/config/resolver.js +25 -10
  38. package/dist/js/node/base/config/testConfigOperator.js +51 -30
  39. package/dist/js/node/base/config/transformer/babelTransformer.js +42 -15
  40. package/dist/js/node/base/hook.js +34 -13
  41. package/dist/js/node/base/index.js +39 -62
  42. package/dist/js/node/base/runJest.js +104 -71
  43. package/dist/js/node/base/types/index.js +15 -0
  44. package/dist/js/node/base/utils.js +70 -34
  45. package/dist/js/node/cli/bff/app.js +64 -22
  46. package/dist/js/node/cli/bff/constant.js +26 -7
  47. package/dist/js/node/cli/bff/index.js +123 -65
  48. package/dist/js/node/cli/bff/mockAPI.js +103 -71
  49. package/dist/js/node/cli/bff/setup.js +71 -28
  50. package/dist/js/node/cli/bff/utils/index.js +57 -22
  51. package/dist/js/node/cli/index.js +92 -46
  52. package/dist/js/node/cli/test.js +81 -27
  53. package/dist/js/node/constant.js +26 -7
  54. package/dist/js/node/index.js +19 -18
  55. package/dist/js/node/modern-app.env.d.js +0 -0
  56. package/dist/js/node/runtime-testing/app.js +53 -25
  57. package/dist/js/node/runtime-testing/base.js +34 -32
  58. package/dist/js/node/runtime-testing/customRender.js +49 -18
  59. package/dist/js/node/runtime-testing/index.js +18 -27
  60. package/dist/js/node/runtime-testing/reduck.js +72 -31
  61. package/dist/js/node/runtime-testing/request.js +36 -13
  62. package/dist/js/node/runtime-testing/resolvePlugins.js +41 -12
  63. package/dist/js/treeshaking/base/config/index.js +150 -31
  64. package/dist/js/treeshaking/base/config/patches/assetsModule.js +9 -11
  65. package/dist/js/treeshaking/base/config/patches/filemock.js +2 -1
  66. package/dist/js/treeshaking/base/config/patches/index.js +221 -64
  67. package/dist/js/treeshaking/base/config/patches/transformer.js +34 -37
  68. package/dist/js/treeshaking/base/config/resolver.js +36 -13
  69. package/dist/js/treeshaking/base/config/testConfigOperator.js +120 -69
  70. package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +16 -10
  71. package/dist/js/treeshaking/base/hook.js +8 -7
  72. package/dist/js/treeshaking/base/index.js +7 -6
  73. package/dist/js/treeshaking/base/runJest.js +281 -164
  74. package/dist/js/treeshaking/base/types/index.js +1 -0
  75. package/dist/js/treeshaking/base/utils.js +72 -48
  76. package/dist/js/treeshaking/cli/bff/app.js +192 -68
  77. package/dist/js/treeshaking/cli/bff/constant.js +2 -1
  78. package/dist/js/treeshaking/cli/bff/index.js +291 -130
  79. package/dist/js/treeshaking/cli/bff/mockAPI.js +181 -91
  80. package/dist/js/treeshaking/cli/bff/setup.js +185 -59
  81. package/dist/js/treeshaking/cli/bff/utils/index.js +47 -21
  82. package/dist/js/treeshaking/cli/index.js +249 -108
  83. package/dist/js/treeshaking/cli/test.js +177 -44
  84. package/dist/js/treeshaking/constant.js +2 -1
  85. package/dist/js/treeshaking/index.js +3 -3
  86. package/dist/js/treeshaking/modern-app.env.d.js +1 -0
  87. package/dist/js/treeshaking/runtime-testing/app.js +85 -39
  88. package/dist/js/treeshaking/runtime-testing/base.js +4 -3
  89. package/dist/js/treeshaking/runtime-testing/customRender.js +38 -10
  90. package/dist/js/treeshaking/runtime-testing/index.js +1 -1
  91. package/dist/js/treeshaking/runtime-testing/reduck.js +85 -33
  92. package/dist/js/treeshaking/runtime-testing/request.js +49 -19
  93. package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +45 -14
  94. package/dist/types/base/config/index.d.ts +1 -0
  95. package/dist/types/base/config/patches/assetsModule.d.ts +1 -0
  96. package/dist/types/base/config/patches/filemock.d.ts +1 -0
  97. package/dist/types/base/config/patches/transformer.d.ts +1 -0
  98. package/dist/types/base/config/testConfigOperator.d.ts +2 -0
  99. package/dist/types/base/runJest.d.ts +2 -0
  100. package/dist/types/base/utils.d.ts +1 -0
  101. package/dist/types/cli/bff/index.d.ts +2 -0
  102. package/dist/types/cli/bff/mockAPI.d.ts +1 -0
  103. package/dist/types/cli/index.d.ts +2 -0
  104. package/dist/types/runtime-testing/app.d.ts +3 -0
  105. package/dist/types/runtime-testing/customRender.d.ts +2 -0
  106. package/package.json +21 -25
@@ -1,39 +1,36 @@
1
1
  import { readCompilerOptions } from "../../utils";
2
- var resolveTsCompilerOptions = function resolveTsCompilerOptions() {
3
- var tsCompilerOptions = readCompilerOptions() || {};
4
- var jsx = tsCompilerOptions.jsx;
5
- if (!jsx) {
6
- return null;
7
- }
8
- tsCompilerOptions.jsx = 'react-jsx';
9
- return tsCompilerOptions;
2
+ var resolveTsCompilerOptions = function() {
3
+ var tsCompilerOptions = readCompilerOptions() || {};
4
+ var jsx = tsCompilerOptions.jsx;
5
+ if (!jsx) {
6
+ return null;
7
+ }
8
+ tsCompilerOptions.jsx = "react-jsx";
9
+ return tsCompilerOptions;
10
10
  };
11
-
12
- /**
13
- * Map `TestConfig.transformer` to jest config
14
- */
15
- export var patchTransformer = function patchTransformer(testOperator) {
16
- var transformer = testOperator.testConfig.transformer;
17
- if (transformer === 'babel-jest') {
18
- testOperator.mergeJestConfig({
19
- transform: {
20
- '\\.[jt]sx?$': require.resolve("../transformer/babelTransformer")
21
- }
22
- });
23
- }
24
- if (transformer === 'ts-jest') {
25
- testOperator.mergeJestConfig({
26
- transform: {
27
- '\\.[jt]sx?$': require.resolve('ts-jest')
28
- }
29
- });
30
- var compilerOptions = resolveTsCompilerOptions();
31
- compilerOptions && testOperator.mergeJestConfig({
32
- globals: {
33
- 'ts-jest': {
34
- tsconfig: compilerOptions
35
- }
36
- }
37
- });
38
- }
39
- };
11
+ var patchTransformer = function(testOperator) {
12
+ var transformer = testOperator.testConfig.transformer;
13
+ if (transformer === "babel-jest") {
14
+ testOperator.mergeJestConfig({
15
+ transform: {
16
+ "\\.[jt]sx?$": require.resolve("../transformer/babelTransformer")
17
+ }
18
+ });
19
+ }
20
+ if (transformer === "ts-jest") {
21
+ testOperator.mergeJestConfig({
22
+ transform: {
23
+ "\\.[jt]sx?$": require.resolve("ts-jest")
24
+ }
25
+ });
26
+ var compilerOptions = resolveTsCompilerOptions();
27
+ compilerOptions && testOperator.mergeJestConfig({
28
+ globals: {
29
+ "ts-jest": {
30
+ tsconfig: compilerOptions
31
+ }
32
+ }
33
+ });
34
+ }
35
+ };
36
+ export { patchTransformer };
@@ -1,14 +1,37 @@
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
- var shouldResolveByEnhance = function shouldResolveByEnhance(url) {
7
- return /^@[^/]+\/[^/]+\/.*/.test(url);
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = function(cb, mod) {
3
+ return function __require() {
4
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
5
+ exports: {}
6
+ }).exports, mod), mod.exports;
7
+ };
8
8
  };
9
- module.exports = function (request, options) {
10
- if (shouldResolveByEnhance(request)) {
11
- return resolver(options.basedir, request);
12
- }
13
- return options.defaultResolver(request, options);
14
- };
9
+ import enhanceResolve from "enhanced-resolve";
10
+ var require_resolver = __commonJS({
11
+ "src/base/config/resolver.ts": function(exports, module) {
12
+ var resolver = enhanceResolve.create.sync({
13
+ conditionNames: [
14
+ "require",
15
+ "node",
16
+ "default"
17
+ ],
18
+ extensions: [
19
+ ".js",
20
+ ".json",
21
+ ".node",
22
+ ".ts",
23
+ ".tsx"
24
+ ]
25
+ });
26
+ var shouldResolveByEnhance = function(url) {
27
+ return /^@[^/]+\/[^/]+\/.*/.test(url);
28
+ };
29
+ module.exports = function(request, options) {
30
+ if (shouldResolveByEnhance(request)) {
31
+ return resolver(options.basedir, request);
32
+ }
33
+ return options.defaultResolver(request, options);
34
+ };
35
+ }
36
+ });
37
+ export default require_resolver();
@@ -1,76 +1,127 @@
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
- var TestConfigOperator = /*#__PURE__*/function () {
8
- function TestConfigOperator(testConfig) {
9
- _classCallCheck(this, TestConfigOperator);
10
- _defineProperty(this, "_testConfig", void 0);
11
- _defineProperty(this, "_jestConfig", void 0);
12
- _defineProperty(this, "userJestConfig", void 0);
13
- _defineProperty(this, "defaultTestConfig", {
14
- transformer: 'babel-jest'
15
- });
16
- this._testConfig = testConfig;
17
- this._jestConfig = {};
18
- this.userJestConfig = testConfig.jest;
19
- this.initial();
20
- }
21
- _createClass(TestConfigOperator, [{
22
- key: "initial",
23
- value: function initial() {
24
- this._testConfig = merge({}, this.defaultTestConfig, this.testConfig);
1
+ function _classCallCheck(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
25
4
  }
26
- }, {
27
- key: "jestConfig",
28
- get: function get() {
29
- return this._jestConfig;
5
+ }
6
+ function _defineProperties(target, props) {
7
+ for(var i = 0; i < props.length; i++){
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor) descriptor.writable = true;
12
+ Object.defineProperty(target, descriptor.key, descriptor);
30
13
  }
31
- }, {
32
- key: "testConfig",
33
- get: function get() {
34
- return this._testConfig;
14
+ }
15
+ function _createClass(Constructor, protoProps, staticProps) {
16
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
+ if (staticProps) _defineProperties(Constructor, staticProps);
18
+ return Constructor;
19
+ }
20
+ function _defineProperty(obj, key, value) {
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
35
30
  }
36
- }, {
37
- key: "mergeJestConfig",
38
- value: function mergeJestConfig(sourceConfig) {
39
- this._jestConfig = merge({}, this._jestConfig, sourceConfig);
40
- }
41
- }, {
42
- key: "setJestUserConfig",
43
- value: function setJestUserConfig() {
44
- var userJestConfig = this.userJestConfig;
45
- if (_typeof(userJestConfig) === 'object') {
46
- this.setJestConfig(userJestConfig);
47
- }
48
- }
49
- }, {
50
- key: "setJestConfig",
51
- value: function setJestConfig(sourceConfig, options) {
52
- if (options) {
53
- var force = options.force;
54
- if (force) {
55
- this._jestConfig = sourceConfig;
56
- return;
31
+ return obj;
32
+ }
33
+ function _objectSpread(target) {
34
+ for(var i = 1; i < arguments.length; i++){
35
+ var source = arguments[i] != null ? arguments[i] : {};
36
+ var ownKeys = Object.keys(source);
37
+ if (typeof Object.getOwnPropertySymbols === "function") {
38
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
39
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
40
+ }));
57
41
  }
58
- }
59
- this._jestConfig = _objectSpread(_objectSpread({}, this._jestConfig), sourceConfig);
42
+ ownKeys.forEach(function(key) {
43
+ _defineProperty(target, key, source[key]);
44
+ });
60
45
  }
61
- }, {
62
- key: "getFinalConfig",
63
- value: function getFinalConfig() {
64
- var userJestConfig = this.userJestConfig;
65
- if (!userJestConfig) {
66
- return this._jestConfig;
67
- }
68
- if (typeof userJestConfig === 'function') {
69
- return userJestConfig(this._jestConfig);
70
- }
71
- return this.jestConfig;
46
+ return target;
47
+ }
48
+ import { merge } from "@modern-js/utils/lodash";
49
+ var TestConfigOperator = /*#__PURE__*/ function() {
50
+ "use strict";
51
+ function TestConfigOperator(testConfig) {
52
+ _classCallCheck(this, TestConfigOperator);
53
+ _defineProperty(this, "_testConfig", void 0);
54
+ _defineProperty(this, "_jestConfig", void 0);
55
+ _defineProperty(this, "userJestConfig", void 0);
56
+ _defineProperty(this, "defaultTestConfig", {
57
+ transformer: "babel-jest"
58
+ });
59
+ this._testConfig = testConfig;
60
+ this._jestConfig = {};
61
+ this.userJestConfig = testConfig.jest;
62
+ this.initial();
72
63
  }
73
- }]);
74
- return TestConfigOperator;
64
+ _createClass(TestConfigOperator, [
65
+ {
66
+ key: "initial",
67
+ value: function initial() {
68
+ this._testConfig = merge({}, this.defaultTestConfig, this.testConfig);
69
+ }
70
+ },
71
+ {
72
+ key: "jestConfig",
73
+ get: function get() {
74
+ return this._jestConfig;
75
+ }
76
+ },
77
+ {
78
+ key: "testConfig",
79
+ get: function get() {
80
+ return this._testConfig;
81
+ }
82
+ },
83
+ {
84
+ key: "mergeJestConfig",
85
+ value: function mergeJestConfig(sourceConfig) {
86
+ this._jestConfig = merge({}, this._jestConfig, sourceConfig);
87
+ }
88
+ },
89
+ {
90
+ key: "setJestUserConfig",
91
+ value: function setJestUserConfig() {
92
+ var userJestConfig = this.userJestConfig;
93
+ if (typeof userJestConfig === "object") {
94
+ this.setJestConfig(userJestConfig);
95
+ }
96
+ }
97
+ },
98
+ {
99
+ key: "setJestConfig",
100
+ value: function setJestConfig(sourceConfig, options) {
101
+ if (options) {
102
+ var force = options.force;
103
+ if (force) {
104
+ this._jestConfig = sourceConfig;
105
+ return;
106
+ }
107
+ }
108
+ this._jestConfig = _objectSpread({}, this._jestConfig, sourceConfig);
109
+ }
110
+ },
111
+ {
112
+ key: "getFinalConfig",
113
+ value: function getFinalConfig() {
114
+ var userJestConfig = this.userJestConfig;
115
+ if (!userJestConfig) {
116
+ return this._jestConfig;
117
+ }
118
+ if (typeof userJestConfig === "function") {
119
+ return userJestConfig(this._jestConfig);
120
+ }
121
+ return this.jestConfig;
122
+ }
123
+ }
124
+ ]);
125
+ return TestConfigOperator;
75
126
  }();
76
- export { TestConfigOperator };
127
+ export { TestConfigOperator };
@@ -1,11 +1,17 @@
1
- var _babelJest$createTran;
2
- import babelJest from 'babel-jest';
3
- var babelTransformer = (_babelJest$createTran = babelJest.createTransformer) === null || _babelJest$createTran === void 0 ? void 0 : _babelJest$createTran.call(babelJest, {
4
- presets: [[require.resolve('@modern-js/babel-preset-app'), {
5
- appDirectory: process.cwd(),
6
- modules: 'cjs'
7
- }]],
8
- configFile: false,
9
- babelrc: false
1
+ var ref;
2
+ import babelJest from "babel-jest";
3
+ var babelTransformer = (ref = babelJest.createTransformer) === null || ref === void 0 ? void 0 : ref.call(babelJest, {
4
+ presets: [
5
+ [
6
+ require.resolve("@modern-js/babel-preset-app"),
7
+ {
8
+ appDirectory: process.cwd(),
9
+ modules: "cjs"
10
+ }
11
+ ]
12
+ ],
13
+ configFile: false,
14
+ babelrc: false
10
15
  });
11
- export default babelTransformer;
16
+ var babelTransformer_default = babelTransformer;
17
+ export { babelTransformer_default as default };
@@ -1,7 +1,8 @@
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
- };
1
+ import { createAsyncPipeline, createParallelWorkflow } from "@modern-js/plugin";
2
+ var jestConfigHook = createAsyncPipeline();
3
+ var afterTestHook = createParallelWorkflow();
4
+ var testingHooks = {
5
+ jestConfig: createAsyncPipeline(),
6
+ afterTest: createParallelWorkflow()
7
+ };
8
+ export { afterTestHook, jestConfigHook, testingHooks };
@@ -1,6 +1,7 @@
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";
1
+ import { runTest, runJest } from "./runJest";
2
+ import { getModuleNameMapper } from "./utils";
3
+ import { DEFAULT_RESOLVER_PATH } from "./config";
4
+ import { TestConfigOperator } from "./config/testConfigOperator";
5
+ import { testingHooks } from "./hook";
6
+ export * from "./types";
7
+ export { DEFAULT_RESOLVER_PATH, TestConfigOperator, getModuleNameMapper, runJest, runTest, testingHooks };