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

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 (106) hide show
  1. package/CHANGELOG.md +145 -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 +11 -6
  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 +64 -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 +56 -18
  33. package/dist/js/node/base/config/patches/assetsModule.js +30 -12
  34. package/dist/js/node/base/config/patches/filemock.js +22 -7
  35. package/dist/js/node/base/config/patches/index.js +50 -15
  36. package/dist/js/node/base/config/patches/transformer.js +38 -25
  37. package/dist/js/node/base/config/resolver.js +37 -10
  38. package/dist/js/node/base/config/testConfigOperator.js +49 -30
  39. package/dist/js/node/base/config/transformer/babelTransformer.js +40 -15
  40. package/dist/js/node/base/hook.js +28 -13
  41. package/dist/js/node/base/index.js +31 -63
  42. package/dist/js/node/base/runJest.js +99 -71
  43. package/dist/js/node/base/utils.js +66 -34
  44. package/dist/js/node/cli/bff/app.js +57 -22
  45. package/dist/js/node/cli/bff/constant.js +22 -7
  46. package/dist/js/node/cli/bff/index.js +121 -65
  47. package/dist/js/node/cli/bff/mockAPI.js +103 -71
  48. package/dist/js/node/cli/bff/setup.js +100 -38
  49. package/dist/js/node/cli/bff/utils/index.js +55 -22
  50. package/dist/js/node/cli/index.js +87 -46
  51. package/dist/js/node/cli/test.js +79 -27
  52. package/dist/js/node/constant.js +22 -7
  53. package/dist/js/node/index.js +19 -18
  54. package/dist/js/node/modern-app.env.d.js +0 -0
  55. package/dist/js/node/runtime-testing/app.js +53 -25
  56. package/dist/js/node/runtime-testing/base.js +30 -33
  57. package/dist/js/node/runtime-testing/customRender.js +49 -18
  58. package/dist/js/node/runtime-testing/index.js +18 -27
  59. package/dist/js/node/runtime-testing/reduck.js +67 -31
  60. package/dist/js/node/runtime-testing/request.js +32 -13
  61. package/dist/js/node/runtime-testing/resolvePlugins.js +41 -12
  62. package/dist/js/treeshaking/base/config/index.js +150 -31
  63. package/dist/js/treeshaking/base/config/patches/assetsModule.js +9 -11
  64. package/dist/js/treeshaking/base/config/patches/filemock.js +2 -1
  65. package/dist/js/treeshaking/base/config/patches/index.js +221 -64
  66. package/dist/js/treeshaking/base/config/patches/transformer.js +34 -37
  67. package/dist/js/treeshaking/base/config/resolver.js +24 -11
  68. package/dist/js/treeshaking/base/config/testConfigOperator.js +120 -69
  69. package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +16 -10
  70. package/dist/js/treeshaking/base/hook.js +8 -7
  71. package/dist/js/treeshaking/base/index.js +7 -6
  72. package/dist/js/treeshaking/base/runJest.js +281 -164
  73. package/dist/js/treeshaking/base/types/index.js +1 -0
  74. package/dist/js/treeshaking/base/utils.js +72 -48
  75. package/dist/js/treeshaking/cli/bff/app.js +192 -68
  76. package/dist/js/treeshaking/cli/bff/constant.js +2 -1
  77. package/dist/js/treeshaking/cli/bff/index.js +291 -130
  78. package/dist/js/treeshaking/cli/bff/mockAPI.js +181 -91
  79. package/dist/js/treeshaking/cli/bff/setup.js +185 -59
  80. package/dist/js/treeshaking/cli/bff/utils/index.js +47 -21
  81. package/dist/js/treeshaking/cli/index.js +248 -108
  82. package/dist/js/treeshaking/cli/test.js +177 -44
  83. package/dist/js/treeshaking/constant.js +2 -1
  84. package/dist/js/treeshaking/index.js +3 -3
  85. package/dist/js/treeshaking/modern-app.env.d.js +1 -0
  86. package/dist/js/treeshaking/runtime-testing/app.js +85 -39
  87. package/dist/js/treeshaking/runtime-testing/base.js +4 -3
  88. package/dist/js/treeshaking/runtime-testing/customRender.js +38 -10
  89. package/dist/js/treeshaking/runtime-testing/index.js +1 -1
  90. package/dist/js/treeshaking/runtime-testing/reduck.js +85 -33
  91. package/dist/js/treeshaking/runtime-testing/request.js +49 -19
  92. package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +45 -14
  93. package/dist/types/base/config/index.d.ts +1 -0
  94. package/dist/types/base/config/patches/assetsModule.d.ts +1 -0
  95. package/dist/types/base/config/patches/filemock.d.ts +1 -0
  96. package/dist/types/base/config/patches/transformer.d.ts +1 -0
  97. package/dist/types/base/config/resolver.d.ts +2 -1
  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 +13 -13
