@dr.pogodin/react-utils 1.16.2 → 1.17.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.
Files changed (97) hide show
  1. package/build/development/client/index.js.map +1 -1
  2. package/build/development/client/init.js.map +1 -1
  3. package/build/development/index.js.map +1 -1
  4. package/build/development/server/Cache.js.map +1 -1
  5. package/build/development/server/index.js +5 -10
  6. package/build/development/server/index.js.map +1 -1
  7. package/build/development/server/renderer.js +35 -15
  8. package/build/development/server/renderer.js.map +1 -1
  9. package/build/development/server/server.js.map +1 -1
  10. package/build/development/server/utils/errors.js.map +1 -1
  11. package/build/development/server/utils/index.js.map +1 -1
  12. package/build/development/shared/components/Button/index.js.map +1 -1
  13. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  14. package/build/development/shared/components/CodeSplit/index.js.map +1 -1
  15. package/build/development/shared/components/Dropdown/index.js.map +1 -1
  16. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  17. package/build/development/shared/components/Input/index.js.map +1 -1
  18. package/build/development/shared/components/Link.js.map +1 -1
  19. package/build/development/shared/components/MetaTags.js.map +1 -1
  20. package/build/development/shared/components/Modal/index.js.map +1 -1
  21. package/build/development/shared/components/NavLink.js.map +1 -1
  22. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  23. package/build/development/shared/components/ScalableRect/index.js.map +1 -1
  24. package/build/development/shared/components/Throbber/index.js.map +1 -1
  25. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  26. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  27. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  28. package/build/development/shared/components/index.js.map +1 -1
  29. package/build/development/shared/utils/Barrier.js.map +1 -1
  30. package/build/development/shared/utils/Emitter.js.map +1 -1
  31. package/build/development/shared/utils/Semaphore.js.map +1 -1
  32. package/build/development/shared/utils/config.js.map +1 -1
  33. package/build/development/shared/utils/index.js.map +1 -1
  34. package/build/development/shared/utils/isomorphy.js +1 -1
  35. package/build/development/shared/utils/isomorphy.js.map +1 -1
  36. package/build/development/shared/utils/jest/E2eSsrEnv.js +179 -0
  37. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -0
  38. package/build/development/shared/utils/{jest.js → jest/index.js} +1 -1
  39. package/build/development/shared/utils/jest/index.js.map +1 -0
  40. package/build/development/shared/utils/splitComponent.js +1 -1
  41. package/build/development/shared/utils/splitComponent.js.map +1 -1
  42. package/build/development/shared/utils/time.js.map +1 -1
  43. package/build/development/shared/utils/webpack.js.map +1 -1
  44. package/build/development/web.bundle.js +3 -3
  45. package/build/production/client/index.js.map +1 -1
  46. package/build/production/client/init.js.map +1 -1
  47. package/build/production/index.js.map +1 -1
  48. package/build/production/server/Cache.js.map +1 -1
  49. package/build/production/server/index.js +5 -5
  50. package/build/production/server/index.js.map +1 -1
  51. package/build/production/server/renderer.js +27 -10
  52. package/build/production/server/renderer.js.map +1 -1
  53. package/build/production/server/server.js.map +1 -1
  54. package/build/production/server/utils/errors.js.map +1 -1
  55. package/build/production/server/utils/index.js.map +1 -1
  56. package/build/production/shared/components/Button/index.js.map +1 -1
  57. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  58. package/build/production/shared/components/CodeSplit/index.js.map +1 -1
  59. package/build/production/shared/components/Dropdown/index.js.map +1 -1
  60. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  61. package/build/production/shared/components/Input/index.js.map +1 -1
  62. package/build/production/shared/components/Link.js.map +1 -1
  63. package/build/production/shared/components/MetaTags.js.map +1 -1
  64. package/build/production/shared/components/Modal/index.js.map +1 -1
  65. package/build/production/shared/components/NavLink.js.map +1 -1
  66. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  67. package/build/production/shared/components/ScalableRect/index.js.map +1 -1
  68. package/build/production/shared/components/Throbber/index.js.map +1 -1
  69. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  70. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  71. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  72. package/build/production/shared/components/index.js.map +1 -1
  73. package/build/production/shared/utils/Barrier.js.map +1 -1
  74. package/build/production/shared/utils/Emitter.js.map +1 -1
  75. package/build/production/shared/utils/Semaphore.js.map +1 -1
  76. package/build/production/shared/utils/config.js.map +1 -1
  77. package/build/production/shared/utils/index.js.map +1 -1
  78. package/build/production/shared/utils/isomorphy.js +1 -1
  79. package/build/production/shared/utils/isomorphy.js.map +1 -1
  80. package/build/production/shared/utils/jest/E2eSsrEnv.js +43 -0
  81. package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -0
  82. package/build/production/shared/utils/{jest.js → jest/index.js} +1 -1
  83. package/build/production/shared/utils/jest/index.js.map +1 -0
  84. package/build/production/shared/utils/splitComponent.js +1 -1
  85. package/build/production/shared/utils/splitComponent.js.map +1 -1
  86. package/build/production/shared/utils/time.js.map +1 -1
  87. package/build/production/shared/utils/webpack.js.map +1 -1
  88. package/build/production/web.bundle.js +1 -1
  89. package/build/production/web.bundle.js.map +1 -1
  90. package/config/jest/default.js +3 -1
  91. package/config/webpack/app-base.js +48 -27
  92. package/config/webpack/app-development.js +40 -22
  93. package/config/webpack/app-production.js +8 -0
  94. package/config/webpack/lib-base.js +13 -6
  95. package/package.json +32 -28
  96. package/build/development/shared/utils/jest.js.map +0 -1
  97. package/build/production/shared/utils/jest.js.map +0 -1
