@modern-js/prod-server 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 (130) hide show
  1. package/CHANGELOG.md +132 -0
  2. package/dist/js/modern/constants.js +32 -25
  3. package/dist/js/modern/index.js +11 -6
  4. package/dist/js/modern/libs/context/context.js +52 -84
  5. package/dist/js/modern/libs/context/index.js +5 -2
  6. package/dist/js/modern/libs/hook-api/index.js +42 -35
  7. package/dist/js/modern/libs/hook-api/route.js +6 -7
  8. package/dist/js/modern/libs/hook-api/template.js +20 -34
  9. package/dist/js/modern/libs/loadConfig.js +45 -24
  10. package/dist/js/modern/libs/metrics.js +3 -4
  11. package/dist/js/modern/libs/proxy.js +68 -37
  12. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -67
  13. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -216
  14. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
  15. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
  16. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
  17. package/dist/js/modern/libs/render/cache/index.js +88 -54
  18. package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
  19. package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -6
  20. package/dist/js/modern/libs/render/cache/spr.js +133 -117
  21. package/dist/js/modern/libs/render/cache/type.js +0 -1
  22. package/dist/js/modern/libs/render/cache/util.js +71 -39
  23. package/dist/js/modern/libs/render/index.js +76 -56
  24. package/dist/js/modern/libs/render/measure.js +38 -27
  25. package/dist/js/modern/libs/render/reader.js +65 -62
  26. package/dist/js/modern/libs/render/ssr.js +50 -32
  27. package/dist/js/modern/libs/render/static.js +50 -33
  28. package/dist/js/modern/libs/render/type.js +9 -6
  29. package/dist/js/modern/libs/route/index.js +8 -15
  30. package/dist/js/modern/libs/route/matcher.js +20 -34
  31. package/dist/js/modern/libs/route/route.js +9 -18
  32. package/dist/js/modern/libs/serve-file.js +33 -20
  33. package/dist/js/modern/server/index.js +144 -145
  34. package/dist/js/modern/server/modern-server-split.js +46 -12
  35. package/dist/js/modern/server/modern-server.js +377 -419
  36. package/dist/js/modern/type.js +0 -1
  37. package/dist/js/modern/utils.js +62 -43
  38. package/dist/js/modern/worker-server.js +34 -14
  39. package/dist/js/node/constants.js +45 -30
  40. package/dist/js/node/index.js +31 -57
  41. package/dist/js/node/libs/context/context.js +79 -94
  42. package/dist/js/node/libs/context/index.js +23 -13
  43. package/dist/js/node/libs/hook-api/index.js +69 -48
  44. package/dist/js/node/libs/hook-api/route.js +22 -11
  45. package/dist/js/node/libs/hook-api/template.js +36 -39
  46. package/dist/js/node/libs/loadConfig.js +69 -35
  47. package/dist/js/node/libs/metrics.js +21 -9
  48. package/dist/js/node/libs/proxy.js +86 -44
  49. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +132 -70
  50. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +268 -218
  51. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +61 -55
  52. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +54 -40
  53. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +101 -119
  54. package/dist/js/node/libs/render/cache/index.js +110 -64
  55. package/dist/js/node/libs/render/cache/page-caches/index.js +50 -14
  56. package/dist/js/node/libs/render/cache/page-caches/lru.js +29 -12
  57. package/dist/js/node/libs/render/cache/spr.js +156 -129
  58. package/dist/js/node/libs/render/cache/type.js +0 -5
  59. package/dist/js/node/libs/render/cache/util.js +88 -45
  60. package/dist/js/node/libs/render/index.js +102 -67
  61. package/dist/js/node/libs/render/measure.js +55 -31
  62. package/dist/js/node/libs/render/reader.js +87 -70
  63. package/dist/js/node/libs/render/ssr.js +76 -47
  64. package/dist/js/node/libs/render/static.js +75 -40
  65. package/dist/js/node/libs/render/type.js +27 -12
  66. package/dist/js/node/libs/route/index.js +26 -26
  67. package/dist/js/node/libs/route/matcher.js +36 -41
  68. package/dist/js/node/libs/route/route.js +25 -22
  69. package/dist/js/node/libs/serve-file.js +61 -32
  70. package/dist/js/node/server/index.js +160 -160
  71. package/dist/js/node/server/modern-server-split.js +68 -22
  72. package/dist/js/node/server/modern-server.js +395 -443
  73. package/dist/js/node/type.js +0 -3
  74. package/dist/js/node/utils.js +74 -52
  75. package/dist/js/node/worker-server.js +53 -21
  76. package/dist/js/treeshaking/constants.js +26 -25
  77. package/dist/js/treeshaking/index.js +10 -10
  78. package/dist/js/treeshaking/libs/context/context.js +268 -237
  79. package/dist/js/treeshaking/libs/context/index.js +3 -3
  80. package/dist/js/treeshaking/libs/hook-api/index.js +265 -143
  81. package/dist/js/treeshaking/libs/hook-api/route.js +65 -30
  82. package/dist/js/treeshaking/libs/hook-api/template.js +121 -85
  83. package/dist/js/treeshaking/libs/loadConfig.js +80 -37
  84. package/dist/js/treeshaking/libs/metrics.js +4 -10
  85. package/dist/js/treeshaking/libs/proxy.js +240 -76
  86. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +288 -121
  87. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +772 -455
  88. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +65 -51
  89. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -35
  90. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +144 -118
  91. package/dist/js/treeshaking/libs/render/cache/index.js +337 -175
  92. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +151 -27
  93. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +80 -42
  94. package/dist/js/treeshaking/libs/render/cache/spr.js +470 -340
  95. package/dist/js/treeshaking/libs/render/cache/type.js +1 -1
  96. package/dist/js/treeshaking/libs/render/cache/util.js +271 -92
  97. package/dist/js/treeshaking/libs/render/index.js +228 -95
  98. package/dist/js/treeshaking/libs/render/measure.js +142 -57
  99. package/dist/js/treeshaking/libs/render/reader.js +325 -177
  100. package/dist/js/treeshaking/libs/render/ssr.js +220 -95
  101. package/dist/js/treeshaking/libs/render/static.js +210 -78
  102. package/dist/js/treeshaking/libs/render/type.js +7 -6
  103. package/dist/js/treeshaking/libs/route/index.js +125 -89
  104. package/dist/js/treeshaking/libs/route/matcher.js +132 -107
  105. package/dist/js/treeshaking/libs/route/route.js +40 -26
  106. package/dist/js/treeshaking/libs/serve-file.js +177 -68
  107. package/dist/js/treeshaking/server/index.js +468 -327
  108. package/dist/js/treeshaking/server/modern-server-split.js +352 -144
  109. package/dist/js/treeshaking/server/modern-server.js +1046 -911
  110. package/dist/js/treeshaking/type.js +1 -1
  111. package/dist/js/treeshaking/utils.js +138 -81
  112. package/dist/js/treeshaking/worker-server.js +176 -55
  113. package/dist/types/index.d.ts +2 -0
  114. package/dist/types/libs/context/context.d.ts +4 -1
  115. package/dist/types/libs/loadConfig.d.ts +1 -0
  116. package/dist/types/libs/render/cache/index.d.ts +2 -0
  117. package/dist/types/libs/render/cache/spr.d.ts +2 -0
  118. package/dist/types/libs/route/route.d.ts +0 -1
  119. package/dist/types/server/index.d.ts +3 -0
  120. package/dist/types/utils.d.ts +1 -1
  121. package/dist/types/worker-server.d.ts +1 -2
  122. package/package.json +7 -14
  123. package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
  124. package/dist/js/modern/libs/render/modern/index.js +0 -37
  125. package/dist/js/node/libs/render/modern/browser-list.js +0 -14
  126. package/dist/js/node/libs/render/modern/index.js +0 -46
  127. package/dist/js/treeshaking/libs/render/modern/browser-list.js +0 -7
  128. package/dist/js/treeshaking/libs/render/modern/index.js +0 -39
  129. package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
  130. package/dist/types/libs/render/modern/index.d.ts +0 -3
