@modern-js/prod-server 2.0.0-beta.0 → 2.0.0-beta.2
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.
- package/CHANGELOG.md +110 -0
- package/dist/js/modern/constants.js +0 -2
- package/dist/js/modern/index.js +0 -1
- package/dist/js/modern/libs/context/context.js +10 -56
- package/dist/js/modern/libs/hook-api/index.js +0 -31
- package/dist/js/modern/libs/hook-api/route.js +0 -8
- package/dist/js/modern/libs/hook-api/template.js +0 -16
- package/dist/js/modern/libs/loadConfig.js +3 -10
- package/dist/js/modern/libs/metrics.js +6 -6
- package/dist/js/modern/libs/proxy.js +7 -12
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -1
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -9
- package/dist/js/modern/libs/render/cache/index.js +8 -16
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -10
- package/dist/js/modern/libs/render/cache/spr.js +12 -62
- package/dist/js/modern/libs/render/cache/util.js +0 -6
- package/dist/js/modern/libs/render/index.js +6 -11
- package/dist/js/modern/libs/render/measure.js +1 -11
- package/dist/js/modern/libs/render/modern/index.js +2 -13
- package/dist/js/modern/libs/render/reader.js +13 -24
- package/dist/js/modern/libs/render/ssr.js +5 -6
- package/dist/js/modern/libs/render/static.js +6 -9
- package/dist/js/modern/libs/render/type.js +0 -1
- package/dist/js/modern/libs/route/index.js +8 -19
- package/dist/js/modern/libs/route/matcher.js +21 -29
- package/dist/js/modern/libs/route/route.js +0 -13
- package/dist/js/modern/libs/serve-file.js +5 -6
- package/dist/js/modern/server/index.js +25 -52
- package/dist/js/modern/server/modern-server-split.js +0 -11
- package/dist/js/modern/server/modern-server.js +87 -167
- package/dist/js/modern/utils.js +12 -27
- package/dist/js/modern/worker-server.js +34 -0
- package/dist/js/node/constants.js +0 -2
- package/dist/js/node/index.js +0 -10
- package/dist/js/node/libs/context/context.js +10 -65
- package/dist/js/node/libs/context/index.js +0 -3
- package/dist/js/node/libs/hook-api/index.js +0 -42
- package/dist/js/node/libs/hook-api/route.js +0 -10
- package/dist/js/node/libs/hook-api/template.js +0 -22
- package/dist/js/node/libs/loadConfig.js +3 -22
- package/dist/js/node/libs/metrics.js +6 -6
- package/dist/js/node/libs/proxy.js +7 -17
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -5
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -12
- package/dist/js/node/libs/render/cache/index.js +8 -22
- package/dist/js/node/libs/render/cache/page-caches/index.js +0 -2
- package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -14
- package/dist/js/node/libs/render/cache/spr.js +12 -71
- package/dist/js/node/libs/render/cache/util.js +0 -18
- package/dist/js/node/libs/render/index.js +6 -26
- package/dist/js/node/libs/render/measure.js +0 -17
- package/dist/js/node/libs/render/modern/index.js +2 -20
- package/dist/js/node/libs/render/reader.js +12 -39
- package/dist/js/node/libs/render/ssr.js +4 -16
- package/dist/js/node/libs/render/static.js +6 -18
- package/dist/js/node/libs/render/type.js +0 -1
- package/dist/js/node/libs/route/index.js +8 -22
- package/dist/js/node/libs/route/matcher.js +18 -34
- package/dist/js/node/libs/route/route.js +0 -15
- package/dist/js/node/libs/serve-file.js +5 -13
- package/dist/js/node/server/index.js +25 -72
- package/dist/js/node/server/modern-server-split.js +0 -13
- package/dist/js/node/server/modern-server.js +87 -196
- package/dist/js/node/utils.js +13 -52
- package/dist/js/node/worker-server.js +41 -0
- package/dist/js/treeshaking/constants.js +28 -0
- package/dist/js/treeshaking/index.js +13 -0
- package/dist/js/treeshaking/libs/context/context.js +243 -0
- package/dist/js/treeshaking/libs/context/index.js +5 -0
- package/dist/js/treeshaking/libs/hook-api/index.js +157 -0
- package/dist/js/treeshaking/libs/hook-api/route.js +33 -0
- package/dist/js/treeshaking/libs/hook-api/template.js +91 -0
- package/dist/js/treeshaking/libs/loadConfig.js +39 -0
- package/dist/js/treeshaking/libs/metrics.js +12 -0
- package/dist/js/treeshaking/libs/proxy.js +80 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +124 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +464 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +53 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +35 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +121 -0
- package/dist/js/treeshaking/libs/render/cache/index.js +184 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +30 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +46 -0
- package/dist/js/treeshaking/libs/render/cache/spr.js +362 -0
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -0
- package/dist/js/treeshaking/libs/render/cache/util.js +101 -0
- package/dist/js/treeshaking/libs/render/index.js +100 -0
- package/dist/js/treeshaking/libs/render/measure.js +61 -0
- package/dist/js/treeshaking/libs/render/modern/browser-list.js +7 -0
- package/dist/js/treeshaking/libs/render/modern/index.js +39 -0
- package/dist/js/treeshaking/libs/render/reader.js +191 -0
- package/dist/js/treeshaking/libs/render/ssr.js +98 -0
- package/dist/js/treeshaking/libs/render/static.js +84 -0
- package/dist/js/treeshaking/libs/render/type.js +6 -0
- package/dist/js/treeshaking/libs/route/index.js +94 -0
- package/dist/js/treeshaking/libs/route/matcher.js +113 -0
- package/dist/js/treeshaking/libs/route/route.js +26 -0
- package/dist/js/treeshaking/libs/serve-file.js +75 -0
- package/dist/js/treeshaking/server/index.js +339 -0
- package/dist/js/treeshaking/server/modern-server-split.js +152 -0
- package/dist/js/treeshaking/server/modern-server.js +946 -0
- package/dist/js/treeshaking/type.js +1 -0
- package/dist/js/treeshaking/utils.js +90 -0
- package/dist/js/treeshaking/worker-server.js +56 -0
- package/dist/types/index.d.ts +0 -2
- package/dist/types/libs/context/context.d.ts +0 -3
- package/dist/types/libs/loadConfig.d.ts +0 -1
- package/dist/types/libs/render/cache/index.d.ts +0 -2
- package/dist/types/libs/render/cache/spr.d.ts +0 -2
- package/dist/types/server/index.d.ts +0 -3
- package/dist/types/utils.d.ts +2 -3
- package/dist/types/worker-server.d.ts +16 -0
- package/package.json +31 -15
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
import { Transform } from 'stream';
|
|
5
|
+
var RegList = {
|
|
6
|
+
before: {
|
|
7
|
+
head: '<head>',
|
|
8
|
+
body: '<body>'
|
|
9
|
+
},
|
|
10
|
+
after: {
|
|
11
|
+
head: '</head>',
|
|
12
|
+
body: '</body>'
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export var TemplateAPI = /*#__PURE__*/function () {
|
|
16
|
+
function TemplateAPI(content) {
|
|
17
|
+
_classCallCheck(this, TemplateAPI);
|
|
18
|
+
_defineProperty(this, "content", void 0);
|
|
19
|
+
this.content = content;
|
|
20
|
+
}
|
|
21
|
+
_createClass(TemplateAPI, [{
|
|
22
|
+
key: "get",
|
|
23
|
+
value: function get() {
|
|
24
|
+
return this.content;
|
|
25
|
+
}
|
|
26
|
+
}, {
|
|
27
|
+
key: "set",
|
|
28
|
+
value: function set(content) {
|
|
29
|
+
this.content = content;
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
32
|
+
key: "prependHead",
|
|
33
|
+
value: function prependHead(fragment) {
|
|
34
|
+
var head = RegList.before.head;
|
|
35
|
+
return this.replace(head, "".concat(head).concat(fragment));
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
key: "appendHead",
|
|
39
|
+
value: function appendHead(fragment) {
|
|
40
|
+
var head = RegList.after.head;
|
|
41
|
+
return this.replace(head, "".concat(fragment).concat(head));
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
key: "prependBody",
|
|
45
|
+
value: function prependBody(fragment) {
|
|
46
|
+
var body = RegList.before.body;
|
|
47
|
+
return this.replace(body, "".concat(body).concat(fragment));
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "appendBody",
|
|
51
|
+
value: function appendBody(fragment) {
|
|
52
|
+
var body = RegList.after.body;
|
|
53
|
+
return this.replace(body, "".concat(fragment).concat(body));
|
|
54
|
+
}
|
|
55
|
+
}, {
|
|
56
|
+
key: "replace",
|
|
57
|
+
value: function replace(reg, text) {
|
|
58
|
+
this.content = this.content.replace(reg, text);
|
|
59
|
+
}
|
|
60
|
+
}]);
|
|
61
|
+
return TemplateAPI;
|
|
62
|
+
}();
|
|
63
|
+
export var templateInjectableStream = function templateInjectableStream(_ref) {
|
|
64
|
+
var prependHead = _ref.prependHead,
|
|
65
|
+
appendHead = _ref.appendHead,
|
|
66
|
+
prependBody = _ref.prependBody,
|
|
67
|
+
appendBody = _ref.appendBody;
|
|
68
|
+
return new Transform({
|
|
69
|
+
write: function write(chunk, _, callback) {
|
|
70
|
+
var chunk_str = chunk.toString();
|
|
71
|
+
if (prependHead) {
|
|
72
|
+
var head = RegList.before.head;
|
|
73
|
+
chunk_str = chunk_str.replace(head, "".concat(head).concat(prependHead));
|
|
74
|
+
}
|
|
75
|
+
if (appendHead) {
|
|
76
|
+
var _head = RegList.after.head;
|
|
77
|
+
chunk_str = chunk_str.replace(_head, "".concat(appendHead).concat(_head));
|
|
78
|
+
}
|
|
79
|
+
if (prependBody) {
|
|
80
|
+
var body = RegList.before.body;
|
|
81
|
+
chunk_str = chunk_str.replace(body, "".concat(body).concat(prependBody));
|
|
82
|
+
}
|
|
83
|
+
if (appendBody) {
|
|
84
|
+
var _body = RegList.after.body;
|
|
85
|
+
chunk_str = chunk_str.replace(_body, "".concat(appendBody).concat(_body));
|
|
86
|
+
}
|
|
87
|
+
this.push(chunk_str);
|
|
88
|
+
callback();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { compatRequire, fs, DEFAULT_SERVER_CONFIG } from '@modern-js/utils';
|
|
4
|
+
import mergeDeep from 'merge-deep';
|
|
5
|
+
export var getServerConfigPath = function getServerConfigPath(distDirectory) {
|
|
6
|
+
var serverConfigFile = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_SERVER_CONFIG;
|
|
7
|
+
var serverConfigPath = path.join(distDirectory, serverConfigFile);
|
|
8
|
+
return "".concat(serverConfigPath, ".js");
|
|
9
|
+
};
|
|
10
|
+
export var requireConfig = function requireConfig(serverConfigPath) {
|
|
11
|
+
if (fs.pathExistsSync(serverConfigPath)) {
|
|
12
|
+
return compatRequire(serverConfigPath);
|
|
13
|
+
}
|
|
14
|
+
return {};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 对配置进行合并,开发环境下,cliConfig 与 serverConfig 进行深合并
|
|
19
|
+
* 生产环境下,resolvedConfig 与 serverConfig 进行深合并
|
|
20
|
+
* resolvedConfigPath: 构建序列化后的 modern.config.js 文件路径
|
|
21
|
+
*/
|
|
22
|
+
export var loadConfig = function loadConfig(_ref) {
|
|
23
|
+
var cliConfig = _ref.cliConfig,
|
|
24
|
+
serverConfig = _ref.serverConfig,
|
|
25
|
+
resolvedConfigPath = _ref.resolvedConfigPath;
|
|
26
|
+
var config = null;
|
|
27
|
+
if (process.env.NODE_ENV === 'production') {
|
|
28
|
+
var resolvedConfig = requireConfig(resolvedConfigPath);
|
|
29
|
+
// cli config has a higher priority,because it's an argument passed in.
|
|
30
|
+
config = mergeDeep(_objectSpread(_objectSpread({}, resolvedConfig), {}, {
|
|
31
|
+
plugins: [] // filter cli plugins
|
|
32
|
+
}), serverConfig, cliConfig);
|
|
33
|
+
} else {
|
|
34
|
+
config = mergeDeep(_objectSpread(_objectSpread({}, cliConfig), {}, {
|
|
35
|
+
plugins: []
|
|
36
|
+
}), serverConfig);
|
|
37
|
+
}
|
|
38
|
+
return config;
|
|
39
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
4
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
|
+
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
6
|
+
import { debug } from "../utils";
|
|
7
|
+
export function formatProxyOptions(proxyOptions) {
|
|
8
|
+
var formattedProxy = [];
|
|
9
|
+
if (!Array.isArray(proxyOptions)) {
|
|
10
|
+
if ('target' in proxyOptions) {
|
|
11
|
+
formattedProxy.push(proxyOptions);
|
|
12
|
+
} else {
|
|
13
|
+
Array.prototype.push.apply(formattedProxy, Object.keys(proxyOptions).reduce(function (total, source) {
|
|
14
|
+
var option = proxyOptions[source];
|
|
15
|
+
total.push(_objectSpread({
|
|
16
|
+
context: source,
|
|
17
|
+
changeOrigin: true,
|
|
18
|
+
logLevel: 'warn'
|
|
19
|
+
}, typeof option === 'string' ? {
|
|
20
|
+
target: option
|
|
21
|
+
} : option));
|
|
22
|
+
return total;
|
|
23
|
+
}, []));
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
formattedProxy.push.apply(formattedProxy, _toConsumableArray(proxyOptions));
|
|
27
|
+
}
|
|
28
|
+
return formattedProxy;
|
|
29
|
+
}
|
|
30
|
+
export var createProxyHandler = function createProxyHandler(proxyOptions) {
|
|
31
|
+
debug('createProxyHandler', proxyOptions);
|
|
32
|
+
if (!proxyOptions) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// If it is not an array, it may be an object that uses the context attribute
|
|
37
|
+
// or an object in the form of { source: ProxyDetail }
|
|
38
|
+
var formattedProxy = formatProxyOptions(proxyOptions);
|
|
39
|
+
var middlewares = formattedProxy.map(function (option) {
|
|
40
|
+
var middleware = createProxyMiddleware(option.context, option);
|
|
41
|
+
|
|
42
|
+
// eslint-disable-next-line consistent-return
|
|
43
|
+
return /*#__PURE__*/function () {
|
|
44
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(ctx, next) {
|
|
45
|
+
var req, res, bypassUrl;
|
|
46
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
47
|
+
while (1) {
|
|
48
|
+
switch (_context.prev = _context.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
req = ctx.req, res = ctx.res;
|
|
51
|
+
bypassUrl = typeof option.bypass === 'function' ? option.bypass(req, res, option) : null; // only false, no true
|
|
52
|
+
if (!(typeof bypassUrl === 'boolean')) {
|
|
53
|
+
_context.next = 7;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
ctx.status = 404;
|
|
57
|
+
return _context.abrupt("return", next());
|
|
58
|
+
case 7:
|
|
59
|
+
if (!(typeof bypassUrl === 'string')) {
|
|
60
|
+
_context.next = 10;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
ctx.url = bypassUrl;
|
|
64
|
+
return _context.abrupt("return", next());
|
|
65
|
+
case 10:
|
|
66
|
+
middleware(req, res, next);
|
|
67
|
+
case 11:
|
|
68
|
+
case "end":
|
|
69
|
+
return _context.stop();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, _callee);
|
|
73
|
+
}));
|
|
74
|
+
return function (_x, _x2) {
|
|
75
|
+
return _ref.apply(this, arguments);
|
|
76
|
+
};
|
|
77
|
+
}();
|
|
78
|
+
});
|
|
79
|
+
return middlewares;
|
|
80
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import url from 'url';
|
|
5
|
+
import { createCache, destroyCache } from "../spr";
|
|
6
|
+
import { cacheAddition, connectFactor, fname, maybeSync, namespaceHash, valueFactory, withCoalescedInvoke } from "../util";
|
|
7
|
+
describe('test spr util functions', function () {
|
|
8
|
+
it('should return value correctly', function () {
|
|
9
|
+
expect(connectFactor('bar', 'foo')).toBe('bar-foo');
|
|
10
|
+
expect(fname(1)).toBe('f1');
|
|
11
|
+
expect(namespaceHash('modern', '!@#$%^&')).toBe('modern/!@#$%^&');
|
|
12
|
+
});
|
|
13
|
+
it('should create or destroy instance correctly', function () {
|
|
14
|
+
var ins1 = createCache();
|
|
15
|
+
var ins2 = createCache();
|
|
16
|
+
expect(ins1 === ins2).toBe(true);
|
|
17
|
+
destroyCache();
|
|
18
|
+
var ins3 = createCache();
|
|
19
|
+
expect(ins1 === ins3).toBe(false);
|
|
20
|
+
expect(ins2 === ins3).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
it('should return function correctly', function () {
|
|
23
|
+
var urlParams = function () {
|
|
24
|
+
return new url.URLSearchParams();
|
|
25
|
+
}();
|
|
26
|
+
urlParams.set('name', 'modern');
|
|
27
|
+
var getParam = valueFactory(urlParams);
|
|
28
|
+
expect(getParam('name')).toBe('modern');
|
|
29
|
+
var headers = {
|
|
30
|
+
age: '12345'
|
|
31
|
+
};
|
|
32
|
+
var getHeader = valueFactory(headers);
|
|
33
|
+
expect(getHeader('age')).toBe('12345');
|
|
34
|
+
});
|
|
35
|
+
it('should add target html content', function () {
|
|
36
|
+
var contentNoHead = '<div>123</div>';
|
|
37
|
+
var html = cacheAddition(contentNoHead, Math.random().toString());
|
|
38
|
+
expect(html).toBe(contentNoHead);
|
|
39
|
+
var contentWithHead = '<head></head><div>123</div>';
|
|
40
|
+
var hash = Math.random().toString();
|
|
41
|
+
var htmlWithHead = cacheAddition(contentWithHead, hash);
|
|
42
|
+
expect(htmlWithHead).toBe("<head><meta name=\"x-moden-spr\" content=\"".concat(hash, "\"></head><div>123</div>"));
|
|
43
|
+
});
|
|
44
|
+
it('should only invoke func one time', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
45
|
+
var index, fn, key, _yield$Promise$all, _yield$Promise$all2, res1, res2;
|
|
46
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
47
|
+
while (1) {
|
|
48
|
+
switch (_context2.prev = _context2.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
index = 0;
|
|
51
|
+
fn = withCoalescedInvoke( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
52
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
53
|
+
while (1) {
|
|
54
|
+
switch (_context.prev = _context.next) {
|
|
55
|
+
case 0:
|
|
56
|
+
return _context.abrupt("return", new Promise(function (resolve) {
|
|
57
|
+
setTimeout(function () {
|
|
58
|
+
index += 1;
|
|
59
|
+
resolve(index);
|
|
60
|
+
}, 500);
|
|
61
|
+
}));
|
|
62
|
+
case 1:
|
|
63
|
+
case "end":
|
|
64
|
+
return _context.stop();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, _callee);
|
|
68
|
+
})));
|
|
69
|
+
key = 'test';
|
|
70
|
+
_context2.next = 5;
|
|
71
|
+
return Promise.all([fn(key, []), fn(key, [])]);
|
|
72
|
+
case 5:
|
|
73
|
+
_yield$Promise$all = _context2.sent;
|
|
74
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
75
|
+
res1 = _yield$Promise$all2[0];
|
|
76
|
+
res2 = _yield$Promise$all2[1];
|
|
77
|
+
expect(res1.isOrigin && res2.isOrigin).toBe(false);
|
|
78
|
+
expect(res1.isOrigin || res2.isOrigin).toBe(true);
|
|
79
|
+
expect(res1.value).toBe(1);
|
|
80
|
+
expect(res2.value).toBe(1);
|
|
81
|
+
case 13:
|
|
82
|
+
case "end":
|
|
83
|
+
return _context2.stop();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}, _callee2);
|
|
87
|
+
})));
|
|
88
|
+
it('should invoke sync or async', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
89
|
+
var foo, async, sync;
|
|
90
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
91
|
+
while (1) {
|
|
92
|
+
switch (_context3.prev = _context3.next) {
|
|
93
|
+
case 0:
|
|
94
|
+
foo = '';
|
|
95
|
+
_context3.next = 3;
|
|
96
|
+
return maybeSync(function () {
|
|
97
|
+
return new Promise(function (resolve) {
|
|
98
|
+
setTimeout(function () {
|
|
99
|
+
resolve(foo);
|
|
100
|
+
}, 100);
|
|
101
|
+
});
|
|
102
|
+
})(false);
|
|
103
|
+
case 3:
|
|
104
|
+
async = _context3.sent;
|
|
105
|
+
expect(async).toBeUndefined();
|
|
106
|
+
_context3.next = 7;
|
|
107
|
+
return maybeSync(function () {
|
|
108
|
+
return new Promise(function (resolve) {
|
|
109
|
+
setTimeout(function () {
|
|
110
|
+
resolve(foo);
|
|
111
|
+
}, 100);
|
|
112
|
+
});
|
|
113
|
+
})(true);
|
|
114
|
+
case 7:
|
|
115
|
+
sync = _context3.sent;
|
|
116
|
+
expect(sync).toBe(foo);
|
|
117
|
+
case 9:
|
|
118
|
+
case "end":
|
|
119
|
+
return _context3.stop();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}, _callee3);
|
|
123
|
+
})));
|
|
124
|
+
});
|