@@ -42,6 +42,8 @@ const {
42
42
  * setting in the Babel config.
43
43
  * @param {boolean} [ops.dontEmitBuildInfo] If set the `.build-info` file won't
44
44
  * be created at the disk during the compilation.
45
+ * @param {boolean} [ops.dontUseProgressPlugin] Set to not include progress
46
+ * plugin.
45
47
  * @param {string|string[]} ops.entry Entry points for "main" chunk. The config
46
48
  * will prepend them by some necessary polyfills, e.g.:
47
49
  * ([babel-polyfill](https://babeljs.io/docs/usage/polyfill/),
@@ -63,12 +65,14 @@ const {
63
65
  * [client-side initialization script](docs/client.md)
64
66
  * provided by **@dr.pogodin/react-utils**. Note that `swDest`'s value cannot be
65
67
  * overriden by config options provided via `workbox` object.
66
- * @param {boolean} [ops.keepBuildInfo] If `true` and a `.build-info` file from
67
- * a previous build exists in the context directory, it will be loaded and
68
- * used, rather than re-generated by the config factory. It allows to re-create
69
- * the Webpack config during a server launch without re-generation of the build
70
- * info file created during a previous build (and thus bundled into the
71
- * frontend bundle).
68
+ * @param {boolean|object} [ops.keepBuildInfo] If `true` and a `.build-info`
69
+ * file from a previous build exists in the context directory, it will be
70
+ * loaded and used, rather than re-generated by the config factory. It allows
71
+ * to re-create the Webpack config during a server launch without re-generation
72
+ * of the build info file created during a previous build (and thus bundled
73
+ * into the frontend bundle). If an object is provided, it will be used as
74
+ * the build info, instead of trying to load it from the filesystem. This
75
+ * feature is intended for testing context.
72
76
  * @param {string} ops.mode
73
77
  * [Webpack mode](https://webpack.js.org/concepts/mode/).
74
78
  * @param {string} [ops.outputPath=build] Optional. Output path for the build.
@@ -158,29 +162,47 @@ module.exports = function configFactory(ops) {
158
162
 
159
163
  // TODO: Once all assets are named by hashes, we probably don't need build
160
164
  // info anymore beside the key, which can be merged into stats object?
165
+ // On the other hand, it is still handy to have to pass around the build
166
+ // timestamp, and any other similar information to the actual app, so it
167
+ // can be used in some scenarious.
161
168
  let buildInfo;
162
169
  const buildInfoUrl = path.resolve(o.context, '.build-info');
163
- /* If build-info file is found, we reuse those data. */
164
- if (!o.dontEmitBuildInfo) {
165
- if (fs.existsSync(buildInfoUrl) && o.keepBuildInfo) {
166
- buildInfo = JSON.parse(fs.readFileSync(buildInfoUrl));
167
- } else {
168
- /* Stores misc build info into the local ".build-info" file in the context
169
- * directory. */
170
- buildInfo = {
171
- /* A random 32-bit key, that can be used for encryption. */
172
- key: forge.random.getBytesSync(32),
173
170
 
174
- /* Public path used during build. */
175
- publicPath: o.publicPath,
171
+ if (o.keepBuildInfo) {
172
+ // If "true" - attempt to load from the filesystem.
173
+ if (o.keepBuildInfo === true) {
174
+ if (fs.existsSync(buildInfoUrl)) {
175
+ buildInfo = JSON.parse(fs.readFileSync(buildInfoUrl));
176
+ }
177
+
178
+ // Otherwise we assume .keepBuildInfo value itself is the build info object
179
+ // to use in the build.
180
+ } else buildInfo = o.keepBuildInfo;
181
+ }
182
+
183
+ // Even if "keepBuildInfo" option was provided, we still generate a new
184
+ // build info object in case nothing could be loaded.
185
+ if (!buildInfo) {
186
+ buildInfo = Object.freeze({
187
+ /* A random 32-bit key, that can be used for encryption. */
188
+ key: forge.random.getBytesSync(32),
189
+
190
+ /* Public path used during build. */
191
+ publicPath: o.publicPath,
176
192
 
177
- /* `true` if client-side code should setup a service worker. */
178
- useServiceWorker: Boolean(o.workbox),
179
- };
180
- fs.writeFileSync(buildInfoUrl, JSON.stringify(buildInfo));
181
- }
193
+ /* `true` if client-side code should setup a service worker. */
194
+ useServiceWorker: Boolean(o.workbox),
195
+ });
182
196
  }
183
197
 
198
+ // If not opted-out, we write the build info to the filesystem. We also attach
199
+ // it to the factory function itself, so it can be easily accessed right after
200
+ // the factory call in testing scenarios.
201
+ if (!o.dontEmitBuildInfo) {
202
+ fs.writeFileSync(buildInfoUrl, JSON.stringify(buildInfo));
203
+ }
204
+ configFactory.buildInfo = buildInfo;
205
+
184
206
  /* Entry points normalization. */
185
207
  const entry = [
186
208
  'core-js/stable',
@@ -190,12 +212,11 @@ module.exports = function configFactory(ops) {
190
212
  ];
191
213
 
192
214
  const plugins = [
193
- new DefinePlugin({
194
- BUILD_INFO: JSON.stringify(buildInfo),
195
- }),
196
- new ProgressPlugin(),
215
+ new DefinePlugin({ BUILD_INFO: JSON.stringify(buildInfo) }),
197
216
  ];
198
217
 
218
+ if (!ops.dontUseProgressPlugin) plugins.push(new ProgressPlugin());
219
+
199
220
  /* Adds InjectManifest plugin from WorkBox, if opted to. */
200
221
  if (o.workbox) {
201
222
  if (!isObject(o.workbox)) o.workbox = {};
@@ -13,17 +13,50 @@ const { merge } = require('webpack-merge');
13
13
 
14
14
  const baseFactory = require('./app-base');
15
15
 
16
+ /**
17
+ * @param {object} ops
18
+ * @param {boolean} [ops.dontUseReactGlobalStateDebugging]
19
+ * @param {boolean} [ops.dontUseHmr]
20
+ */
16
21
  module.exports = function configFactory(ops) {
17
22
  const o = defaults(clone(ops), {
18
23
  cssLocalIdent: '[package]___[path][name]___[local]___[hash:base64:6]',
19
24
  });
20
25
 
21
- const entry = [
22
- '@dr.pogodin/react-utils/build/development/client/init',
23
- 'webpack-hot-middleware/client?reload=true',
24
- ...Array.isArray(o.entry) ? o.entry : [o.entry],
26
+ const entry = ['@dr.pogodin/react-utils/build/development/client/init'];
27
+ if (!o.dontUseHmr) entry.push('webpack-hot-middleware/client?reload=true');
28
+ entry.push(...Array.isArray(o.entry) ? o.entry : [o.entry]);
29
+
30
+ const plugins = [
31
+ new MiniCssExtractPlugin({
32
+ chunkFilename: '[id].css',
33
+ filename: '[id].css',
34
+ }),
35
+ new webpack.DefinePlugin({
36
+ 'process.env.BABEL_ENV': JSON.stringify('development'),
37
+ 'process.env.DEV_TOOLS': JSON.stringify(true),
38
+ 'process.env.NODE_ENV': JSON.stringify('development'),
39
+ 'process.env.REACT_GLOBAL_STATE_DEBUG':
40
+ JSON.stringify(!o.dontUseReactGlobalStateDebugging),
41
+ }),
25
42
  ];
26
43
 
44
+ // TODO: There should be no reason to include these plugins when HMR is opted
45
+ // out, however if I remove them, the compilation fails with obscure
46
+ // "ReferenceError: $RefreshReg$ is not defined" error. For now it seems
47
+ // fine to keep these plugins anyway, thus the shortcut of "if" condition
48
+ // below.
49
+ if (true || !o.dontUseHmr) {
50
+ plugins.push(
51
+ new webpack.HotModuleReplacementPlugin(),
52
+ new ReactRefreshPlugin({
53
+ overlay: {
54
+ sockIntegration: 'whm',
55
+ },
56
+ }),
57
+ );
58
+ }
59
+
27
60
  const res = merge(baseFactory({
28
61
  ...o,
29
62
  babelEnv: 'development',
@@ -34,24 +67,7 @@ module.exports = function configFactory(ops) {
34
67
  chunkFilename: '[id].js',
35
68
  filename: '[id].js',
36
69
  },
37
- plugins: [
38
- new MiniCssExtractPlugin({
39
- chunkFilename: '[id].css',
40
- filename: '[id].css',
41
- }),
42
- new webpack.DefinePlugin({
43
- 'process.env.BABEL_ENV': JSON.stringify('development'),
44
- 'process.env.DEV_TOOLS': JSON.stringify(true),
45
- 'process.env.NODE_ENV': JSON.stringify('development'),
46
- 'process.env.REACT_GLOBAL_STATE_DEBUG': JSON.stringify(true),
47
- }),
48
- new webpack.HotModuleReplacementPlugin(),
49
- new ReactRefreshPlugin({
50
- overlay: {
51
- sockIntegration: 'whm',
52
- },
53
- }),
54
- ],
70
+ plugins,
55
71
  snapshot: {
56
72
  // This enforces Webpack to watch for possible changes in node_modules
57
73
  // dependencies, which is a great convenience in library-centric dev
@@ -59,5 +75,7 @@ module.exports = function configFactory(ops) {
59
75
  managedPaths: [],
60
76
  },
61
77
  });
78
+
79
+ configFactory.buildInfo = baseFactory.buildInfo;
62
80
  return res;
63
81
  };
@@ -10,6 +10,12 @@ const webpack = require('webpack');
10
10
  const { merge } = require('webpack-merge');
11
11
  const baseFactory = require('./app-base');
12
12
 
13
+ /**
14
+ * @param {object} ops
15
+ * @param {string} ops.context Base URL for resolution of relative config paths.
16
+ * @param {boolean} [ops.dontEmitBuildInfo] If set the `.build-info` file won't
17
+ * be created at the disk during the compilation.
18
+ */
13
19
  module.exports = function configFactory(ops) {
14
20
  const entry = [
15
21
  '@dr.pogodin/react-utils/build/production/client/init',
@@ -49,5 +55,7 @@ module.exports = function configFactory(ops) {
49
55
  }),
50
56
  ],
51
57
  });
58
+
59
+ configFactory.buildInfo = baseFactory.buildInfo;
52
60
  return res;
53
61
  };
@@ -13,7 +13,19 @@ const {
13
13
  getLocalIdent,
14
14
  } = require('@dr.pogodin/babel-plugin-react-css-modules/utils');
15
15
 
16
+ /**
17
+ * @param {object} ops
18
+ * @param {boolean} [ops.dontUseProgressPlugin] Set to not include progress
19
+ * plugin.
20
+ * @return {object}
21
+ */
16
22
  module.exports = function configFactory(ops) {
23
+ const plugins = [
24
+ new MiniCssExtractPlugin({ filename: 'style.css' }),
25
+ ];
26
+
27
+ if (!ops.dontUseProgressPlugin) plugins.push(new ProgressPlugin());
28
+
17
29
  return {
18
30
  context: ops.context,
19
31
  entry: ops.entry,
@@ -47,12 +59,7 @@ module.exports = function configFactory(ops) {
47
59
  path: ops.outputPath,
48
60
  libraryTarget: 'umd',
49
61
  },
50
- plugins: [
51
- new MiniCssExtractPlugin({
52
- filename: 'style.css',
53
- }),
54
- new ProgressPlugin(),
55
- ],
62
+ plugins,
56
63
  module: {
57
64
  rules: [{
58
65
  /* Handles font imports in url(..) instructions in CSS. Effectively,
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.16.2",
2
+ "version": "1.17.2",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -10,16 +10,16 @@
10
10
  "dependencies": {
11
11
  "@babel/runtime": "^7.17.9",
12
12
  "@dr.pogodin/babel-plugin-react-css-modules": "^6.8.0",
13
- "@dr.pogodin/react-global-state": "^0.8.1",
14
- "@dr.pogodin/react-themes": "^1.4.2",
15
- "axios": "^0.26.1",
13
+ "@dr.pogodin/react-global-state": "^0.8.3",
14
+ "@dr.pogodin/react-themes": "^1.4.3",
15
+ "axios": "^0.27.2",
16
16
  "commander": "^9.0.0",
17
17
  "compression": "^1.7.4",
18
18
  "config": "^3.3.7",
19
19
  "cookie-parser": "^1.4.6",
20
20
  "cross-env": "^7.0.3",
21
21
  "dayjs": "^1.11.1",
22
- "express": "^4.17.3",
22
+ "express": "^4.18.1",
23
23
  "helmet": "^5.0.2",
24
24
  "http-status-codes": "^2.2.0",
25
25
  "joi": "^17.6.0",
@@ -29,8 +29,8 @@
29
29
  "prop-types": "^15.8.1",
30
30
  "qs": "^6.10.1",
31
31
  "raf": "^3.4.1",
32
- "react": "^18.0.0",
33
- "react-dom": "^18.0.0",
32
+ "react": "^18.1.0",
33
+ "react-dom": "^18.1.0",
34
34
  "react-helmet": "^6.1.0",
35
35
  "react-router-dom": "^6.3.0",
36
36
  "request-ip": "^2.1.3",
@@ -43,51 +43,54 @@
43
43
  },
44
44
  "description": "Collection of generic ReactJS components and utils",
45
45
  "devDependencies": {
46
- "@babel/cli": "^7.17.6",
47
- "@babel/core": "^7.17.9",
46
+ "@babel/cli": "^7.17.10",
47
+ "@babel/core": "^7.17.10",
48
48
  "@babel/eslint-parser": "^7.17.0",
49
49
  "@babel/eslint-plugin": "^7.17.7",
50
- "@babel/node": "^7.16.8",
51
- "@babel/plugin-transform-runtime": "^7.17.0",
52
- "@babel/preset-env": "^7.16.11",
50
+ "@babel/node": "^7.17.10",
51
+ "@babel/plugin-transform-runtime": "^7.17.10",
52
+ "@babel/preset-env": "^7.17.10",
53
53
  "@babel/preset-react": "^7.16.7",
54
+ "@babel/register": "^7.17.7",
54
55
  "@dr.pogodin/babel-plugin-transform-assets": "^1.1.1",
55
56
  "@dr.pogodin/babel-preset-svgr": "^1.4.0",
56
57
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
57
- "autoprefixer": "^10.4.4",
58
- "babel-jest": "^27.5.1",
59
- "babel-loader": "^8.2.4",
58
+ "autoprefixer": "^10.4.5",
59
+ "babel-jest": "^28.0.3",
60
+ "babel-loader": "^8.2.5",
60
61
  "babel-plugin-module-resolver": "^4.1.0",
61
- "core-js": "^3.22.0",
62
+ "core-js": "^3.22.3",
62
63
  "css-loader": "^6.7.1",
63
64
  "css-minimizer-webpack-plugin": "^3.4.1",
64
- "eslint": "^8.13.0",
65
+ "eslint": "^8.14.0",
65
66
  "eslint-config-airbnb": "^19.0.4",
66
67
  "eslint-import-resolver-babel-module": "^5.3.1",
67
68
  "eslint-plugin-import": "^2.26.0",
68
- "eslint-plugin-jest": "^26.1.4",
69
+ "eslint-plugin-jest": "^26.1.5",
69
70
  "eslint-plugin-jsx-a11y": "^6.5.1",
70
71
  "eslint-plugin-react": "^7.29.4",
71
- "eslint-plugin-react-hooks": "^4.4.0",
72
+ "eslint-plugin-react-hooks": "^4.5.0",
72
73
  "identity-obj-proxy": "^3.0.0",
73
- "jest": "^27.5.1",
74
+ "jest": "^28.0.3",
75
+ "jest-environment-jsdom": "^28.0.2",
76
+ "memfs": "^3.4.1",
74
77
  "mini-css-extract-plugin": "^2.6.0",
75
78
  "mockdate": "^3.0.5",
76
79
  "nodelist-foreach-polyfill": "^1.2.0",
77
- "postcss": "^8.4.12",
80
+ "postcss": "^8.4.13",
78
81
  "postcss-loader": "^6.2.1",
79
- "postcss-scss": "^4.0.3",
82
+ "postcss-scss": "^4.0.4",
80
83
  "pretty": "^2.0.0",
81
- "react-refresh": "^0.12.0",
82
- "react-test-renderer": "^18.0.0",
84
+ "react-refresh": "^0.13.0",
85
+ "react-test-renderer": "^18.1.0",
83
86
  "regenerator-runtime": "^0.13.9",
84
87
  "resolve-url-loader": "^5.0.0",
85
- "sass": "^1.50.0",
88
+ "sass": "^1.51.0",
86
89
  "sass-loader": "^12.6.0",
87
90
  "sitemap": "^7.1.1",
88
- "stylelint": "^14.7.1",
91
+ "stylelint": "^14.8.1",
89
92
  "stylelint-config-standard-scss": "^3.0.0",
90
- "supertest": "^6.2.2",
93
+ "supertest": "^6.2.3",
91
94
  "webpack": "^5.72.0",
92
95
  "webpack-dev-middleware": "^5.3.1",
93
96
  "webpack-hot-middleware": "^2.25.1",
@@ -124,7 +127,8 @@
124
127
  "browser": "./build/production/style.css"
125
128
  },
126
129
  "./build/development/client/init": "./build/development/client/init.js",
127
- "./build/production/client/init": "./build/production/client/init.js"
130
+ "./build/production/client/init": "./build/production/client/init.js",
131
+ "./jest-e2e-ssr-env": "./build/production/shared/utils/jest/E2eSsrEnv.js"
128
132
  },
129
133
  "homepage": "https://dr.pogodin.studio",
130
134
  "keywords": [
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/shared/utils/jest.jsx"],"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","unmount","remove","render","component","Renderer","create","toJSON","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","TU","Simulate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AAGA;;AACA;;;;;;AATA;;AACA;;AAMA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AAGAA,MAAM,CAACC,wBAAP,GAAkC,IAAlC;AAEA,MAAMC,uBAAuB,GAAGC,OAAO,CAACC,QAAxC;AAEA;AACA;AACA;AACA;;AACO,SAASC,cAAT,GAA0B;AAC/BC,EAAAA,MAAM,CAACC,cAAP,CAAsBJ,OAAtB,EAA+B,UAA/B,EAA2C;AAAEK,IAAAA,KAAK,EAAE;AAAT,GAA3C;AACD;AAED;AACA;AACA;;;AACO,SAASC,gBAAT,GAA4B;AACjCH,EAAAA,MAAM,CAACC,cAAP,CAAsBJ,OAAtB,EAA+B,UAA/B,EAA2C;AACzCK,IAAAA,KAAK,EAAEN,uBADkC;AAEzCQ,IAAAA,QAAQ,EAAE;AAF+B,GAA3C;AAID;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,WAAT,CAAqBC,IAAI,GAAG,CAA5B,EAA+B;AACpC,QAAMC,CAAC,GAAGD,IAAI,CAACE,QAAL,CAAc,EAAd,EAAkBC,QAAlB,CAA2B,EAA3B,EAA+B,GAA/B,CAAV;AACA,SAAQ,GAAEF,CAAC,CAACG,KAAF,CAAQ,CAAR,EAAW,CAAX,CAAc,IAAGH,CAAC,CAACG,KAAF,CAAQ,CAAR,EAAW,EAAX,CAAe,IAAGH,CAAC,CAACG,KAAF,CAAQ,EAAR,EAAY,EAAZ,CAAgB,IAAGH,CAAC,CAACG,KAAF,CAAQ,EAAR,EAAY,EAAZ,CAAgB,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AAGa,aAAa,CAACJ,SAAD,CAAzB;AACAS,EAAAA,MAAM,CAAClB,GAAD,CAAN,CAAYmB,eAAZ;AACA,SAAOnB,GAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASoB,QAAT,CAAkBX,SAAlB,EAA6B;AAClC,QAAMT,GAAG,GAAGQ,MAAM,CAACC,SAAD,CAAlB;AACAS,EAAAA,MAAM,CAAClB,GAAD,CAAN,CAAYmB,eAAZ;AACA,SAAOnB,GAAP;AACD;;AAEM,MAAMqB,QAAQ,GAAGC,mBAAGC,QAApB","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"],"file":"jest.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/shared/utils/jest.jsx"],"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","unmount","remove","render","component","Renderer","create","toJSON","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","TU","Simulate"],"mappings":"0iBAGA,0DACA,wCACA,wEAGA,8EACA,4E,o9BATA,mC,CACA,sD,CAMA,sD,CAGA,qD,CAEA;AACA;AACA;AACA;AACA,GAGAA,MAAM,CAACC,wBAAP,CAAkC,IAAlC,CAEA,KAAMC,CAAAA,uBAAuB,CAAGC,OAAO,CAACC,QAAxC,CAEA;AACA;AACA;AACA,GACO,QAASC,CAAAA,cAAT,EAA0B,CAC/BC,MAAM,CAACC,cAAP,CAAsBJ,OAAtB,CAA+B,UAA/B,CAA2C,CAAEK,KAAK,CAAE,IAAT,CAA3C,CACD,CAED;AACA;AACA,GACO,QAASC,CAAAA,gBAAT,EAA4B,CACjCH,MAAM,CAACC,cAAP,CAAsBJ,OAAtB,CAA+B,UAA/B,CAA2C,CACzCK,KAAK,CAAEN,uBADkC,CAEzCQ,QAAQ,CAAE,KAF+B,CAA3C,CAID,CAED;AACA;AACA;AACA;AACA;AACA,GACO,QAASC,CAAAA,WAAT,CAAqBC,IAAI,CAAG,CAA5B,CAA+B,CACpC,KAAMC,CAAAA,CAAC,CAAGD,IAAI,CAACE,QAAL,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,CAAAA,aAAT,CAAuBJ,SAAvB,CAAkC,CACvC,KAAMK,CAAAA,QAAQ,CAAG,GAAIC,iBAArB,CACAD,QAAQ,CAACN,MAAT,CAAgBC,SAAhB,EACA,MAAOK,CAAAA,QAAQ,CAACE,eAAT,EACR,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACO,QAASC,CAAAA,eAAT,CAAyBR,SAAzB,CAAoC,CACzC,KAAMT,CAAAA,GAAG,CAAGa,aAAa,CAACJ,SAAD,CAAzB,CACAS,MAAM,CAAClB,GAAD,CAAN,CAAYmB,eAAZ,GACA,MAAOnB,CAAAA,GACR,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACO,QAASoB,CAAAA,QAAT,CAAkBX,SAAlB,CAA6B,CAClC,KAAMT,CAAAA,GAAG,CAAGQ,MAAM,CAACC,SAAD,CAAlB,CACAS,MAAM,CAAClB,GAAD,CAAN,CAAYmB,eAAZ,GACA,MAAOnB,CAAAA,GACR,CAEM,KAAMqB,CAAAA,QAAQ,CAAGC,mBAAGC,QAApB,C","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"],"file":"jest.js"}