@@ -1,98 +1,188 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
- import _typeof from "@babel/runtime/helpers/esm/typeof";
4
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
- import * as ptr from 'path-to-regexp';
6
- import * as mockAppModule from "./app";
7
-
8
- // eslint-disable-next-line @typescript-eslint/naming-convention
9
- var mock_replaceUrlWithParams = function mock_replaceUrlWithParams(url, paramValues, payload) {
10
- var keys = [];
11
- ptr.pathToRegexp(url, keys);
12
- var params = keys.reduce(function (cur, key, index) {
13
- if (paramValues[index]) {
14
- cur[key.name] = paramValues[index];
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithHoles(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _arrayWithoutHoles(arr) {
10
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
11
+ }
12
+ function _defineProperty(obj, key, value) {
13
+ if (key in obj) {
14
+ Object.defineProperty(obj, key, {
15
+ value: value,
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true
19
+ });
20
+ } else {
21
+ obj[key] = value;
22
+ }
23
+ return obj;
24
+ }
25
+ function _iterableToArray(iter) {
26
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
27
+ }
28
+ function _iterableToArrayLimit(arr, i) {
29
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
30
+ if (_i == null) return;
31
+ var _arr = [];
32
+ var _n = true;
33
+ var _d = false;
34
+ var _s, _e;
35
+ try {
36
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
37
+ _arr.push(_s.value);
38
+ if (i && _arr.length === i) break;
39
+ }
40
+ } catch (err) {
41
+ _d = true;
42
+ _e = err;
43
+ } finally{
44
+ try {
45
+ if (!_n && _i["return"] != null) _i["return"]();
46
+ } finally{
47
+ if (_d) throw _e;
48
+ }
49
+ }
50
+ return _arr;
51
+ }
52
+ function _nonIterableRest() {
53
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
54
+ }
55
+ function _nonIterableSpread() {
56
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
+ }
58
+ function _objectSpread(target) {
59
+ for(var i = 1; i < arguments.length; i++){
60
+ var source = arguments[i] != null ? arguments[i] : {};
61
+ var ownKeys = Object.keys(source);
62
+ if (typeof Object.getOwnPropertySymbols === "function") {
63
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
65
+ }));
66
+ }
67
+ ownKeys.forEach(function(key) {
68
+ _defineProperty(target, key, source[key]);
69
+ });
15
70
  }
16
- return cur;
17
- }, {});
18
- var getFinalPath = ptr.compile(url, {
19
- encode: encodeURIComponent
20
- });
21
- return getFinalPath(_objectSpread(_objectSpread({}, params), payload));
71
+ return target;
72
+ }
73
+ function _slicedToArray(arr, i) {
74
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
75
+ }
76
+ function _toConsumableArray(arr) {
77
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
78
+ }
79
+ function _unsupportedIterableToArray(o, minLen) {
80
+ if (!o) return;
81
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
82
+ var n = Object.prototype.toString.call(o).slice(8, -1);
83
+ if (n === "Object" && o.constructor) n = o.constructor.name;
84
+ if (n === "Map" || n === "Set") return Array.from(n);
85
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
86
+ }
87
+ import * as ptr from "path-to-regexp";
88
+ import * as mockAppModule from "./app";
89
+ var mock_replaceUrlWithParams = function(url, paramValues, payload) {
90
+ var keys = [];
91
+ ptr.pathToRegexp(url, keys);
92
+ var params = keys.reduce(function(cur, key, index) {
93
+ if (paramValues[index]) {
94
+ cur[key.name] = paramValues[index];
95
+ }
96
+ return cur;
97
+ }, {});
98
+ var getFinalPath = ptr.compile(url, {
99
+ encode: encodeURIComponent
100
+ });
101
+ return getFinalPath(_objectSpread({}, params, payload));
22
102
  };