@@ -1,464 +1,781 @@
1
- import _toArray from "@babel/runtime/helpers/esm/toArray";
2
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
4
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
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 asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (info.done) {
18
+ resolve(value);
19
+ } else {
20
+ Promise.resolve(value).then(_next, _throw);
21
+ }
22
+ }
23
+ function _asyncToGenerator(fn) {
24
+ return function() {
25
+ var self = this, args = arguments;
26
+ return new Promise(function(resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+ function _next(value) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
+ }
31
+ function _throw(err) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
+ }
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+ function _defineProperty(obj, key, value) {
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+ return obj;
50
+ }
51
+ function _iterableToArray(iter) {
52
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
+ }
54
+ function _nonIterableRest() {
55
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
57
+ function _objectSpread(target) {
58
+ for(var i = 1; i < arguments.length; i++){
59
+ var source = arguments[i] != null ? arguments[i] : {};
60
+ var ownKeys = Object.keys(source);
61
+ if (typeof Object.getOwnPropertySymbols === "function") {
62
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
63
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
64
+ }));
65
+ }
66
+ ownKeys.forEach(function(key) {
67
+ _defineProperty(target, key, source[key]);
68
+ });
69
+ }
70
+ return target;
71
+ }
72
+ function _toArray(arr) {
73
+ return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
74
+ }
75
+ function _unsupportedIterableToArray(o, minLen) {
76
+ if (!o) return;
77
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
78
+ var n = Object.prototype.toString.call(o).slice(8, -1);
79
+ if (n === "Object" && o.constructor) n = o.constructor.name;
80
+ if (n === "Map" || n === "Set") return Array.from(n);
81
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
82
+ }
83
+ var __generator = this && this.__generator || function(thisArg, body) {
84
+ var f, y, t, g, _ = {
85
+ label: 0,
86
+ sent: function() {
87
+ if (t[0] & 1) throw t[1];
88
+ return t[1];
89
+ },
90
+ trys: [],
91
+ ops: []
92
+ };
93
+ return g = {
94
+ next: verb(0),
95
+ "throw": verb(1),
96
+ "return": verb(2)
97
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
98
+ return this;
99
+ }), g;
100
+ function verb(n) {
101
+ return function(v) {
102
+ return step([
103
+ n,
104
+ v
105
+ ]);
106
+ };
107
+ }
108
+ function step(op) {
109
+ if (f) throw new TypeError("Generator is already executing.");
110
+ while(_)try {
111
+ 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;
112
+ if (y = 0, t) op = [
113
+ op[0] & 2,
114
+ t.value
115
+ ];
116
+ switch(op[0]){
117
+ case 0:
118
+ case 1:
119
+ t = op;
120
+ break;
121
+ case 4:
122
+ _.label++;
123
+ return {
124
+ value: op[1],
125
+ done: false
126
+ };
127
+ case 5:
128
+ _.label++;
129
+ y = op[1];
130
+ op = [
131
+ 0
132
+ ];
133
+ continue;
134
+ case 7:
135
+ op = _.ops.pop();
136
+ _.trys.pop();
137
+ continue;
138
+ default:
139
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
140
+ _ = 0;
141
+ continue;
142
+ }
143
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
144
+ _.label = op[1];
145
+ break;
146
+ }
147
+ if (op[0] === 6 && _.label < t[1]) {
148
+ _.label = t[1];
149
+ t = op;
150
+ break;
151
+ }
152
+ if (t && _.label < t[2]) {
153
+ _.label = t[2];
154
+ _.ops.push(op);
155
+ break;
156
+ }
157
+ if (t[2]) _.ops.pop();
158
+ _.trys.pop();
159
+ continue;
160
+ }
161
+ op = body.call(thisArg, _);
162
+ } catch (e) {
163
+ op = [
164
+ 6,
165
+ e
166
+ ];
167
+ y = 0;
168
+ } finally{
169
+ f = t = 0;
170
+ }
171
+ if (op[0] & 5) throw op[1];
172
+ return {
173
+ value: op[0] ? op[1] : void 0,
174
+ done: true
175
+ };
176
+ }
177
+ };
6
178
  import { createCache, destroyCache } from "../spr";
