@dr.pogodin/react-utils 1.21.1 → 1.21.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/build/development/client/index.js +0 -7
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +3 -17
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +0 -13
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +2 -9
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +7 -32
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +24 -80
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +21 -61
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +2 -9
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/index.js +0 -4
- package/build/development/shared/components/Button/index.js +2 -13
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +2 -9
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/CodeSplit/index.js +11 -22
- package/build/development/shared/components/CodeSplit/index.js.map +1 -1
- package/build/development/shared/components/Dropdown/index.js +0 -11
- package/build/development/shared/components/Dropdown/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +3 -9
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +0 -7
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +3 -6
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/MetaTags.js +1 -8
- package/build/development/shared/components/MetaTags.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +2 -19
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +2 -6
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +0 -7
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/ScalableRect/index.js +1 -6
- package/build/development/shared/components/ScalableRect/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +0 -9
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +9 -28
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +0 -16
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +3 -11
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +0 -17
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/utils/Barrier.js +1 -13
- package/build/development/shared/utils/Barrier.js.map +1 -1
- package/build/development/shared/utils/Emitter.js +4 -13
- package/build/development/shared/utils/Emitter.js.map +1 -1
- package/build/development/shared/utils/Semaphore.js +13 -19
- package/build/development/shared/utils/Semaphore.js.map +1 -1
- package/build/development/shared/utils/config.js +0 -5
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/index.js +5 -26
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy.js +6 -12
- package/build/development/shared/utils/isomorphy.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +20 -41
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +10 -31
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +2 -5
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +6 -15
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +1 -5
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/development/style.css +5 -24
- package/build/development/web.bundle.js +27 -27
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/CodeSplit/index.js.map +1 -1
- package/build/production/shared/components/Dropdown/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/MetaTags.js.map +1 -1
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/ScalableRect/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/utils/Barrier.js.map +1 -1
- package/build/production/shared/utils/Emitter.js.map +1 -1
- package/build/production/shared/utils/Semaphore.js.map +1 -1
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/production/style.css +1 -1
- package/build/production/style.css.map +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/config/babel/node-ssr.js +1 -1
- package/package.json +24 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isomorphy.js","names":["IS_CLIENT_SIDE","process","versions","node","global","REACT_UTILS_FORCE_CLIENT_SIDE","IS_SERVER_SIDE","getMode","env","NODE_ENV","isDevBuild","isProdBuild","getBuildInfo","window","TRU_BUILD_INFO","buildTimestamp","timestamp"],"sources":["../../../../src/shared/utils/isomorphy.js"],"sourcesContent":["/* global window */\n\n/**\n * `true` within client-side environment (browser), `false` at server-side.\n */\nexport const IS_CLIENT_SIDE = typeof process !== 'object'\n || !process.versions || !process.versions.node\n || !!global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n/**\n * `true` within the server-side environment (node), `false` at client-side.\n */\nexport const IS_SERVER_SIDE = !IS_CLIENT_SIDE;\n\n/**\n * @ignore\n * @return {string} Code mode: \"development\" or \"production\".\n */\nfunction getMode() {\n return process.env.NODE_ENV;\n}\n\n/**\n * Returns `true` if development version of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isDevBuild() {\n return getMode() === 'development';\n}\n\n/**\n * Returns `true` if production build of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isProdBuild() {\n return getMode() === 'production';\n}\n\n/**\n * Returns build info object.\n * @returns {object}\n */\nexport function getBuildInfo() {\n return (IS_CLIENT_SIDE ? window : global).TRU_BUILD_INFO;\n}\n\n/**\n * Returns build timestamp of the front-end JS bundle.\n * @return {string} ISO date/time string.\n */\nexport function buildTimestamp() {\n return getBuildInfo().timestamp;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"isomorphy.js","names":["IS_CLIENT_SIDE","process","versions","node","global","REACT_UTILS_FORCE_CLIENT_SIDE","IS_SERVER_SIDE","getMode","env","NODE_ENV","isDevBuild","isProdBuild","getBuildInfo","window","TRU_BUILD_INFO","buildTimestamp","timestamp"],"sources":["../../../../src/shared/utils/isomorphy.js"],"sourcesContent":["/* global window */\n\n/**\n * `true` within client-side environment (browser), `false` at server-side.\n */\nexport const IS_CLIENT_SIDE = typeof process !== 'object'\n || !process.versions || !process.versions.node\n || !!global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n/**\n * `true` within the server-side environment (node), `false` at client-side.\n */\nexport const IS_SERVER_SIDE = !IS_CLIENT_SIDE;\n\n/**\n * @ignore\n * @return {string} Code mode: \"development\" or \"production\".\n */\nfunction getMode() {\n return process.env.NODE_ENV;\n}\n\n/**\n * Returns `true` if development version of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isDevBuild() {\n return getMode() === 'development';\n}\n\n/**\n * Returns `true` if production build of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isProdBuild() {\n return getMode() === 'production';\n}\n\n/**\n * Returns build info object.\n * @returns {object}\n */\nexport function getBuildInfo() {\n return (IS_CLIENT_SIDE ? window : global).TRU_BUILD_INFO;\n}\n\n/**\n * Returns build timestamp of the front-end JS bundle.\n * @return {string} ISO date/time string.\n */\nexport function buildTimestamp() {\n return getBuildInfo().timestamp;\n}\n"],"mappings":";;;;;;;;;;AAAA;;AAEA;AACA;AACA;AACO,MAAMA,cAAc,GAAG,OAAOC,OAAO,KAAK,QAAQ,IACpD,CAACA,OAAO,CAACC,QAAQ,IAAI,CAACD,OAAO,CAACC,QAAQ,CAACC,IAAI,IAC3C,CAAC,CAACC,MAAM,CAACC,6BAA6B;;AAE3C;AACA;AACA;AAFA;AAGO,MAAMC,cAAc,GAAG,CAACN,cAAc;;AAE7C;AACA;AACA;AACA;AAHA;AAIA,SAASO,OAAO,GAAG;EACjB,OAAON,OAAO,CAACO,GAAG,CAACC,QAAQ;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAU,GAAG;EAC3B,OAAOH,OAAO,EAAE,KAAK,aAAa;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASI,WAAW,GAAG;EAC5B,OAAOJ,OAAO,EAAE,KAAK,YAAY;AACnC;;AAEA;AACA;AACA;AACA;AACO,SAASK,YAAY,GAAG;EAC7B,OAAO,CAACZ,cAAc,GAAGa,MAAM,GAAGT,MAAM,EAAEU,cAAc;AAC1D;;AAEA;AACA;AACA;AACA;AACO,SAASC,cAAc,GAAG;EAC/B,OAAOH,YAAY,EAAE,CAACI,SAAS;AACjC"}
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
9
|
var _renderer = _interopRequireDefault(require("../../../server/renderer"));
|
|
13
|
-
|
|
14
10
|
var _lodash = require("lodash");
|
|
15
|
-
|
|
16
11
|
var _register = _interopRequireDefault(require("@babel/register"));
|
|
17
|
-
|
|
18
12
|
var _jestEnvironmentJsdom = _interopRequireDefault(require("jest-environment-jsdom"));
|
|
19
|
-
|
|
20
13
|
var _memfs = require("memfs");
|
|
21
|
-
|
|
22
14
|
var _webpack = _interopRequireDefault(require("webpack"));
|
|
23
|
-
|
|
24
15
|
/**
|
|
25
16
|
* Jest environment for end-to-end SSR and client-side testing. It relies on
|
|
26
17
|
* the standard react-utils mechanics to execute SSR of given scene, and also
|
|
27
18
|
* Webpack build of the code for client-side execution, it further exposes
|
|
28
19
|
* Jsdom environment for the client-side testing of the outcomes.
|
|
29
20
|
*/
|
|
30
|
-
|
|
31
21
|
/* eslint-disable global-require, import/no-dynamic-require */
|
|
22
|
+
|
|
32
23
|
// BEWARE: The module is not imported into the JU module / the main assembly of
|
|
33
24
|
// the library, because doing so easily breaks stuff:
|
|
34
25
|
// 1) This module depends on Node-specific modules, which would make JU
|
|
@@ -37,12 +28,13 @@ var _webpack = _interopRequireDefault(require("webpack"));
|
|
|
37
28
|
// it seems to randomly break tests using it for a different reason,
|
|
38
29
|
// probably some sort of a require-loop, or some issues with weak
|
|
39
30
|
// require in that scenario.
|
|
31
|
+
|
|
40
32
|
// As this environment is a part of the Jest testing utils,
|
|
41
33
|
// we assume development dependencies are available when it is used.
|
|
42
|
-
|
|
43
34
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
44
35
|
|
|
45
36
|
/* eslint-enable import/no-extraneous-dependencies */
|
|
37
|
+
|
|
46
38
|
class E2eSsrEnv extends _jestEnvironmentJsdom.default {
|
|
47
39
|
/**
|
|
48
40
|
* Loads Webpack config, and exposes it to the environment via global
|
|
@@ -60,18 +52,16 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
|
|
|
60
52
|
this.global.webpackConfig = factory(options);
|
|
61
53
|
const fs = this.global.webpackOutputFs;
|
|
62
54
|
let buildInfo = `${options.context}/.build-info`;
|
|
63
|
-
|
|
64
55
|
if (fs.existsSync(buildInfo)) {
|
|
65
56
|
buildInfo = fs.readFileSync(buildInfo, 'utf8');
|
|
66
57
|
this.global.buildInfo = JSON.parse(buildInfo);
|
|
67
58
|
}
|
|
68
59
|
}
|
|
60
|
+
|
|
69
61
|
/**
|
|
70
62
|
* Executes Webpack build.
|
|
71
63
|
* @return {Promise}
|
|
72
64
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
65
|
async runWebpack() {
|
|
76
66
|
this.loadWebpackConfig();
|
|
77
67
|
const compiler = (0, _webpack.default)(this.global.webpackConfig);
|
|
@@ -79,26 +69,25 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
|
|
|
79
69
|
return new Promise((done, fail) => {
|
|
80
70
|
compiler.run((err, stats) => {
|
|
81
71
|
if (err) fail(err);
|
|
82
|
-
|
|
83
72
|
if (stats.hasErrors()) {
|
|
84
73
|
console.error(stats.toJson().errors);
|
|
85
74
|
fail(Error('Webpack compilation failed'));
|
|
86
75
|
}
|
|
76
|
+
this.global.webpackStats = stats.toJson();
|
|
87
77
|
|
|
88
|
-
|
|
78
|
+
// Keeps reference to the raw Webpack stats object, which should be
|
|
89
79
|
// explicitly passed to the server-side renderer alongside the request,
|
|
90
80
|
// so that it can to pick up asset paths for different named chunks.
|
|
91
|
-
|
|
92
81
|
this.webpackStats = stats;
|
|
93
82
|
done();
|
|
94
83
|
});
|
|
95
84
|
});
|
|
96
85
|
}
|
|
97
|
-
|
|
98
86
|
async runSsr() {
|
|
99
87
|
let options = this.pragmas['ssr-options'];
|
|
100
|
-
options = options ? JSON.parse(options) : {};
|
|
88
|
+
options = options ? JSON.parse(options) : {};
|
|
101
89
|
|
|
90
|
+
// TODO: This is temporary to shortcut the logging added to SSR.
|
|
102
91
|
if (options.logger === undefined) {
|
|
103
92
|
options.logger = {
|
|
104
93
|
debug: _lodash.noop,
|
|
@@ -107,39 +96,33 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
|
|
|
107
96
|
warn: _lodash.noop
|
|
108
97
|
};
|
|
109
98
|
}
|
|
110
|
-
|
|
111
99
|
let root;
|
|
112
|
-
|
|
113
100
|
switch (options.root) {
|
|
114
101
|
case 'TEST':
|
|
115
102
|
root = this.testFolder;
|
|
116
103
|
break;
|
|
117
|
-
|
|
118
104
|
default:
|
|
119
105
|
root = process.cwd();
|
|
120
|
-
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Note: This enables Babel transformation for the code dynamically loaded
|
|
121
109
|
// below, as the usual Jest Babel setup does not seem to apply to
|
|
122
110
|
// the environment code, and imports from it.
|
|
123
|
-
|
|
124
|
-
|
|
125
111
|
(0, _register.default)({
|
|
126
112
|
envName: options.babelEnv,
|
|
127
113
|
extensions: ['.js', '.jsx', '.svg'],
|
|
128
114
|
root
|
|
129
115
|
});
|
|
130
116
|
if (!options.buildInfo) options.buildInfo = this.global.buildInfo;
|
|
131
|
-
|
|
132
117
|
if (options.entry) {
|
|
133
118
|
const p = _path.default.resolve(this.testFolder, options.entry);
|
|
134
|
-
|
|
135
119
|
options.Application = require(p)[options.entryExportName || 'default'];
|
|
136
120
|
}
|
|
137
|
-
|
|
138
121
|
const renderer = (0, _renderer.default)(this.global.webpackConfig, options);
|
|
139
122
|
let status = 200; // OK
|
|
140
|
-
|
|
141
123
|
const markup = await new Promise((done, fail) => {
|
|
142
|
-
renderer(this.ssrRequest,
|
|
124
|
+
renderer(this.ssrRequest,
|
|
125
|
+
// TODO: This will do for now, with the current implementation of
|
|
143
126
|
// the renderer, but it will require a rework once the renderer is
|
|
144
127
|
// updated to do streaming.
|
|
145
128
|
{
|
|
@@ -167,19 +150,20 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
|
|
|
167
150
|
this.global.ssrOptions = options;
|
|
168
151
|
this.global.ssrStatus = status;
|
|
169
152
|
}
|
|
170
|
-
|
|
171
153
|
constructor(config, context) {
|
|
172
154
|
const pragmas = context.docblockPragmas;
|
|
173
155
|
let request = pragmas['ssr-request'];
|
|
174
156
|
request = request ? JSON.parse(request) : {};
|
|
175
157
|
if (!request.url) request.url = '/';
|
|
176
|
-
request.csrfToken = _lodash.noop;
|
|
158
|
+
request.csrfToken = _lodash.noop;
|
|
177
159
|
|
|
160
|
+
// This ensures the initial JsDom URL matches the value we use for SSR.
|
|
178
161
|
(0, _lodash.set)(config.projectConfig, 'testEnvironmentOptions.url', `http://localhost${request.url}`);
|
|
179
162
|
super(config, context);
|
|
180
163
|
this.global.dom = this.dom;
|
|
181
|
-
this.global.webpackOutputFs = (0, _memfs.createFsFromVolume)(new _memfs.Volume());
|
|
164
|
+
this.global.webpackOutputFs = (0, _memfs.createFsFromVolume)(new _memfs.Volume());
|
|
182
165
|
|
|
166
|
+
// Extracts necessary settings from config and context.
|
|
183
167
|
const {
|
|
184
168
|
projectConfig
|
|
185
169
|
} = config;
|
|
@@ -189,32 +173,27 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
|
|
|
189
173
|
this.ssrRequest = request;
|
|
190
174
|
this.pragmas = pragmas;
|
|
191
175
|
}
|
|
192
|
-
|
|
193
176
|
async setup() {
|
|
194
177
|
await super.setup();
|
|
195
178
|
await this.runWebpack();
|
|
196
179
|
if (this.withSsr) await this.runSsr();
|
|
197
180
|
this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;
|
|
198
181
|
}
|
|
199
|
-
|
|
200
182
|
async teardown() {
|
|
201
|
-
delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;
|
|
183
|
+
delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;
|
|
184
|
+
|
|
185
|
+
// Resets module cache and @babel/register. Effectively this ensures that
|
|
202
186
|
// the next time an instance of this environment is set up, all modules are
|
|
203
187
|
// transformed by Babel from scratch, thus taking into account the latest
|
|
204
188
|
// Babel config (which may change between different environment instances,
|
|
205
189
|
// which does not seem to be taken into account by Babel / Node caches
|
|
206
190
|
// automatically).
|
|
207
|
-
|
|
208
191
|
Object.keys(require.cache).forEach(key => {
|
|
209
192
|
delete require.cache[key];
|
|
210
193
|
});
|
|
211
|
-
|
|
212
194
|
_register.default.revert();
|
|
213
|
-
|
|
214
195
|
super.teardown();
|
|
215
196
|
}
|
|
216
|
-
|
|
217
197
|
}
|
|
218
|
-
|
|
219
198
|
exports.default = E2eSsrEnv;
|
|
220
199
|
//# sourceMappingURL=E2eSsrEnv.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"E2eSsrEnv.js","names":["E2eSsrEnv","JsdomEnv","loadWebpackConfig","options","pragmas","JSON","parse","defaults","context","testFolder","fs","global","webpackOutputFs","factory","require","path","resolve","rootDir","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","compiler","webpack","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","Error","webpackStats","runSsr","logger","undefined","debug","noop","info","log","warn","root","process","cwd","register","envName","babelEnv","extensions","entry","p","Application","entryExportName","renderer","ssrFactory","status","markup","ssrRequest","cookie","send","set","value","locals","devMiddleware","ssrMarkup","ssrOptions","ssrStatus","constructor","config","docblockPragmas","request","url","csrfToken","projectConfig","dom","createFsFromVolume","Volume","dirname","testPath","withSsr","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","revert"],"sources":["../../../../../src/shared/utils/jest/E2eSsrEnv.js"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n/* eslint-disable global-require, import/no-dynamic-require */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\nimport path from 'path';\nimport ssrFactory from 'server/renderer';\n\nimport { defaults, noop, set } from 'lodash';\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\nimport register from '@babel/register';\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { createFsFromVolume, Volume } from 'memfs';\nimport webpack from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\nexport default class E2eSsrEnv extends JsdomEnv {\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n loadWebpackConfig() {\n let options = this.pragmas['webpack-config-options'];\n options = options ? JSON.parse(options) : {};\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n let factory = this.pragmas['webpack-config-factory'] || '';\n factory = require(path.resolve(this.rootDir, factory));\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8');\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack() {\n this.loadWebpackConfig();\n\n const compiler = webpack(this.global.webpackConfig);\n compiler.outputFileSystem = this.global.webpackOutputFs;\n return new Promise((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats.hasErrors()) {\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr() {\n let options = this.pragmas['ssr-options'];\n options = options ? JSON.parse(options) : {};\n\n // TODO: This is temporary to shortcut the logging added to SSR.\n if (options.logger === undefined) {\n options.logger = {\n debug: noop,\n info: noop,\n log: noop,\n warn: noop,\n };\n }\n\n let root;\n switch (options.root) {\n case 'TEST': root = this.testFolder; break;\n default: root = process.cwd();\n }\n\n // Note: This enables Babel transformation for the code dynamically loaded\n // below, as the usual Jest Babel setup does not seem to apply to\n // the environment code, and imports from it.\n register({\n envName: options.babelEnv,\n extensions: ['.js', '.jsx', '.svg'],\n root,\n });\n\n if (!options.buildInfo) options.buildInfo = this.global.buildInfo;\n\n if (options.entry) {\n const p = path.resolve(this.testFolder, options.entry);\n options.Application = require(p)[options.entryExportName || 'default'];\n }\n\n const renderer = ssrFactory(this.global.webpackConfig, options);\n let status = 200; // OK\n const markup = await new Promise((done, fail) => {\n renderer(\n this.ssrRequest,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n {\n cookie: noop,\n send: done,\n set: noop,\n status: (value) => {\n status = value;\n },\n\n // This is how up-to-date Webpack stats are passed to the server in\n // development mode, and we use this here always, instead of having\n // to pass some information via filesystem.\n locals: {\n webpack: {\n devMiddleware: {\n stats: this.webpackStats,\n },\n },\n },\n },\n\n (error) => {\n if (error) fail(error);\n else done('');\n },\n );\n });\n\n this.global.ssrMarkup = markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = status;\n }\n\n constructor(config, context) {\n const pragmas = context.docblockPragmas;\n let request = pragmas['ssr-request'];\n request = request ? JSON.parse(request) : {};\n if (!request.url) request.url = '/';\n request.csrfToken = noop;\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n }\n\n async setup() {\n await super.setup();\n await this.runWebpack();\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown() {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n // Resets module cache and @babel/register. Effectively this ensures that\n // the next time an instance of this environment is set up, all modules are\n // transformed by Babel from scratch, thus taking into account the latest\n // Babel config (which may change between different environment instances,\n // which does not seem to be taken into account by Babel / Node caches\n // automatically).\n Object.keys(require.cache).forEach((key) => {\n delete require.cache[key];\n });\n register.revert();\n super.teardown();\n }\n}\n"],"mappings":";;;;;;;;;AAiBA;;AACA;;AAEA;;AAKA;;AACA;;AACA;;AACA;;AA5BA;AACA;AACA;AACA;AACA;AACA;;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA;AACA;;AACA;;AAKA;AAEe,MAAMA,SAAN,SAAwBC,6BAAxB,CAAiC;EAC9C;AACF;AACA;AACA;EACEC,iBAAiB,GAAG;IAClB,IAAIC,OAAO,GAAG,KAAKC,OAAL,CAAa,wBAAb,CAAd;IACAD,OAAO,GAAGA,OAAO,GAAGE,IAAI,CAACC,KAAL,CAAWH,OAAX,CAAH,GAAyB,EAA1C;IACA,IAAAI,gBAAA,EAASJ,OAAT,EAAkB;MAChBK,OAAO,EAAE,KAAKC,UADE;MAEhBC,EAAE,EAAE,KAAKC,MAAL,CAAYC;IAFA,CA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,4BAFF,EAGG,mBAAkBH,OAAO,CAACC,GAAI,EAHjC;IAMA,MAAMH,MAAN,EAAcjE,OAAd;IAEA,KAAKG,MAAL,CAAYoE,GAAZ,GAAkB,KAAKA,GAAvB;IACA,KAAKpE,MAAL,CAAYC,eAAZ,GAA8B,IAAAoE,yBAAA,EAAmB,IAAIC,aAAJ,EAAnB,CAA9B,CAjB2B,CAmB3B;;IACA,MAAM;MAAEH;IAAF,IAAoBL,MAA1B;IACA,KAAKxD,OAAL,GAAe6D,aAAa,CAAC7D,OAA7B;IACA,KAAKR,UAAL,GAAkBM,aAAA,CAAKmE,OAAL,CAAa1E,OAAO,CAAC2E,QAArB,CAAlB;IACA,KAAKC,OAAL,GAAe,CAAChF,OAAO,CAAC,QAAD,CAAvB;IACA,KAAK0D,UAAL,GAAkBa,OAAlB;IACA,KAAKvE,OAAL,GAAeA,OAAf;EACD;;EAEU,MAALiF,KAAK,GAAG;IACZ,MAAM,MAAMA,KAAN,EAAN;IACA,MAAM,KAAK/D,UAAL,EAAN;IACA,IAAI,KAAK8D,OAAT,EAAkB,MAAM,KAAK7C,MAAL,EAAN;IAClB,KAAK5B,MAAL,CAAY2E,6BAAZ,GAA4C,IAA5C;EACD;;EAEa,MAARC,QAAQ,GAAG;IACf,OAAO,KAAK5E,MAAL,CAAY2E,6BAAnB,CADe,CAGf;IACA;IACA;IACA;IACA;IACA;;IACAE,MAAM,CAACC,IAAP,CAAY3E,OAAO,CAAC4E,KAApB,EAA2BC,OAA3B,CAAoCC,GAAD,IAAS;MAC1C,OAAO9E,OAAO,CAAC4E,KAAR,CAAcE,GAAd,CAAP;IACD,CAFD;;IAGA1C,iBAAA,CAAS2C,MAAT;;IACA,MAAMN,QAAN;EACD;;AApL6C"}
|
|
1
|
+
{"version":3,"file":"E2eSsrEnv.js","names":["E2eSsrEnv","JsdomEnv","loadWebpackConfig","options","pragmas","JSON","parse","defaults","context","testFolder","fs","global","webpackOutputFs","factory","require","path","resolve","rootDir","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","compiler","webpack","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","Error","webpackStats","runSsr","logger","undefined","debug","noop","info","log","warn","root","process","cwd","register","envName","babelEnv","extensions","entry","p","Application","entryExportName","renderer","ssrFactory","status","markup","ssrRequest","cookie","send","set","value","locals","devMiddleware","ssrMarkup","ssrOptions","ssrStatus","constructor","config","docblockPragmas","request","url","csrfToken","projectConfig","dom","createFsFromVolume","Volume","dirname","testPath","withSsr","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","revert"],"sources":["../../../../../src/shared/utils/jest/E2eSsrEnv.js"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n/* eslint-disable global-require, import/no-dynamic-require */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\nimport path from 'path';\nimport ssrFactory from 'server/renderer';\n\nimport { defaults, noop, set } from 'lodash';\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\nimport register from '@babel/register';\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { createFsFromVolume, Volume } from 'memfs';\nimport webpack from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\nexport default class E2eSsrEnv extends JsdomEnv {\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n loadWebpackConfig() {\n let options = this.pragmas['webpack-config-options'];\n options = options ? JSON.parse(options) : {};\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n let factory = this.pragmas['webpack-config-factory'] || '';\n factory = require(path.resolve(this.rootDir, factory));\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8');\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack() {\n this.loadWebpackConfig();\n\n const compiler = webpack(this.global.webpackConfig);\n compiler.outputFileSystem = this.global.webpackOutputFs;\n return new Promise((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats.hasErrors()) {\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr() {\n let options = this.pragmas['ssr-options'];\n options = options ? JSON.parse(options) : {};\n\n // TODO: This is temporary to shortcut the logging added to SSR.\n if (options.logger === undefined) {\n options.logger = {\n debug: noop,\n info: noop,\n log: noop,\n warn: noop,\n };\n }\n\n let root;\n switch (options.root) {\n case 'TEST': root = this.testFolder; break;\n default: root = process.cwd();\n }\n\n // Note: This enables Babel transformation for the code dynamically loaded\n // below, as the usual Jest Babel setup does not seem to apply to\n // the environment code, and imports from it.\n register({\n envName: options.babelEnv,\n extensions: ['.js', '.jsx', '.svg'],\n root,\n });\n\n if (!options.buildInfo) options.buildInfo = this.global.buildInfo;\n\n if (options.entry) {\n const p = path.resolve(this.testFolder, options.entry);\n options.Application = require(p)[options.entryExportName || 'default'];\n }\n\n const renderer = ssrFactory(this.global.webpackConfig, options);\n let status = 200; // OK\n const markup = await new Promise((done, fail) => {\n renderer(\n this.ssrRequest,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n {\n cookie: noop,\n send: done,\n set: noop,\n status: (value) => {\n status = value;\n },\n\n // This is how up-to-date Webpack stats are passed to the server in\n // development mode, and we use this here always, instead of having\n // to pass some information via filesystem.\n locals: {\n webpack: {\n devMiddleware: {\n stats: this.webpackStats,\n },\n },\n },\n },\n\n (error) => {\n if (error) fail(error);\n else done('');\n },\n );\n });\n\n this.global.ssrMarkup = markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = status;\n }\n\n constructor(config, context) {\n const pragmas = context.docblockPragmas;\n let request = pragmas['ssr-request'];\n request = request ? JSON.parse(request) : {};\n if (!request.url) request.url = '/';\n request.csrfToken = noop;\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n }\n\n async setup() {\n await super.setup();\n await this.runWebpack();\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown() {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n // Resets module cache and @babel/register. Effectively this ensures that\n // the next time an instance of this environment is set up, all modules are\n // transformed by Babel from scratch, thus taking into account the latest\n // Babel config (which may change between different environment instances,\n // which does not seem to be taken into account by Babel / Node caches\n // automatically).\n Object.keys(require.cache).forEach((key) => {\n delete require.cache[key];\n });\n register.revert();\n super.teardown();\n }\n}\n"],"mappings":";;;;;;;AAiBA;AACA;AAEA;AAKA;AACA;AACA;AACA;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA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6B,GAAG,IAAI;EAClD;EAEA,MAAMC,QAAQ,GAAG;IACf,OAAO,IAAI,CAAC5E,MAAM,CAAC2E,6BAA6B;;IAEhD;IACA;IACA;IACA;IACA;IACA;IACAE,MAAM,CAACC,IAAI,CAAC3E,OAAO,CAAC4E,KAAK,CAAC,CAACC,OAAO,CAAEC,GAAG,IAAK;MAC1C,OAAO9E,OAAO,CAAC4E,KAAK,CAACE,GAAG,CAAC;IAC3B,CAAC,CAAC;IACF1C,iBAAQ,CAAC2C,MAAM,EAAE;IACjB,KAAK,CAACN,QAAQ,EAAE;EAClB;AACF;AAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -21,23 +20,14 @@ exports.shallowSnapshot = shallowSnapshot;
|
|
|
21
20
|
exports.simulate = void 0;
|
|
22
21
|
exports.snapshot = snapshot;
|
|
23
22
|
exports.unmockClientSide = unmockClientSide;
|
|
24
|
-
|
|
25
23
|
var _mockdate = _interopRequireDefault(require("mockdate"));
|
|
26
|
-
|
|
27
24
|
var _client = require("react-dom/client");
|
|
28
|
-
|
|
29
25
|
var _testUtils = _interopRequireWildcard(require("react-dom/test-utils"));
|
|
30
|
-
|
|
31
26
|
var _reactTestRenderer = _interopRequireDefault(require("react-test-renderer"));
|
|
32
|
-
|
|
33
27
|
var _shallow = _interopRequireDefault(require("react-test-renderer/shallow"));
|
|
34
|
-
|
|
35
28
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
36
|
-
|
|
37
29
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
38
|
-
|
|
39
30
|
/* global expect, jest, document */
|
|
40
|
-
|
|
41
31
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
42
32
|
|
|
43
33
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
@@ -49,78 +39,73 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
49
39
|
* from `react-dom/test-utils`.
|
|
50
40
|
* @param {function} action
|
|
51
41
|
*/
|
|
42
|
+
|
|
52
43
|
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
53
44
|
const originalProcessVersions = process.versions;
|
|
45
|
+
|
|
54
46
|
/**
|
|
55
47
|
* Tricks **react-utils** into thinking the test is running within client-side
|
|
56
48
|
* (browser) environment.
|
|
57
49
|
*/
|
|
58
|
-
|
|
59
50
|
function mockClientSide() {
|
|
60
51
|
Object.defineProperty(process, 'versions', {
|
|
61
52
|
value: null
|
|
62
53
|
});
|
|
63
54
|
}
|
|
55
|
+
|
|
64
56
|
/**
|
|
65
57
|
* Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.
|
|
66
58
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
59
|
function unmockClientSide() {
|
|
70
60
|
Object.defineProperty(process, 'versions', {
|
|
71
61
|
value: originalProcessVersions,
|
|
72
62
|
writable: false
|
|
73
63
|
});
|
|
74
64
|
}
|
|
65
|
+
|
|
75
66
|
/**
|
|
76
67
|
* Generates a mock UUID, or better said it determenistically transforms given
|
|
77
68
|
* `seed` number into a UUID-formatted string.
|
|
78
69
|
* @param {number} seed
|
|
79
70
|
* @return {string}
|
|
80
71
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
72
|
function getMockUuid(seed = 0) {
|
|
84
73
|
const x = seed.toString(16).padStart(32, '0');
|
|
85
74
|
return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;
|
|
86
75
|
}
|
|
76
|
+
|
|
87
77
|
/**
|
|
88
78
|
* Advances mock timers, and mock date by the specified time.
|
|
89
79
|
* @param {number} time Time step [ms].
|
|
90
80
|
* @returns {Promise} Wait for this to "jump after" any async code which should
|
|
91
81
|
* be executed because of the mock time movement.
|
|
92
82
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
83
|
async function mockTimer(time) {
|
|
96
84
|
_mockdate.default.set(time + Date.now());
|
|
97
|
-
|
|
98
85
|
jest.advanceTimersByTime(time);
|
|
99
86
|
}
|
|
87
|
+
|
|
100
88
|
/**
|
|
101
89
|
* Mounts `scene` to the DOM, and returns the root scene element.
|
|
102
90
|
* @param {React.ReactNode} scene
|
|
103
91
|
* @return {HTMLElement} Created container DOM element with destroy() function
|
|
104
92
|
* attached.
|
|
105
93
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
94
|
function mount(scene) {
|
|
109
95
|
let root;
|
|
110
96
|
const res = document.createElement('div');
|
|
111
97
|
document.body.appendChild(res);
|
|
112
|
-
|
|
113
98
|
res.destroy = () => {
|
|
114
99
|
(0, _testUtils.act)(() => root.unmount());
|
|
115
100
|
res.remove();
|
|
116
101
|
};
|
|
117
|
-
|
|
118
102
|
(0, _testUtils.act)(() => {
|
|
119
103
|
root = (0, _client.createRoot)(res);
|
|
120
104
|
root.render(scene);
|
|
121
105
|
});
|
|
122
106
|
return res;
|
|
123
107
|
}
|
|
108
|
+
|
|
124
109
|
/* OLD STUFF BELOW THIS MARK */
|
|
125
110
|
|
|
126
111
|
/**
|
|
@@ -132,11 +117,10 @@ function mount(scene) {
|
|
|
132
117
|
* import { JU } from '@dr.pogodin/react-utils';
|
|
133
118
|
* console.log(JU.render(<div>Example</div>));
|
|
134
119
|
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
120
|
function render(component) {
|
|
138
121
|
return _reactTestRenderer.default.create(component).toJSON();
|
|
139
122
|
}
|
|
123
|
+
|
|
140
124
|
/**
|
|
141
125
|
* Generates a shallow render of given ReactJS component, using
|
|
142
126
|
* [react-test-renderer/shallow](https://reactjs.org/docs/shallow-renderer.html)
|
|
@@ -144,13 +128,12 @@ function render(component) {
|
|
|
144
128
|
* @param {object} component ReactJS component to render.
|
|
145
129
|
* @return {object} JSON representation of the shallow component's render tree.
|
|
146
130
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
131
|
function shallowRender(component) {
|
|
150
132
|
const renderer = new _shallow.default();
|
|
151
133
|
renderer.render(component);
|
|
152
134
|
return renderer.getRenderOutput();
|
|
153
135
|
}
|
|
136
|
+
|
|
154
137
|
/**
|
|
155
138
|
* Makes a shallow snapshot test of the given ReactJS component, and also
|
|
156
139
|
* returns JSON representation of the rendered component tree. Under the hood
|
|
@@ -160,13 +143,12 @@ function shallowRender(component) {
|
|
|
160
143
|
* @param {object} component ReactJS component to render.
|
|
161
144
|
* @return {object} JSON representation of shallow render.
|
|
162
145
|
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
146
|
function shallowSnapshot(component) {
|
|
166
147
|
const res = shallowRender(component);
|
|
167
148
|
expect(res).toMatchSnapshot();
|
|
168
149
|
return res;
|
|
169
150
|
}
|
|
151
|
+
|
|
170
152
|
/**
|
|
171
153
|
* Makes snapshot test of the given ReactJS component, and also returns JSON
|
|
172
154
|
* representation of the rendered component tree. Under the hood, it uses
|
|
@@ -175,14 +157,11 @@ function shallowSnapshot(component) {
|
|
|
175
157
|
* @param {object} component ReactJS component to render.
|
|
176
158
|
* @return {object} JSON render of the component.
|
|
177
159
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
180
160
|
function snapshot(component) {
|
|
181
161
|
const res = render(component);
|
|
182
162
|
expect(res).toMatchSnapshot();
|
|
183
163
|
return res;
|
|
184
164
|
}
|
|
185
|
-
|
|
186
165
|
const simulate = _testUtils.default.Simulate;
|
|
187
166
|
exports.simulate = simulate;
|
|
188
167
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["global","IS_REACT_ACT_ENVIRONMENT","originalProcessVersions","process","versions","mockClientSide","Object","defineProperty","value","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockTimer","time","mockdate","set","Date","now","jest","advanceTimersByTime","mount","scene","root","res","document","createElement","body","appendChild","destroy","act","unmount","remove","createRoot","render","component","Renderer","create","toJSON","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","TU","Simulate"],"sources":["../../../../../src/shared/utils/jest/index.jsx"],"sourcesContent":["/* global expect, jest, document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport mockdate from 'mockdate';\nimport { createRoot } from 'react-dom/client';\nimport TU, { act } from 'react-dom/test-utils';\n\n/* eslint-disable import/no-extraneous-dependencies */\nimport Renderer from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow';\n/* eslint-enable import/no-extraneous-dependencies */\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react-dom/test-utils`.\n * @param {function} action\n */\nexport { act };\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide() {\n Object.defineProperty(process, 'versions', { value: null });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide() {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0) {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time) {\n mockdate.set(time + Date.now());\n jest.advanceTimersByTime(time);\n}\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param {React.ReactNode} scene\n * @return {HTMLElement} Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene) {\n let root;\n const res = document.createElement('div');\n document.body.appendChild(res);\n res.destroy = () => {\n act(() => root.unmount());\n res.remove();\n };\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\n/* OLD STUFF BELOW THIS MARK */\n\n/**\n * Renders provided ReactJS component into JSON representation of the component\n * tree, using [`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer).\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the rendered tree.\n * @example\n * import { JU } from '@dr.pogodin/react-utils';\n * console.log(JU.render(<div>Example</div>));\n */\nexport function render(component) {\n return Renderer.create(component).toJSON();\n}\n\n/**\n * Generates a shallow render of given ReactJS component, using\n * [react-test-renderer/shallow](https://reactjs.org/docs/shallow-renderer.html)\n * and returns the result.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the shallow component's render tree.\n */\nexport function shallowRender(component) {\n const renderer = new ShallowRenderer();\n renderer.render(component);\n return renderer.getRenderOutput();\n}\n\n/**\n * Makes a shallow snapshot test of the given ReactJS component, and also\n * returns JSON representation of the rendered component tree. Under the hood\n * it uses {@link module:JU.shallowRender shallowRender(..)} to generate\n * the render, then executes `expect(RENDER_RESULT).toMatchSnapshot()`,\n * and finally returns the `RENDER_RESULT` to the caller.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of shallow render.\n */\nexport function shallowSnapshot(component) {\n const res = shallowRender(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\n/**\n * Makes snapshot test of the given ReactJS component, and also returns JSON\n * representation of the rendered component tree. Under the hood, it uses\n * {@link module:JU.render render(..)} to render it, then executes\n * `expect(RENDER_RESULT).toMatchSnapshot()`, and then returns `RENDER_RESULT`.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON render of the component.\n */\nexport function snapshot(component) {\n const res = render(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\nexport const simulate = TU.Simulate;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["global","IS_REACT_ACT_ENVIRONMENT","originalProcessVersions","process","versions","mockClientSide","Object","defineProperty","value","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockTimer","time","mockdate","set","Date","now","jest","advanceTimersByTime","mount","scene","root","res","document","createElement","body","appendChild","destroy","act","unmount","remove","createRoot","render","component","Renderer","create","toJSON","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","TU","Simulate"],"sources":["../../../../../src/shared/utils/jest/index.jsx"],"sourcesContent":["/* global expect, jest, document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport mockdate from 'mockdate';\nimport { createRoot } from 'react-dom/client';\nimport TU, { act } from 'react-dom/test-utils';\n\n/* eslint-disable import/no-extraneous-dependencies */\nimport Renderer from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow';\n/* eslint-enable import/no-extraneous-dependencies */\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react-dom/test-utils`.\n * @param {function} action\n */\nexport { act };\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide() {\n Object.defineProperty(process, 'versions', { value: null });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide() {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0) {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time) {\n mockdate.set(time + Date.now());\n jest.advanceTimersByTime(time);\n}\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param {React.ReactNode} scene\n * @return {HTMLElement} Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene) {\n let root;\n const res = document.createElement('div');\n document.body.appendChild(res);\n res.destroy = () => {\n act(() => root.unmount());\n res.remove();\n };\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\n/* OLD STUFF BELOW THIS MARK */\n\n/**\n * Renders provided ReactJS component into JSON representation of the component\n * tree, using [`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer).\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the rendered tree.\n * @example\n * import { JU } from '@dr.pogodin/react-utils';\n * console.log(JU.render(<div>Example</div>));\n */\nexport function render(component) {\n return Renderer.create(component).toJSON();\n}\n\n/**\n * Generates a shallow render of given ReactJS component, using\n * [react-test-renderer/shallow](https://reactjs.org/docs/shallow-renderer.html)\n * and returns the result.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the shallow component's render tree.\n */\nexport function shallowRender(component) {\n const renderer = new ShallowRenderer();\n renderer.render(component);\n return renderer.getRenderOutput();\n}\n\n/**\n * Makes a shallow snapshot test of the given ReactJS component, and also\n * returns JSON representation of the rendered component tree. Under the hood\n * it uses {@link module:JU.shallowRender shallowRender(..)} to generate\n * the render, then executes `expect(RENDER_RESULT).toMatchSnapshot()`,\n * and finally returns the `RENDER_RESULT` to the caller.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of shallow render.\n */\nexport function shallowSnapshot(component) {\n const res = shallowRender(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\n/**\n * Makes snapshot test of the given ReactJS component, and also returns JSON\n * representation of the rendered component tree. Under the hood, it uses\n * {@link module:JU.render render(..)} to render it, then executes\n * `expect(RENDER_RESULT).toMatchSnapshot()`, and then returns `RENDER_RESULT`.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON render of the component.\n */\nexport function snapshot(component) {\n const res = render(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\nexport const simulate = TU.Simulate;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGA;AACA;AACA;AAGA;AACA;AAA0D;AAAA;AAT1D;AACA;;AAMA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;;AAGAA,MAAM,CAACC,wBAAwB,GAAG,IAAI;AAEtC,MAAMC,uBAAuB,GAAGC,OAAO,CAACC,QAAQ;;AAEhD;AACA;AACA;AACA;AACO,SAASC,cAAc,GAAG;EAC/BC,MAAM,CAACC,cAAc,CAACJ,OAAO,EAAE,UAAU,EAAE;IAAEK,KAAK,EAAE;EAAK,CAAC,CAAC;AAC7D;;AAEA;AACA;AACA;AACO,SAASC,gBAAgB,GAAG;EACjCH,MAAM,CAACC,cAAc,CAACJ,OAAO,EAAE,UAAU,EAAE;IACzCK,KAAK,EAAEN,uBAAuB;IAC9BQ,QAA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A;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASU,MAAM,CAACC,SAAS,EAAE;EAChC,OAAOC,0BAAQ,CAACC,MAAM,CAACF,SAAS,CAAC,CAACG,MAAM,EAAE;AAC5C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,aAAa,CAACJ,SAAS,EAAE;EACvC,MAAMK,QAAQ,GAAG,IAAIC,gBAAe,EAAE;EACtCD,QAAQ,CAACN,MAAM,CAACC,SAAS,CAAC;EAC1B,OAAOK,QAAQ,CAACE,eAAe,EAAE;AACnC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,eAAe,CAACR,SAAS,EAAE;EACzC,MAAMX,GAAG,GAAGe,aAAa,CAACJ,SAAS,CAAC;EACpCS,MAAM,CAACpB,GAAG,CAAC,CAACqB,eAAe,EAAE;EAC7B,OAAOrB,GAAG;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASsB,QAAQ,CAACX,SAAS,EAAE;EAClC,MAAMX,GAAG,GAAGU,MAAM,CAACC,SAAS,CAAC;EAC7BS,MAAM,CAACpB,GAAG,CAAC,CAACqB,eAAe,EAAE;EAC7B,OAAOrB,GAAG;AACZ;AAEO,MAAMuB,QAAQ,GAAGC,kBAAE,CAACC,QAAQ;AAAC"}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = splitComponent;
|
|
9
|
-
|
|
10
8
|
var _react = require("react");
|
|
11
|
-
|
|
12
9
|
var _CodeSplit = _interopRequireDefault(require("../components/CodeSplit"));
|
|
13
|
-
|
|
14
10
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
15
11
|
|
|
16
12
|
/**
|
|
@@ -33,7 +29,8 @@ function splitComponent({
|
|
|
33
29
|
return ({
|
|
34
30
|
children,
|
|
35
31
|
...props
|
|
36
|
-
} = {}) => /*#__PURE__*/(0, _react.createElement)(_CodeSplit.default, {
|
|
32
|
+
} = {}) => /*#__PURE__*/(0, _react.createElement)(_CodeSplit.default, {
|
|
33
|
+
...props,
|
|
37
34
|
chunkName,
|
|
38
35
|
getComponent,
|
|
39
36
|
placeholder
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitComponent.js","names":["splitComponent","chunkName","getComponent","placeholder","children","props","createElement","CodeSplit"],"sources":["../../../../src/shared/utils/splitComponent.js"],"sourcesContent":["/* eslint-disable react/jsx-props-no-spreading */\n\nimport { createElement } from 'react';\n\nimport CodeSplit from 'components/CodeSplit';\n\n/**\n * Wraps a regular React component into a \"code splitting\" component,\n * i.e. all code used exclusively by that component and its sub-tree\n * will go into a separate, asynchronously loaded, code chunk for\n * the client-side.\n * @param {object} options\n * @param {string} options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent({\n chunkName,\n getComponent,\n placeholder,\n}) {\n // eslint-disable-next-line react/prop-types\n return ({ children, ...props } = {}) => createElement(\n CodeSplit,\n {\n ...props,\n chunkName,\n getComponent,\n placeholder,\n },\n children,\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"splitComponent.js","names":["splitComponent","chunkName","getComponent","placeholder","children","props","createElement","CodeSplit"],"sources":["../../../../src/shared/utils/splitComponent.js"],"sourcesContent":["/* eslint-disable react/jsx-props-no-spreading */\n\nimport { createElement } from 'react';\n\nimport CodeSplit from 'components/CodeSplit';\n\n/**\n * Wraps a regular React component into a \"code splitting\" component,\n * i.e. all code used exclusively by that component and its sub-tree\n * will go into a separate, asynchronously loaded, code chunk for\n * the client-side.\n * @param {object} options\n * @param {string} options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent({\n chunkName,\n getComponent,\n placeholder,\n}) {\n // eslint-disable-next-line react/prop-types\n return ({ children, ...props } = {}) => createElement(\n CodeSplit,\n {\n ...props,\n chunkName,\n getComponent,\n placeholder,\n },\n children,\n );\n}\n"],"mappings":";;;;;;;AAEA;AAEA;AAJA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAc,CAAC;EACrCC,SAAS;EACTC,YAAY;EACZC;AACF,CAAC,EAAE;EACD;EACA,OAAO,CAAC;IAAEC,QAAQ;IAAE,GAAGC;EAAM,CAAC,GAAG,CAAC,CAAC,kBAAK,IAAAC,oBAAa,EACnDC,kBAAS,EACT;IACE,GAAGF,KAAK;IACRJ,SAAS;IACTC,YAAY;IACZC;EACF,CAAC,EACDC,QAAQ,CACT;AACH"}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
8
|
exports.timer = timer;
|
|
10
|
-
|
|
11
9
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
12
|
-
|
|
13
10
|
var _lodash = require("lodash");
|
|
14
|
-
|
|
15
11
|
var _Barrier = require("./Barrier");
|
|
16
|
-
|
|
17
12
|
/**
|
|
18
13
|
* @static
|
|
19
14
|
* @const SEC_MS
|
|
@@ -23,6 +18,7 @@ var _Barrier = require("./Barrier");
|
|
|
23
18
|
* console.log(time.SEC_MS); // Prints: 1000
|
|
24
19
|
*/
|
|
25
20
|
_dayjs.default.SEC_MS = 1000;
|
|
21
|
+
|
|
26
22
|
/**
|
|
27
23
|
* @static
|
|
28
24
|
* @const MIN_MS
|
|
@@ -31,8 +27,8 @@ _dayjs.default.SEC_MS = 1000;
|
|
|
31
27
|
* import { time } from '@dr.pogodin/react-utils';
|
|
32
28
|
* console.log(time.MIN_MS); // Prints: 60000
|
|
33
29
|
*/
|
|
34
|
-
|
|
35
30
|
_dayjs.default.MIN_MS = 60 * _dayjs.default.SEC_MS;
|
|
31
|
+
|
|
36
32
|
/**
|
|
37
33
|
* @static
|
|
38
34
|
* @const HOUR_MS
|
|
@@ -41,8 +37,8 @@ _dayjs.default.MIN_MS = 60 * _dayjs.default.SEC_MS;
|
|
|
41
37
|
* import { time } from '@dr.pogodin/react-utils';
|
|
42
38
|
* console.log(time.HOUR_MS); // Prints: 3600000
|
|
43
39
|
*/
|
|
44
|
-
|
|
45
40
|
_dayjs.default.HOUR_MS = 60 * _dayjs.default.MIN_MS;
|
|
41
|
+
|
|
46
42
|
/**
|
|
47
43
|
* @static
|
|
48
44
|
* @const DAY_MS
|
|
@@ -51,8 +47,8 @@ _dayjs.default.HOUR_MS = 60 * _dayjs.default.MIN_MS;
|
|
|
51
47
|
* import { time } from '@dr.pogodin/react-utils';
|
|
52
48
|
* console.log(time.DAY_MS); // Prints: 86400000
|
|
53
49
|
*/
|
|
54
|
-
|
|
55
50
|
_dayjs.default.DAY_MS = 24 * _dayjs.default.HOUR_MS;
|
|
51
|
+
|
|
56
52
|
/**
|
|
57
53
|
* @static
|
|
58
54
|
* @const YEAR_MS
|
|
@@ -62,8 +58,8 @@ _dayjs.default.DAY_MS = 24 * _dayjs.default.HOUR_MS;
|
|
|
62
58
|
* import { time } from '@dr.pogodin/react-utils';
|
|
63
59
|
* console.log(time.YEAR_MS); // Prints: 31536000000
|
|
64
60
|
*/
|
|
65
|
-
|
|
66
61
|
_dayjs.default.YEAR_MS = 365 * _dayjs.default.DAY_MS;
|
|
62
|
+
|
|
67
63
|
/**
|
|
68
64
|
* @static
|
|
69
65
|
* @func now
|
|
@@ -73,8 +69,8 @@ _dayjs.default.YEAR_MS = 365 * _dayjs.default.DAY_MS;
|
|
|
73
69
|
* import { time } from '@dr.pogodin/react-utils';
|
|
74
70
|
* console.log(time.now()); // Prints the current timestamp, e.g. 1618608761000.
|
|
75
71
|
*/
|
|
76
|
-
|
|
77
72
|
_dayjs.default.now = Date.now;
|
|
73
|
+
|
|
78
74
|
/**
|
|
79
75
|
* Creates a Promise, which resolves after the given timeout.
|
|
80
76
|
* @param {number} timeout Timeout [ms].
|
|
@@ -82,22 +78,17 @@ _dayjs.default.now = Date.now;
|
|
|
82
78
|
* .abort() method attached, which cancels the pending timer resolution
|
|
83
79
|
* (without resolving or rejecting the barrier).
|
|
84
80
|
*/
|
|
85
|
-
|
|
86
81
|
async function timer(timeout) {
|
|
87
82
|
const res = new _Barrier.Barrier();
|
|
88
|
-
|
|
89
83
|
if (timeout > 0) {
|
|
90
84
|
const id = setTimeout(res.resolve.bind(res), timeout);
|
|
91
|
-
|
|
92
85
|
res.abort = () => clearTimeout(id);
|
|
93
86
|
} else {
|
|
94
87
|
res.abort = _lodash.noop;
|
|
95
88
|
res.resolve();
|
|
96
89
|
}
|
|
97
|
-
|
|
98
90
|
return res;
|
|
99
91
|
}
|
|
100
|
-
|
|
101
92
|
_dayjs.default.timer = timer;
|
|
102
93
|
var _default = _dayjs.default;
|
|
103
94
|
exports.default = _default;
|