23
-
24
- // eslint-disable-next-line @typescript-eslint/naming-convention
25
- var mock_getParamsAndPayload = function mock_getParamsAndPayload(args) {
26
- if (args.length === 0) {
27
- return [[], {}];
28
- }
29
- var head = args[0];
30
- if (_typeof(head) === 'object') {
31
- return [[], head];
32
- } else {
33
- var latest = args[args.length - 1];
34
- if (_typeof(latest) === 'object') {
35
- return [args.slice(0, args.length - 1), latest];
103
+ var mock_getParamsAndPayload = function(args) {
104
+ if (args.length === 0) {
105
+ return [
106
+ [],
107
+ {}
108
+ ];
109
+ }
110
+ var head = args[0];
111
+ if (typeof head === "object") {
112
+ return [
113
+ [],
114
+ head
115
+ ];
36
116
  } else {
37
- return [args, {}];
117
+ var latest = args[args.length - 1];
118
+ if (typeof latest === "object") {
119
+ return [
120
+ args.slice(0, args.length - 1),
121
+ latest
122
+ ];
123
+ } else {
124
+ return [
125
+ args,
126
+ {}
127
+ ];
128
+ }
38
129
  }
39
- }
40
130
  };
41
- export default (function (mockApiInfosByFile) {
42
- var files = Object.keys(mockApiInfosByFile);
43
- files.forEach(function (mockedFile) {
44
- jest.mock(mockedFile, function () {
45
- var supertest = require('supertest');
46
- return mockApiInfosByFile[mockedFile].reduce(function (res, info) {
47
- var module = _defineProperty({}, info.name, function () {
48
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
49
- args[_key] = arguments[_key];
50
- }
51
- if (mockAppModule.isInHandler()) {
52
- return info.handler.apply(info, args);
53
- }
54
- var _mock_getParamsAndPay = mock_getParamsAndPayload(args),
55
- _mock_getParamsAndPay2 = _slicedToArray(_mock_getParamsAndPay, 2),
56
- params = _mock_getParamsAndPay2[0],
57
- payload = _mock_getParamsAndPay2[1];
58
- var _ref = module[info.name],
59
- returnHttp = _ref.returnHttp;
60
- var url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
61
- var app = mockAppModule.getApp();
62
- var test = supertest(app)[info.httpMethod.toLowerCase()](url);
63
- if (payload.query) {
64
- test = test.query(payload.query);
65
- }
66
- if (payload.body) {
67
- test = test.send(payload.body);
68
- }
69
- if (payload.data) {
70
- test = test.send(payload.data);
71
- }
72
- if (payload.headers) {
73
- for (var name in payload.headers) {
74
- test = test.set(name, payload.headers[name]);
75
- }
76
- }
77
- if (payload.cookies) {
78
- test = test.set('Cookie', [payload.cookies]);
79
- }
80
- if (returnHttp) {
81
- return test;
82
- }
83
- return test.then(function (value) {
84
- try {
85
- return JSON.parse(value.text);
86
- } catch (_unused) {
87
- return value.text;
88
- }
89
- });
131
+ var mockAPI_default = function(mockApiInfosByFile) {
132
+ var files = Object.keys(mockApiInfosByFile);
133
+ files.forEach(function(mockedFile) {
134
+ jest.mock(mockedFile, function() {
135
+ var supertest = require("supertest");
136
+ return mockApiInfosByFile[mockedFile].reduce(function(res, info) {
137
+ var module = _defineProperty({}, info.name, function() {
138
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
139
+ args[_key] = arguments[_key];
140
+ }
141
+ if (mockAppModule.isInHandler()) {
142
+ var _info;
143
+ return (_info = info).handler.apply(_info, _toConsumableArray(args));
144
+ }
145
+ var ref = _slicedToArray(mock_getParamsAndPayload(args), 2), params = ref[0], payload = ref[1];
146
+ var returnHttp = module[info.name].returnHttp;
147
+ var url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
148
+ var app = mockAppModule.getApp();
149
+ var test = supertest(app)[info.httpMethod.toLowerCase()](url);
150
+ if (payload.query) {
151
+ test = test.query(payload.query);
152
+ }
153
+ if (payload.body) {
154
+ test = test.send(payload.body);
155
+ }
156
+ if (payload.data) {
157
+ test = test.send(payload.data);
158
+ }
159
+ if (payload.headers) {
160
+ for(var name in payload.headers){
161
+ test = test.set(name, payload.headers[name]);
162
+ }
163
+ }
164
+ if (payload.cookies) {
165
+ test = test.set("Cookie", [
166
+ payload.cookies
167
+ ]);
168
+ }
169
+ if (returnHttp) {
170
+ return test;
171
+ }
172
+ return test.then(function(value) {
173
+ try {
174
+ return JSON.parse(value.text);
175
+ } catch (e) {
176
+ return value.text;
177
+ }
178
+ });
179
+ });
180
+ res[info.name] = module[info.name];
181
+ Object.assign(res[info.name], info.handler);
182
+ res.__esModule = true;
183
+ return res;
184
+ }, {});
90
185
  });
91
- res[info.name] = module[info.name];
92
- Object.assign(res[info.name], info.handler);
93
- res.__esModule = true;
94
- return res;
95
- }, {});
96
186
  });
97
- });
98
- });
187
+ };
188
+ export { mockAPI_default as default };
@@ -1,66 +1,192 @@
1
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import path from 'path';
4
- import { ApiRouter } from '@modern-js/bff-core';
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _asyncToGenerator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ var __generator = this && this.__generator || function(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g;
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ };
125
+ import path from "path";
126
+ import { ApiRouter } from "@modern-js/bff-core";
5
127
  import { bff_info_key } from "./constant";
6
128
  import mockAPI from "./mockAPI";
7
129
  import { createApp, closeServer } from "./app";
8
130
  var uped = false;
9
- var setup = function setup() {
10
- var _bff_info$modernUserC, _bff_info$modernUserC2;
11
- if (uped) {
12
- return;
13
- }
14
- uped = true;
15
- var bff_info = global[bff_info_key];
16
- var 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;
17
- var apiRouter = new ApiRouter({
18
- apiDir: path.join(bff_info.appDir, './api'),
19
- prefix: prefix
20
- });
21
- var apiInfos = apiRouter.getApiHandlers();
22
- var apiInfosByFile = apiInfos.reduce(function (res, apiInfo) {
23
- if (!res[apiInfo.filename]) {
24
- res[apiInfo.filename] = [];
131
+ var setup = function() {
132
+ var ref, ref1;
133
+ if (uped) {
134
+ return;
25
135
  }
26
- res[apiInfo.filename].push(apiInfo);
27
- return res;
28
- }, {});
29
- var app = null;
30
- beforeAll( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
31
- return _regeneratorRuntime().wrap(function _callee$(_context) {
32
- while (1) {
33
- switch (_context.prev = _context.next) {
34
- case 0:
35
- if (app) {
36
- _context.next = 4;
37
- break;
38
- }
39
- _context.next = 3;
40
- return createApp(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes);
41
- case 3:
42
- app = _context.sent;
43
- case 4:
44
- case "end":
45
- return _context.stop();
136
+ uped = true;
137
+ var bff_info = global[bff_info_key];
138
+ var prefix = bff_info === null || bff_info === void 0 ? void 0 : (ref = bff_info.modernUserConfig) === null || ref === void 0 ? void 0 : (ref1 = ref.bff) === null || ref1 === void 0 ? void 0 : ref1.prefix;
139
+ var apiRouter = new ApiRouter({
140
+ apiDir: path.join(bff_info.appDir, "./api"),
141
+ prefix: prefix
142
+ });
143
+ var apiInfos = apiRouter.getApiHandlers();
144
+ var apiInfosByFile = apiInfos.reduce(function(res, apiInfo) {
145
+ if (!res[apiInfo.filename]) {
146
+ res[apiInfo.filename] = [];
46
147
  }
47
- }
48
- }, _callee);
49
- })));
50
- afterAll( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
51
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
52
- while (1) {
53
- switch (_context2.prev = _context2.next) {
54
- case 0:
55
- _context2.next = 2;
56
- return closeServer();
57
- case 2:
58
- case "end":
59
- return _context2.stop();
60
- }
61
- }
62
- }, _callee2);
63
- })));
64
- mockAPI(apiInfosByFile);
148
+ res[apiInfo.filename].push(apiInfo);
149
+ return res;
150
+ }, {});
151
+ var app = null;
152
+ beforeAll(/*#__PURE__*/ _asyncToGenerator(function() {
153
+ return __generator(this, function(_state) {
154
+ switch(_state.label){
155
+ case 0:
156
+ if (!!app) return [
157
+ 3,
158
+ 2
159
+ ];
160
+ return [
161
+ 4,
162
+ createApp(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes)
163
+ ];
164
+ case 1:
165
+ app = _state.sent();
166
+ _state.label = 2;
167
+ case 2:
168
+ return [
169
+ 2
170
+ ];
171
+ }
172
+ });
173
+ }));
174
+ afterAll(/*#__PURE__*/ _asyncToGenerator(function() {
175
+ return __generator(this, function(_state) {
176
+ switch(_state.label){
177
+ case 0:
178
+ return [
179
+ 4,
180
+ closeServer()
181
+ ];
182
+ case 1:
183
+ _state.sent();
184
+ return [
185
+ 2
186
+ ];
187
+ }
188
+ });
189
+ }));
190
+ mockAPI(apiInfosByFile);
65
191
  };