7
179
  import { errorConfiguration } from "./error-configuration";
8
180
  import { cacheabelAry } from "./cacheable";
9
181
  import { matchedCacheableAry } from "./matched-cache";
10
- var createCacheConfig = function createCacheConfig() {
11
- var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
12
- return _objectSpread({
13
- excludes: null,
14
- includes: null,
15
- interval: 10,
16
- staleLimit: false,
17
- level: 0,
18
- fallback: false,
19
- matches: null
20
- }, config);
182
+ var createCacheConfig = function() {
183
+ var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
184
+ return _objectSpread({
185
+ excludes: null,
186
+ includes: null,
187
+ interval: 10,
188
+ staleLimit: false,
189
+ level: 0,
190
+ fallback: false,
191
+ matches: null
192
+ }, config);
21
193
  };
22
- jest.setTimeout(60000);
23
- describe('cache', function () {
24
- it('should cache correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
25
- var cache, context, content, cacheConfig, cacheResult;
26
- return _regeneratorRuntime().wrap(function _callee$(_context) {
27
- while (1) {
28
- switch (_context.prev = _context.next) {
29
- case 0:
30
- destroyCache();
31
- cache = createCache();
32
- context = {
33
- entry: '',
34
- pathname: '',
35
- query: {},
36
- headers: {}
37
- };
38
- content = 'hello';
39
- cacheConfig = createCacheConfig();
40
- _context.next = 7;
41
- return cache.set(context, content, cacheConfig, true);
42
- case 7:
43
- _context.next = 9;
44
- return cache.get(context);
45
- case 9:
46
- cacheResult = _context.sent;
47
- expect(cacheResult).not.toBe(null);
48
- expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe('hello');
49
- case 12:
50
- case "end":
51
- return _context.stop();
52
- }
53
- }
54
- }, _callee);
55
- })));
56
- it('should ignore cache set when cache config not exist', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
57
- var cache, context, content, shouldCache;
58
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
59
- while (1) {
60
- switch (_context2.prev = _context2.next) {
61
- case 0:
62
- destroyCache();
63
- destroyCache();
64
- cache = createCache();
65
- context = {
66
- entry: '',
67
- pathname: '',
68
- query: {},
69
- headers: {}
70
- };
71
- content = 'hello';
72
- _context2.next = 7;
73
- return cache.set(context, content, null, true);
74
- case 7:
75
- shouldCache = _context2.sent;
76
- expect(shouldCache).toBe(false);
77
- case 9:
78
- case "end":
79
- return _context2.stop();
80
- }
81
- }
82
- }, _callee2);
83
- })));
84
- it('should calcual cache key error', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
85
- var cache, content, _iterator, _step, config, cacheConfig, tmpEntry, context, shouldCache;
86
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
87
- while (1) {
88
- switch (_context3.prev = _context3.next) {
89
- case 0:
90
- destroyCache();
91
- cache = createCache();
92
- content = 'hello';
93
- _iterator = _createForOfIteratorHelper(errorConfiguration);
94
- _context3.prev = 4;
95
- _iterator.s();
96
- case 6:
97
- if ((_step = _iterator.n()).done) {
98
- _context3.next = 17;
99
- break;
194
+ jest.setTimeout(6e4);
195
+ describe("cache", function() {
196
+ it("should cache correctly", /*#__PURE__*/ _asyncToGenerator(function() {
197
+ var cache, context, content, cacheConfig, cacheResult;
198
+ return __generator(this, function(_state) {
199
+ switch(_state.label){
200
+ case 0:
201
+ destroyCache();
202
+ cache = createCache();
203
+ context = {
204
+ entry: "",
205
+ pathname: "",
206
+ query: {},
207
+ headers: {}
208
+ };
209
+ content = "hello";
210
+ cacheConfig = createCacheConfig();
211
+ return [
212
+ 4,
213
+ cache.set(context, content, cacheConfig, true)
214
+ ];
215
+ case 1:
216
+ _state.sent();
217
+ return [
218
+ 4,
219
+ cache.get(context)
220
+ ];
221
+ case 2:
222
+ cacheResult = _state.sent();
223
+ expect(cacheResult).not.toBe(null);
224
+ expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe("hello");
225
+ return [
226
+ 2
227
+ ];
100
228
  }
101
- config = _step.value;
102
- cacheConfig = createCacheConfig(config);
103
- tmpEntry = Math.random().toString();
104
- context = {
105
- entry: tmpEntry,
106
- pathname: '',
107
- query: {},
108
- headers: {}
109
- };
110
- _context3.next = 13;
111
- return cache.set(context, content, cacheConfig);
112
- case 13:
113
- shouldCache = _context3.sent;
114
- expect(shouldCache).toBe(false);
115
- case 15:
116
- _context3.next = 6;
117
- break;
118
- case 17:
119
- _context3.next = 22;
120
- break;
121
- case 19:
122
- _context3.prev = 19;
123
- _context3.t0 = _context3["catch"](4);
124
- _iterator.e(_context3.t0);
125
- case 22:
126
- _context3.prev = 22;
127
- _iterator.f();
128
- return _context3.finish(22);
129
- case 25:
130
- case "end":
131
- return _context3.stop();
132
- }
133
- }
134
- }, _callee3, null, [[4, 19, 22, 25]]);
135
- })));
136
- it('should get nothing for diff requestKey', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
137
- var cache, context, content, cacheConfig, context_req, cacheResult;
138
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
139
- while (1) {
140
- switch (_context4.prev = _context4.next) {
141
- case 0:
142
- destroyCache();
143
- cache = createCache();
144
- context = {
145
- entry: '',
146
- pathname: '',
147
- query: {},
148
- headers: {}
149
- };
150
- content = 'hello';
151
- cacheConfig = createCacheConfig({
152
- level: 1,
153
- includes: {
154
- query: ['name']
155
- }
156
- });
157
- _context4.next = 7;
158
- return cache.set(context, content, cacheConfig, true);
159
- case 7:
160
- context_req = {
161
- entry: '',
162
- pathname: '/home',
163
- query: {},
164
- headers: {}
165
- };
166
- _context4.next = 10;
167
- return cache.get(context_req);
168
- case 10:
169
- cacheResult = _context4.sent;
170
- expect(cacheResult).toBe(null);
171
- case 12:
172
- case "end":
173
- return _context4.stop();
174
- }
175
- }
176
- }, _callee4);
177
- })));
178
- it('should get nothing for diff cacheHash', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
179
- var cache, context, content, cacheConfig, context_req, cacheResult;
180
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
181
- while (1) {
182
- switch (_context5.prev = _context5.next) {
183
- case 0:
184
- destroyCache();
185
- cache = createCache();
186
- context = {
187
- entry: '',
188
- pathname: '',
189
- query: {},
190
- headers: {}
191
- };
192
- content = 'hello';
193
- cacheConfig = createCacheConfig({
194
- level: 1,
195
- includes: {
196
- query: ['name']
197
- }
198
- });
199
- _context5.next = 7;
200
- return cache.set(context, content, cacheConfig, true);
201
- case 7:
202
- context_req = {
203
- entry: '',
204
- pathname: '',
205
- query: {
206
- name: 'zll'
207
- },
208
- headers: {}
209
- };
210
- _context5.next = 10;
211
- return cache.get(context_req);
212
- case 10:
213
- cacheResult = _context5.sent;
214
- expect(cacheResult).toBe(null);
215
- case 12:
216
- case "end":
217
- return _context5.stop();
218
- }
219
- }
220
- }, _callee5);
221
- })));
222
- it('should get cache correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
223
- var cache, _iterator2, _step2, cacheable, context, cacheConfig, cacheResult;
224
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
225
- while (1) {
226
- switch (_context6.prev = _context6.next) {
227
- case 0:
228
- destroyCache();
229
- cache = createCache();
230
- _iterator2 = _createForOfIteratorHelper(cacheabelAry);
231
- _context6.prev = 3;
232
- _iterator2.s();
233
- case 5:
234
- if ((_step2 = _iterator2.n()).done) {
235
- _context6.next = 17;
236
- break;
229
+ });
230
+ }));
231
+ it("should ignore cache set when cache config not exist", /*#__PURE__*/ _asyncToGenerator(function() {
232
+ var cache, context, content, shouldCache;
233
+ return __generator(this, function(_state) {
234
+ switch(_state.label){
235
+ case 0:
236
+ destroyCache();
237
+ destroyCache();
238
+ cache = createCache();
239
+ context = {
240
+ entry: "",
241
+ pathname: "",
242
+ query: {},
243
+ headers: {}
244
+ };
245
+ content = "hello";
246
+ return [
247
+ 4,
248
+ cache.set(context, content, null, true)
249
+ ];
250
+ case 1:
251
+ shouldCache = _state.sent();
252
+ expect(shouldCache).toBe(false);
253
+ return [
254
+ 2
255
+ ];
237
256
  }
238
- cacheable = _step2.value;
239
- context = {
240
- entry: '',
241
- pathname: cacheable.requestOpt.url,
242
- query: cacheable.requestOpt.query || {},
243
- headers: cacheable.requestOpt.headers || {}
244
- };
245
- cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
246
- _context6.next = 11;
247
- return cache.set(context, cacheable.content, cacheConfig, true);
248
- case 11:
249
- _context6.next = 13;
250
- return cache.get(context);
251
- case 13:
252
- cacheResult = _context6.sent;
253
- expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(cacheable.content);
254
- case 15:
255
- _context6.next = 5;
256
- break;
257
- case 17:
258
- _context6.next = 22;
259
- break;
260
- case 19:
261
- _context6.prev = 19;
262
- _context6.t0 = _context6["catch"](3);
263
- _iterator2.e(_context6.t0);
264
- case 22:
265
- _context6.prev = 22;
266
- _iterator2.f();
267
- return _context6.finish(22);
268
- case 25:
269
- case "end":
270
- return _context6.stop();
271
- }
272
- }
273
- }, _callee6, null, [[3, 19, 22, 25]]);
274
- })));
275
- it('should match cache correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
276
- var cache, _iterator3, _step3, _cacheResult, cacheable, _cacheable, baseCacheable, matchOne, other, _baseCacheable$reques, requestOpt, cacheConfig, content, context, matchContext, cacheResult, _iterator4, _step4, notMatch, notMatchContext, nothing;
277
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
278
- while (1) {
279
- switch (_context7.prev = _context7.next) {
280
- case 0:
281
- destroyCache();
282
- cache = createCache();
283
- _iterator3 = _createForOfIteratorHelper(matchedCacheableAry);
284
- _context7.prev = 3;
285
- _iterator3.s();
286
- case 5:
287
- if ((_step3 = _iterator3.n()).done) {
288
- _context7.next = 39;
289
- break;
257
+ });
258
+ }));
259
+ it("should calcual cache key error", /*#__PURE__*/ _asyncToGenerator(function() {
260
+ var cache, content, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, config, cacheConfig, tmpEntry, context, shouldCache, err;
261
+ return __generator(this, function(_state) {
262
+ switch(_state.label){
263
+ case 0:
264
+ destroyCache();
265
+ cache = createCache();
266
+ content = "hello";
267
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
268
+ _state.label = 1;
269
+ case 1:
270
+ _state.trys.push([
271
+ 1,
272
+ 6,
273
+ 7,
274
+ 8
275
+ ]);
276
+ _iterator = errorConfiguration[Symbol.iterator]();
277
+ _state.label = 2;
278
+ case 2:
279
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
280
+ 3,
281
+ 5
282
+ ];
283
+ config = _step.value;
284
+ cacheConfig = createCacheConfig(config);
285
+ tmpEntry = Math.random().toString();
286
+ context = {
287
+ entry: tmpEntry,
288
+ pathname: "",
289
+ query: {},
290
+ headers: {}
291
+ };
292
+ return [
293
+ 4,
294
+ cache.set(context, content, cacheConfig)
295
+ ];
296
+ case 3:
297
+ shouldCache = _state.sent();
298
+ expect(shouldCache).toBe(false);
299
+ _state.label = 4;
300
+ case 4:
301
+ _iteratorNormalCompletion = true;
302
+ return [
303
+ 3,
304
+ 2
305
+ ];
306
+ case 5:
307
+ return [
308
+ 3,
309
+ 8
310
+ ];
311
+ case 6:
312
+ err = _state.sent();
313
+ _didIteratorError = true;
314
+ _iteratorError = err;
315
+ return [
316
+ 3,
317
+ 8
318
+ ];
319
+ case 7:
320
+ try {
321
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
322
+ _iterator.return();
323
+ }
324
+ } finally{
325
+ if (_didIteratorError) {
326
+ throw _iteratorError;
327
+ }
328
+ }
329
+ return [
330
+ 7
331
+ ];
332
+ case 8:
333
+ return [
334
+ 2
335
+ ];
290
336
  }
291
- cacheable = _step3.value;
292
- _cacheable = _toArray(cacheable), baseCacheable = _cacheable[0], matchOne = _cacheable[1], other = _cacheable.slice(2);
293
- _baseCacheable$reques = baseCacheable.requestOpt, requestOpt = _baseCacheable$reques === void 0 ? {} : _baseCacheable$reques, cacheConfig = baseCacheable.cacheConfig, content = baseCacheable.content;
294
- context = {
295
- entry: '',
296
- pathname: requestOpt.url,
297
- query: requestOpt.query,
298
- headers: requestOpt.headers
299
- };
300
- _context7.next = 12;
301
- return cache.set(context, content, createCacheConfig(cacheConfig), true);
302
- case 12:
303
- matchContext = {
304
- entry: '',
305
- pathname: matchOne.url,
306
- query: matchOne.query,
307
- headers: matchOne.headers
308
- };
309
- _context7.next = 15;
310
- return cache.get(matchContext);
311
- case 15:
312
- cacheResult = _context7.sent;
313
- expect((_cacheResult = cacheResult) === null || _cacheResult === void 0 ? void 0 : _cacheResult.content).toBe(content);
314
- _iterator4 = _createForOfIteratorHelper(other);
315
- _context7.prev = 18;
316
- _iterator4.s();
317
- case 20:
318
- if ((_step4 = _iterator4.n()).done) {
319
- _context7.next = 29;
320
- break;
337
+ });
338
+ }));
339
+ it("should get nothing for diff requestKey", /*#__PURE__*/ _asyncToGenerator(function() {
340
+ var cache, context, content, cacheConfig, context_req, cacheResult;
341
+ return __generator(this, function(_state) {
342
+ switch(_state.label){
343
+ case 0:
344
+ destroyCache();
345
+ cache = createCache();
346
+ context = {
347
+ entry: "",
348
+ pathname: "",
349
+ query: {},
350
+ headers: {}
351
+ };
352
+ content = "hello";
353
+ cacheConfig = createCacheConfig({
354
+ level: 1,
355
+ includes: {
356
+ query: [
357
+ "name"
358
+ ]
359
+ }
360
+ });
361
+ return [
362
+ 4,
363
+ cache.set(context, content, cacheConfig, true)
364
+ ];
365
+ case 1:
366
+ _state.sent();
367
+ context_req = {
368
+ entry: "",
369
+ pathname: "/home",
370
+ query: {},
371
+ headers: {}
372
+ };
373
+ return [
374
+ 4,
375
+ cache.get(context_req)
376
+ ];
377
+ case 2:
378
+ cacheResult = _state.sent();
379
+ expect(cacheResult).toBe(null);
380
+ return [
381
+ 2
382
+ ];
321
383
  }
322
- notMatch = _step4.value;
323
- notMatchContext = {
324
- entry: '',
325
- pathname: notMatch.url,
326
- query: notMatch.query,
327
- headers: notMatch.headers
328
- };
329
- _context7.next = 25;
330
- return cache.get(notMatchContext);
331
- case 25:
332
- nothing = _context7.sent;
333
- expect(nothing).toBe(null);
334
- case 27:
335
- _context7.next = 20;
336
- break;
337
- case 29:
338
- _context7.next = 34;
339
- break;
340
- case 31:
341
- _context7.prev = 31;
342
- _context7.t0 = _context7["catch"](18);
343
- _iterator4.e(_context7.t0);
344
- case 34:
345
- _context7.prev = 34;
346
- _iterator4.f();
347
- return _context7.finish(34);
348
- case 37:
349
- _context7.next = 5;
350
- break;
351
- case 39:
352
- _context7.next = 44;
353
- break;
354
- case 41:
355
- _context7.prev = 41;
356
- _context7.t1 = _context7["catch"](3);
357
- _iterator3.e(_context7.t1);
358
- case 44:
359
- _context7.prev = 44;
360
- _iterator3.f();
361
- return _context7.finish(44);
362
- case 47:
363
- case "end":
364
- return _context7.stop();
365
- }
366
- }
367
- }, _callee7, null, [[3, 41, 44, 47], [18, 31, 34, 37]]);
368
- })));
369
- it('should stale cache correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
370
- var cache, context, config, content, shouldCache, freshResult, staleResult;
371
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
372
- while (1) {
373
- switch (_context8.prev = _context8.next) {
374
- case 0:
375
- destroyCache();
376
- cache = createCache();
377
- context = {
378
- entry: '',
379
- pathname: '',
380
- query: {},
381
- headers: {}
382
- };
383
- config = createCacheConfig({
384
- interval: 5
385
- });
386
- content = 'hello';
387
- _context8.next = 7;
388
- return cache.set(context, content, config, true);
389
- case 7:
390
- shouldCache = _context8.sent;
391
- expect(shouldCache.value).toBe(true);
392
- _context8.next = 11;
393
- return cache.get(context);
394
- case 11:
395
- freshResult = _context8.sent;
396
- expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isStale).toBe(false);
397
- _context8.next = 15;
398
- return new Promise(function (resolve) {
399
- setTimeout(function () {
400
- resolve();
401
- }, 6000);
402
- });
403
- case 15:
404
- _context8.next = 17;
405
- return cache.get(context);
406
- case 17:
407
- staleResult = _context8.sent;
408
- expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
409
- case 19:
410
- case "end":
411
- return _context8.stop();
412
- }
413
- }
414
- }, _callee8);
415
- })));
416
- it('should garbage cache correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
417
- var cache, context, config, content, shouldCache, freshResult, staleResult;
418
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
419
- while (1) {
420
- switch (_context9.prev = _context9.next) {
421
- case 0:
422
- destroyCache();
423
- cache = createCache();
424
- context = {
425
- entry: '',
426
- pathname: '',
427
- query: {},
428
- headers: {}
429
- };
430
- config = createCacheConfig({
431
- interval: 3,
432
- staleLimit: 8
433
- });
434
- content = 'hello';
435
- _context9.next = 7;
436
- return cache.set(context, content, config, true);
437
- case 7:
438
- shouldCache = _context9.sent;
439
- expect(shouldCache.value).toBe(true);
440
- _context9.next = 11;
441
- return cache.get(context);
442
- case 11:
443
- freshResult = _context9.sent;
444
- expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isGarbage).toBe(false);
445
- _context9.next = 15;
446
- return new Promise(function (resolve) {
447
- setTimeout(function () {
448
- resolve();
449
- }, 10000);
450
- });
451
- case 15:
452
- _context9.next = 17;
453
- return cache.get(context);
454
- case 17:
455
- staleResult = _context9.sent;
456
- expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isGarbage).toBe(true);
457
- case 19:
458
- case "end":
459
- return _context9.stop();
460
- }
461
- }
462
- }, _callee9);
463
- })));
464
- });
384
+ });
385
+ }));
386
+ it("should get nothing for diff cacheHash", /*#__PURE__*/ _asyncToGenerator(function() {
387
+ var cache, context, content, cacheConfig, context_req, cacheResult;
388
+ return __generator(this, function(_state) {
389
+ switch(_state.label){
390
+ case 0:
391
+ destroyCache();
392
+ cache = createCache();
393
+ context = {
394
+ entry: "",
395
+ pathname: "",
396
+ query: {},
397
+ headers: {}
398
+ };
399
+ content = "hello";
400
+ cacheConfig = createCacheConfig({
401
+ level: 1,
402
+ includes: {
403
+ query: [
404
+ "name"
405
+ ]
406
+ }
407
+ });
408
+ return [
409
+ 4,
410
+ cache.set(context, content, cacheConfig, true)
411
+ ];
412
+ case 1:
413
+ _state.sent();
414
+ context_req = {
415
+ entry: "",
416
+ pathname: "",
417
+ query: {
418
+ name: "zll"
419
+ },
420
+ headers: {}
421
+ };
422
+ return [
423
+ 4,
424
+ cache.get(context_req)
425
+ ];
426
+ case 2:
427
+ cacheResult = _state.sent();
428
+ expect(cacheResult).toBe(null);
429
+ return [
430
+ 2
431
+ ];
432
+ }
433
+ });
434
+ }));
435
+ it("should get cache correctly", /*#__PURE__*/ _asyncToGenerator(function() {
436
+ var cache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, cacheable, context, cacheConfig, cacheResult, err;
437
+ return __generator(this, function(_state) {
438
+ switch(_state.label){
439
+ case 0:
440
+ destroyCache();
441
+ cache = createCache();
442
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
443
+ _state.label = 1;
444
+ case 1:
445
+ _state.trys.push([
446
+ 1,
447
+ 7,
448
+ 8,
449
+ 9
450
+ ]);
451
+ _iterator = cacheabelAry[Symbol.iterator]();
452
+ _state.label = 2;
453
+ case 2:
454
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
455
+ 3,
456
+ 6
457
+ ];
458
+ cacheable = _step.value;
459
+ context = {
460
+ entry: "",
461
+ pathname: cacheable.requestOpt.url,
462
+ query: cacheable.requestOpt.query || {},
463
+ headers: cacheable.requestOpt.headers || {}
464
+ };
465
+ cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
466
+ return [
467
+ 4,
468
+ cache.set(context, cacheable.content, cacheConfig, true)
469
+ ];
470
+ case 3:
471
+ _state.sent();
472
+ return [
473
+ 4,
474
+ cache.get(context)
475
+ ];
476
+ case 4:
477
+ cacheResult = _state.sent();
478
+ expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(cacheable.content);
479
+ _state.label = 5;
480
+ case 5:
481
+ _iteratorNormalCompletion = true;
482
+ return [
483
+ 3,
484
+ 2
485
+ ];
486
+ case 6:
487
+ return [
488
+ 3,
489
+ 9
490
+ ];
491
+ case 7:
492
+ err = _state.sent();
493
+ _didIteratorError = true;
494
+ _iteratorError = err;
495
+ return [
496
+ 3,
497
+ 9
498
+ ];
499
+ case 8:
500
+ try {
501
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
502
+ _iterator.return();
503
+ }
504
+ } finally{
505
+ if (_didIteratorError) {
506
+ throw _iteratorError;
507
+ }
508
+ }
509
+ return [
510
+ 7
511
+ ];
512
+ case 9:
513
+ return [
514
+ 2
515
+ ];
516
+ }
517
+ });
518
+ }));
519
+ it("should match cache correctly", /*#__PURE__*/ _asyncToGenerator(function() {
520
+ var cache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, cacheable, _cacheable, baseCacheable, matchOne, other, _requestOpt, requestOpt, cacheConfig, content, context, matchContext, cacheResult, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, notMatch, notMatchContext, nothing, err, err;
521
+ return __generator(this, function(_state) {
522
+ switch(_state.label){
523
+ case 0:
524
+ destroyCache();
525
+ cache = createCache();
526
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
527
+ _state.label = 1;
528
+ case 1:
529
+ _state.trys.push([
530
+ 1,
531
+ 14,
532
+ 15,
533
+ 16
534
+ ]);
535
+ _iterator = matchedCacheableAry[Symbol.iterator]();
536
+ _state.label = 2;
537
+ case 2:
538
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
539
+ 3,
540
+ 13
541
+ ];
542
+ cacheable = _step.value;
543
+ _cacheable = _toArray(cacheable), baseCacheable = _cacheable[0], matchOne = _cacheable[1], other = _cacheable.slice(2);
544
+ _requestOpt = baseCacheable.requestOpt, requestOpt = _requestOpt === void 0 ? {} : _requestOpt, cacheConfig = baseCacheable.cacheConfig, content = baseCacheable.content;
545
+ context = {
546
+ entry: "",
547
+ pathname: requestOpt.url,
548
+ query: requestOpt.query,
549
+ headers: requestOpt.headers
550
+ };
551
+ return [
552
+ 4,
553
+ cache.set(context, content, createCacheConfig(cacheConfig), true)
554
+ ];
555
+ case 3:
556
+ _state.sent();
557
+ matchContext = {
558
+ entry: "",
559
+ pathname: matchOne.url,
560
+ query: matchOne.query,
561
+ headers: matchOne.headers
562
+ };
563
+ return [
564
+ 4,
565
+ cache.get(matchContext)
566
+ ];
567
+ case 4:
568
+ cacheResult = _state.sent();
569
+ expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(content);
570
+ _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
571
+ _state.label = 5;
572
+ case 5:
573
+ _state.trys.push([
574
+ 5,
575
+ 10,
576
+ 11,
577
+ 12
578
+ ]);
579
+ _iterator1 = other[Symbol.iterator]();
580
+ _state.label = 6;
581
+ case 6:
582
+ if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
583
+ 3,
584
+ 9
585
+ ];
586
+ notMatch = _step1.value;
587
+ notMatchContext = {
588
+ entry: "",
589
+ pathname: notMatch.url,
590
+ query: notMatch.query,
591
+ headers: notMatch.headers
592
+ };
593
+ return [
594
+ 4,
595
+ cache.get(notMatchContext)
596
+ ];
597
+ case 7:
598
+ nothing = _state.sent();
599
+ expect(nothing).toBe(null);
600
+ _state.label = 8;
601
+ case 8:
602
+ _iteratorNormalCompletion1 = true;
603
+ return [
604
+ 3,
605
+ 6
606
+ ];
607
+ case 9:
608
+ return [
609
+ 3,
610
+ 12
611
+ ];
612
+ case 10:
613
+ err = _state.sent();
614
+ _didIteratorError1 = true;
615
+ _iteratorError1 = err;
616
+ return [
617
+ 3,
618
+ 12
619
+ ];
620
+ case 11:
621
+ try {
622
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
623
+ _iterator1.return();
624
+ }
625
+ } finally{
626
+ if (_didIteratorError1) {
627
+ throw _iteratorError1;
628
+ }
629
+ }
630
+ return [
631
+ 7
632
+ ];
633
+ case 12:
634
+ _iteratorNormalCompletion = true;
635
+ return [
636
+ 3,
637
+ 2
638
+ ];
639
+ case 13:
640
+ return [
641
+ 3,
642
+ 16
643
+ ];
644
+ case 14:
645
+ err = _state.sent();
646
+ _didIteratorError = true;
647
+ _iteratorError = err;
648
+ return [
649
+ 3,
650
+ 16
651
+ ];
652
+ case 15:
653
+ try {
654
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
655
+ _iterator.return();
656
+ }
657
+ } finally{
658
+ if (_didIteratorError) {
659
+ throw _iteratorError;
660
+ }
661
+ }
662
+ return [
663
+ 7
664
+ ];
665
+ case 16:
666
+ return [
667
+ 2
668
+ ];
669
+ }
670
+ });
671
+ }));
672
+ it("should stale cache correctly", /*#__PURE__*/ _asyncToGenerator(function() {
673
+ var cache, context, config, content, shouldCache, freshResult, staleResult;
674
+ return __generator(this, function(_state) {
675
+ switch(_state.label){
676
+ case 0:
677
+ destroyCache();
678
+ cache = createCache();
679
+ context = {
680
+ entry: "",
681
+ pathname: "",
682
+ query: {},
683
+ headers: {}
684
+ };
685
+ config = createCacheConfig({
686
+ interval: 5
687
+ });
688
+ content = "hello";
689
+ return [
690
+ 4,
691
+ cache.set(context, content, config, true)
692
+ ];
693
+ case 1:
694
+ shouldCache = _state.sent();
695
+ expect(shouldCache.value).toBe(true);
696
+ return [
697
+ 4,
698
+ cache.get(context)
699
+ ];
700
+ case 2:
701
+ freshResult = _state.sent();
702
+ expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isStale).toBe(false);
703
+ return [
704
+ 4,
705
+ new Promise(function(resolve) {
706
+ setTimeout(function() {
707
+ resolve();
708
+ }, 6e3);
709
+ })
710
+ ];
711
+ case 3:
712
+ _state.sent();
713
+ return [
714
+ 4,
715
+ cache.get(context)
716
+ ];
717
+ case 4:
718
+ staleResult = _state.sent();
719
+ expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
720
+ return [
721
+ 2
722
+ ];
723
+ }
724
+ });
725
+ }));
726
+ it("should garbage cache correctly", /*#__PURE__*/ _asyncToGenerator(function() {
727
+ var cache, context, config, content, shouldCache, freshResult, staleResult;
728
+ return __generator(this, function(_state) {
729
+ switch(_state.label){
730
+ case 0:
731
+ destroyCache();
732
+ cache = createCache();
733
+ context = {
734
+ entry: "",
735
+ pathname: "",
736
+ query: {},
737
+ headers: {}
738
+ };
739
+ config = createCacheConfig({
740
+ interval: 3,
741
+ staleLimit: 8
742
+ });
743
+ content = "hello";
744
+ return [
745
+ 4,
746
+ cache.set(context, content, config, true)
747
+ ];
748
+ case 1:
749
+ shouldCache = _state.sent();
750
+ expect(shouldCache.value).toBe(true);
751
+ return [
752
+ 4,
753
+ cache.get(context)
754
+ ];
755
+ case 2:
756
+ freshResult = _state.sent();
757
+ expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isGarbage).toBe(false);
758
+ return [
759
+ 4,
760
+ new Promise(function(resolve) {
761
+ setTimeout(function() {
762
+ resolve();
763
+ }, 1e4);
764
+ })
765
+ ];
766
+ case 3:
767
+ _state.sent();
768
+ return [
769
+ 4,
770
+ cache.get(context)
771
+ ];
772
+ case 4:
773
+ staleResult = _state.sent();
774
+ expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isGarbage).toBe(true);
775
+ return [
776
+ 2
777
+ ];
778
+ }
779
+ });
780
+ }));
781
+ });