66
- setup();
192
+ setup();
@@ -1,21 +1,47 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import path from 'path';
3
- import { chalk } from '@modern-js/utils';
4
- export var isBFFProject = function isBFFProject(pwd) {
5
- try {
6
- var packageJson = require(path.join(pwd, './package.json'));
7
- var dependencies = packageJson.dependencies,
8
- devDependencies = packageJson.devDependencies;
9
- var isBFF = Object.keys(_objectSpread(_objectSpread({}, dependencies), devDependencies)).some(function (dependency) {
10
- return dependency.includes('plugin-bff');
11
- });
12
- var isMWA = Object.keys(devDependencies).some(function (devDependency) {
13
- return devDependency.includes('app-tools');
14
- });
15
- return isMWA && isBFF;
16
- } catch (error) {
17
- // eslint-disable-next-line no-console
18
- console.log(chalk.red(error));
19
- return false;
20
- }
21
- };
1
+ function _defineProperty(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _objectSpread(target) {
15
+ for(var i = 1; i < arguments.length; i++){
16
+ var source = arguments[i] != null ? arguments[i] : {};
17
+ var ownKeys = Object.keys(source);
18
+ if (typeof Object.getOwnPropertySymbols === "function") {
19
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
+ }));
22
+ }
23
+ ownKeys.forEach(function(key) {
24
+ _defineProperty(target, key, source[key]);
25
+ });
26
+ }
27
+ return target;
28
+ }
29
+ import path from "path";
30
+ import { chalk } from "@modern-js/utils";
31
+ var isBFFProject = function(pwd) {
32
+ try {
33
+ var packageJson = require(path.join(pwd, "./package.json"));
34
+ var dependencies = packageJson.dependencies, devDependencies = packageJson.devDependencies;
35
+ var isBFF = Object.keys(_objectSpread({}, dependencies, devDependencies)).some(function(dependency) {
36
+ return dependency.includes("plugin-bff");
37
+ });
38
+ var isMWA = Object.keys(devDependencies).some(function(devDependency) {
39
+ return devDependency.includes("app-tools");
40
+ });
41
+ return isMWA && isBFF;
42
+ } catch (error) {
43
+ console.log(chalk.red(error));
44
+ return false;
45
+ }
46
+ };
47
+ export { isBFFProject };