@dr.pogodin/react-utils 1.47.0-alpha.1 → 1.47.0-alpha.11
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/babel.config.js +1 -1
- package/babel.module.config.js +11 -0
- package/bin/build.js +8 -4
- package/bin/setup.js +2 -3
- package/build/development/client/getInj.js +57 -44
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +15 -21
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +2 -6
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +3 -183
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +1 -8
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +22 -50
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +83 -92
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +58 -62
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +8 -31
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/index.js +2 -9
- package/build/development/server/utils/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +9 -16
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +6 -13
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +4 -10
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +11 -18
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +6 -13
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +16 -22
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +6 -13
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +7 -14
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +15 -22
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +7 -14
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +12 -18
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +16 -23
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +10 -17
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +16 -130
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +18 -19
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +24 -28
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +19 -19
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +12 -17
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js +1 -7
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/components/selectors/index.js +3 -27
- package/build/development/shared/components/selectors/index.js.map +1 -1
- package/build/development/shared/utils/config.js +40 -21
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +3 -8
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js +12 -89
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +2 -9
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js +2 -8
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js +7 -32
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +24 -31
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/global.js +1 -7
- package/build/development/shared/utils/jest/global.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +20 -44
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +54 -46
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +22 -31
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +17 -16
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js +13 -11
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js +3 -3
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js +2 -2
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js +2 -6
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js +3 -3
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js +8 -8
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +24 -25
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +9 -11
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +9 -9
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/server/utils/index.js +2 -1
- package/build/production/server/utils/index.js.map +1 -1
- package/build/production/shared/components/Button/index.js +4 -4
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +4 -4
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +5 -5
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js +3 -3
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +7 -7
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js +2 -2
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +2 -2
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js +5 -5
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +2 -2
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js +4 -4
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +4 -4
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +4 -4
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js +3 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +4 -4
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/components/selectors/common.js +2 -2
- package/build/production/shared/components/selectors/common.js.map +1 -1
- package/build/production/shared/components/selectors/index.js +1 -1
- package/build/production/shared/components/selectors/index.js.map +1 -1
- package/build/production/shared/utils/config.js +8 -6
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/globalState.js +2 -2
- package/build/production/shared/utils/globalState.js.map +1 -1
- package/build/production/shared/utils/index.js +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy/buildInfo.js +3 -3
- package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/production/shared/utils/isomorphy/environment-check.js +3 -3
- package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/production/shared/utils/isomorphy/index.js +4 -4
- package/build/production/shared/utils/isomorphy/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js +14 -14
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/global.js +1 -1
- package/build/production/shared/utils/jest/global.js.map +1 -1
- package/build/production/shared/utils/jest/index.js +11 -11
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +11 -22
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +3 -3
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js +6 -6
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/types-code/client/getInj.d.ts +1 -2
- package/build/types-code/client/index.d.ts +1 -1
- package/build/types-code/index.d.ts +1 -7
- package/build/types-code/server/index.d.ts +6 -11
- package/build/types-code/server/utils/index.d.ts +1 -1
- package/build/types-code/shared/utils/config.d.ts +4 -2
- package/build/types-code/shared/utils/index.d.ts +2 -2
- package/build/types-code/shared/utils/splitComponent.d.ts +6 -4
- package/build/web/client/getInj.js +55 -44
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/client/index.js +15 -21
- package/build/web/client/index.js.map +1 -1
- package/build/web/client/init.js +2 -4
- package/build/web/client/init.js.map +1 -1
- package/build/web/index.js +1 -15
- package/build/web/index.js.map +1 -1
- package/build/web/server/index.js +12 -21
- package/build/web/server/index.js.map +1 -1
- package/build/web/server/renderer.js +34 -40
- package/build/web/server/renderer.js.map +1 -1
- package/build/web/server/server.js +14 -11
- package/build/web/server/server.js.map +1 -1
- package/build/web/server/utils/index.js +1 -1
- package/build/web/server/utils/index.js.map +1 -1
- package/build/web/shared/components/Button/index.js +1 -1
- package/build/web/shared/components/Button/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/index.js +1 -1
- package/build/web/shared/components/Checkbox/index.js.map +1 -1
- package/build/web/shared/components/Input/index.js +1 -1
- package/build/web/shared/components/Input/index.js.map +1 -1
- package/build/web/shared/components/Modal/index.js +3 -3
- package/build/web/shared/components/Modal/index.js.map +1 -1
- package/build/web/shared/components/PageLayout/index.js +1 -1
- package/build/web/shared/components/PageLayout/index.js.map +1 -1
- package/build/web/shared/components/TextArea/index.js +1 -1
- package/build/web/shared/components/TextArea/index.js.map +1 -1
- package/build/web/shared/components/Throbber/index.js +1 -1
- package/build/web/shared/components/Throbber/index.js.map +1 -1
- package/build/web/shared/components/WithTooltip/index.js +1 -1
- package/build/web/shared/components/WithTooltip/index.js.map +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +3 -0
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js +3 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js +4 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/Switch/index.js +2 -1
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/web/shared/utils/config.js +38 -14
- package/build/web/shared/utils/config.js.map +1 -1
- package/build/web/shared/utils/index.js +2 -2
- package/build/web/shared/utils/index.js.map +1 -1
- package/build/web/shared/utils/jest/E2eSsrEnv.js +3 -2
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/web/shared/utils/splitComponent.js +27 -20
- package/build/web/shared/utils/splitComponent.js.map +1 -1
- package/build/web/shared/utils/webpack.js +13 -7
- package/build/web/shared/utils/webpack.js.map +1 -1
- package/config/babel/node-ssr.js +12 -6
- package/config/babel/webpack.js +6 -1
- package/config/jest/default.js +8 -2
- package/config/jest/setup.js +8 -1
- package/config/webpack/app-base.js +23 -15
- package/config/webpack/app-development.js +2 -3
- package/config/webpack/lib-base.js +1 -2
- package/package.json +35 -25
- package/types.d.ts +1 -6
- package/node-entry.js +0 -15
- package/src/client/getInj.ts +0 -51
- package/src/client/index.tsx +0 -43
- package/src/client/init.ts +0 -52
- package/src/index.ts +0 -79
- package/src/server/Cache.ts +0 -61
- package/src/server/index.ts +0 -249
- package/src/server/renderer.tsx +0 -653
- package/src/server/server.ts +0 -332
- package/src/server/utils/errors.ts +0 -122
- package/src/server/utils/index.ts +0 -3
- package/src/shared/components/Button/index.tsx +0 -130
- package/src/shared/components/Button/style.scss +0 -54
- package/src/shared/components/Checkbox/index.tsx +0 -53
- package/src/shared/components/Checkbox/theme.scss +0 -63
- package/src/shared/components/GenericLink/index.tsx +0 -141
- package/src/shared/components/GenericLink/style.scss +0 -3
- package/src/shared/components/Input/index.tsx +0 -96
- package/src/shared/components/Input/theme.scss +0 -52
- package/src/shared/components/Link.tsx +0 -25
- package/src/shared/components/Modal/base-theme.scss +0 -38
- package/src/shared/components/Modal/index.tsx +0 -177
- package/src/shared/components/Modal/styles.scss +0 -3
- package/src/shared/components/NavLink.tsx +0 -18
- package/src/shared/components/PageLayout/base-theme.scss +0 -30
- package/src/shared/components/PageLayout/index.tsx +0 -51
- package/src/shared/components/TextArea/index.tsx +0 -139
- package/src/shared/components/TextArea/style.scss +0 -68
- package/src/shared/components/Throbber/index.tsx +0 -28
- package/src/shared/components/Throbber/theme.scss +0 -26
- package/src/shared/components/WithTooltip/Tooltip.tsx +0 -274
- package/src/shared/components/WithTooltip/default-theme.scss +0 -36
- package/src/shared/components/WithTooltip/index.tsx +0 -186
- package/src/shared/components/YouTubeVideo/base.scss +0 -15
- package/src/shared/components/YouTubeVideo/index.tsx +0 -73
- package/src/shared/components/YouTubeVideo/throbber.scss +0 -11
- package/src/shared/components/index.ts +0 -20
- package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +0 -124
- package/src/shared/components/selectors/CustomDropdown/Options/style.scss +0 -6
- package/src/shared/components/selectors/CustomDropdown/index.tsx +0 -146
- package/src/shared/components/selectors/CustomDropdown/theme.scss +0 -118
- package/src/shared/components/selectors/NativeDropdown/index.tsx +0 -90
- package/src/shared/components/selectors/NativeDropdown/theme.scss +0 -81
- package/src/shared/components/selectors/Switch/index.tsx +0 -74
- package/src/shared/components/selectors/Switch/theme.scss +0 -39
- package/src/shared/components/selectors/common.ts +0 -57
- package/src/shared/components/selectors/index.ts +0 -8
- package/src/shared/utils/config.ts +0 -28
- package/src/shared/utils/globalState.ts +0 -44
- package/src/shared/utils/index.ts +0 -45
- package/src/shared/utils/isomorphy/buildInfo.ts +0 -50
- package/src/shared/utils/isomorphy/environment-check.ts +0 -18
- package/src/shared/utils/isomorphy/index.ts +0 -36
- package/src/shared/utils/jest/E2eSsrEnv.ts +0 -305
- package/src/shared/utils/jest/global.ts +0 -17
- package/src/shared/utils/jest/index.ts +0 -215
- package/src/shared/utils/splitComponent.tsx +0 -275
- package/src/shared/utils/time.ts +0 -101
- package/src/shared/utils/webpack.ts +0 -74
- package/src/styles/_global/reset.css +0 -52
- package/src/styles/_mixins/fonts.scss +0 -40
- package/src/styles/_mixins/media.scss +0 -150
- package/src/styles/_mixins/typography.scss +0 -83
- package/src/styles/global.scss +0 -11
- package/src/styles/mixins.scss +0 -6
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Jest environment for end-to-end SSR and client-side testing. It relies on
|
|
3
|
-
* the standard react-utils mechanics to execute SSR of given scene, and also
|
|
4
|
-
* Webpack build of the code for client-side execution, it further exposes
|
|
5
|
-
* Jsdom environment for the client-side testing of the outcomes.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// BEWARE: The module is not imported into the JU module / the main assembly of
|
|
9
|
-
// the library, because doing so easily breaks stuff:
|
|
10
|
-
// 1) This module depends on Node-specific modules, which would make JU
|
|
11
|
-
// incompatible with JsDom if included into JU.
|
|
12
|
-
// 2) If this module is weakly imported from somewhere else in the lib,
|
|
13
|
-
// it seems to randomly break tests using it for a different reason,
|
|
14
|
-
// probably some sort of a require-loop, or some issues with weak
|
|
15
|
-
// require in that scenario.
|
|
16
|
-
|
|
17
|
-
// TODO: We need to add correct typing for environment options.
|
|
18
|
-
|
|
19
|
-
import path from 'node:path';
|
|
20
|
-
|
|
21
|
-
import type { Request, Response } from 'express';
|
|
22
|
-
|
|
23
|
-
import defaults from 'lodash/defaults';
|
|
24
|
-
import set from 'lodash/set';
|
|
25
|
-
|
|
26
|
-
import type { ReactNode } from 'react';
|
|
27
|
-
|
|
28
|
-
// As this environment is a part of the Jest testing utils,
|
|
29
|
-
// we assume development dependencies are available when it is used.
|
|
30
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
31
|
-
import register from '@babel/register/experimental-worker';
|
|
32
|
-
|
|
33
|
-
import JsdomEnv from 'jest-environment-jsdom';
|
|
34
|
-
import { Volume, createFsFromVolume } from 'memfs';
|
|
35
|
-
import webpack, { type Configuration } from 'webpack';
|
|
36
|
-
/* eslint-enable import/no-extraneous-dependencies */
|
|
37
|
-
|
|
38
|
-
import type {
|
|
39
|
-
EnvironmentContext,
|
|
40
|
-
JestEnvironmentConfig,
|
|
41
|
-
} from '@jest/environment';
|
|
42
|
-
|
|
43
|
-
import ssrFactory from 'server/renderer';
|
|
44
|
-
|
|
45
|
-
import { setBuildInfo } from '../isomorphy/buildInfo';
|
|
46
|
-
|
|
47
|
-
function noop() {
|
|
48
|
-
// NOOP
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default class E2eSsrEnv extends JsdomEnv {
|
|
52
|
-
pragmas: Record<string, string | string[]>;
|
|
53
|
-
|
|
54
|
-
ssrRequest: object;
|
|
55
|
-
|
|
56
|
-
rootDir: string;
|
|
57
|
-
|
|
58
|
-
testFolder: string;
|
|
59
|
-
|
|
60
|
-
withSsr: boolean;
|
|
61
|
-
|
|
62
|
-
webpackStats?: webpack.StatsCompilation;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Loads Webpack config, and exposes it to the environment via global
|
|
66
|
-
* webpackConfig object.
|
|
67
|
-
*/
|
|
68
|
-
private loadWebpackConfig() {
|
|
69
|
-
const optionsString = this.pragmas['webpack-config-options'] as string;
|
|
70
|
-
|
|
71
|
-
const options = (optionsString ? JSON.parse(optionsString) : {}) as
|
|
72
|
-
webpack.Configuration;
|
|
73
|
-
|
|
74
|
-
defaults(options, {
|
|
75
|
-
context: this.testFolder,
|
|
76
|
-
fs: this.global.webpackOutputFs,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const factoryPath = this.pragmas['webpack-config-factory'] as string;
|
|
80
|
-
// eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-require-imports
|
|
81
|
-
let factory = require(path.resolve(this.rootDir, factoryPath)) as
|
|
82
|
-
(((ops: Configuration) => Configuration) | {
|
|
83
|
-
default: (ops: Configuration) => Configuration;
|
|
84
|
-
});
|
|
85
|
-
factory = 'default' in factory ? factory.default : factory;
|
|
86
|
-
|
|
87
|
-
this.global.webpackConfig = factory(options);
|
|
88
|
-
|
|
89
|
-
const fs = this.global.webpackOutputFs;
|
|
90
|
-
let buildInfo = `${options.context}/.build-info`;
|
|
91
|
-
if (fs.existsSync(buildInfo)) {
|
|
92
|
-
buildInfo = fs.readFileSync(buildInfo, 'utf8') as string;
|
|
93
|
-
this.global.buildInfo = JSON.parse(buildInfo);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Executes Webpack build.
|
|
99
|
-
* @return {Promise}
|
|
100
|
-
*/
|
|
101
|
-
async runWebpack(): Promise<void> {
|
|
102
|
-
this.loadWebpackConfig();
|
|
103
|
-
|
|
104
|
-
if (!this.global.webpackConfig) throw Error('Failed to load Webpack config');
|
|
105
|
-
const compiler = webpack(this.global.webpackConfig);
|
|
106
|
-
if (!compiler) throw Error('Failed to construct Webpack compiler');
|
|
107
|
-
|
|
108
|
-
// TODO: The "as typeof compiler.outputFileSystem" piece below is
|
|
109
|
-
// a workaround for the Webpack regression:
|
|
110
|
-
// https://github.com/webpack/webpack/issues/18242
|
|
111
|
-
compiler.outputFileSystem = this.global.webpackOutputFs as
|
|
112
|
-
typeof compiler.outputFileSystem;
|
|
113
|
-
|
|
114
|
-
return new Promise<void>((done, fail) => {
|
|
115
|
-
compiler.run((err, stats) => {
|
|
116
|
-
if (err) fail(err);
|
|
117
|
-
if (stats?.hasErrors()) {
|
|
118
|
-
// eslint-disable-next-line no-console
|
|
119
|
-
console.error(stats.toJson().errors);
|
|
120
|
-
fail(Error('Webpack compilation failed'));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
this.global.webpackStats = stats?.toJson();
|
|
124
|
-
|
|
125
|
-
// Keeps reference to the raw Webpack stats object, which should be
|
|
126
|
-
// explicitly passed to the server-side renderer alongside the request,
|
|
127
|
-
// so that it can to pick up asset paths for different named chunks.
|
|
128
|
-
this.webpackStats = stats;
|
|
129
|
-
|
|
130
|
-
done();
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async runSsr(): Promise<void> {
|
|
136
|
-
const optionsString = this.pragmas['ssr-options'] as string;
|
|
137
|
-
const options = optionsString
|
|
138
|
-
? JSON.parse(optionsString) as Record<string, unknown>
|
|
139
|
-
: {};
|
|
140
|
-
|
|
141
|
-
// TODO: This is temporary to shortcut the logging added to SSR.
|
|
142
|
-
options.logger ??= {
|
|
143
|
-
debug: noop,
|
|
144
|
-
info: noop,
|
|
145
|
-
log: noop,
|
|
146
|
-
warn: noop,
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
options.buildInfo ??= this.global.buildInfo;
|
|
150
|
-
|
|
151
|
-
let cleanup: (() => void) | undefined;
|
|
152
|
-
|
|
153
|
-
if (options.entry) {
|
|
154
|
-
const p = path.resolve(this.testFolder, options.entry as string);
|
|
155
|
-
// TODO: This sure can be replaced by a dynamic import().
|
|
156
|
-
// eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-require-imports
|
|
157
|
-
const module = require(p) as NodeJS.Module;
|
|
158
|
-
if ('cleanup' in module) cleanup = module.cleanup as () => void;
|
|
159
|
-
|
|
160
|
-
const exportName = (options.entryExportName as string) || 'default';
|
|
161
|
-
if (exportName in module) {
|
|
162
|
-
options.Application = (
|
|
163
|
-
module as unknown as Record<string, unknown>
|
|
164
|
-
)[exportName] as ReactNode;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const renderer = ssrFactory(this.global.webpackConfig!, options);
|
|
169
|
-
let status = 200; // OK
|
|
170
|
-
const markup = await new Promise<string>((done, fail) => {
|
|
171
|
-
void renderer(
|
|
172
|
-
this.ssrRequest as Request,
|
|
173
|
-
|
|
174
|
-
// TODO: This will do for now, with the current implementation of
|
|
175
|
-
// the renderer, but it will require a rework once the renderer is
|
|
176
|
-
// updated to do streaming.
|
|
177
|
-
({
|
|
178
|
-
cookie: noop,
|
|
179
|
-
send: done,
|
|
180
|
-
set: noop,
|
|
181
|
-
status: (value: number) => {
|
|
182
|
-
status = value;
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
// This is how up-to-date Webpack stats are passed to the server in
|
|
186
|
-
// development mode, and we use this here always, instead of having
|
|
187
|
-
// to pass some information via filesystem.
|
|
188
|
-
locals: {
|
|
189
|
-
webpack: {
|
|
190
|
-
devMiddleware: {
|
|
191
|
-
stats: this.webpackStats,
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
} as unknown) as Response,
|
|
196
|
-
|
|
197
|
-
(error) => {
|
|
198
|
-
// TODO: Strictly speaking, that error as Error casting is not all
|
|
199
|
-
// correct, but it works, so no need to spend time on it right now.
|
|
200
|
-
if (error) fail(error as Error);
|
|
201
|
-
else done('');
|
|
202
|
-
},
|
|
203
|
-
);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
this.global.ssrMarkup = markup;
|
|
207
|
-
this.global.ssrOptions = options;
|
|
208
|
-
this.global.ssrStatus = status;
|
|
209
|
-
|
|
210
|
-
if (cleanup) cleanup();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
constructor(
|
|
214
|
-
config: JestEnvironmentConfig,
|
|
215
|
-
context: EnvironmentContext,
|
|
216
|
-
) {
|
|
217
|
-
const pragmas = context.docblockPragmas;
|
|
218
|
-
|
|
219
|
-
const requestString = pragmas['ssr-request'] as string;
|
|
220
|
-
const request = requestString
|
|
221
|
-
? JSON.parse(requestString) as Record<string, unknown>
|
|
222
|
-
: {};
|
|
223
|
-
|
|
224
|
-
request.url ??= '/';
|
|
225
|
-
request.csrfToken = noop;
|
|
226
|
-
|
|
227
|
-
// This ensures the initial JsDom URL matches the value we use for SSR.
|
|
228
|
-
set(
|
|
229
|
-
config.projectConfig,
|
|
230
|
-
'testEnvironmentOptions.url',
|
|
231
|
-
`http://localhost${request.url as string}`,
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
super(config, context);
|
|
235
|
-
|
|
236
|
-
this.global.dom = this.dom;
|
|
237
|
-
this.global.webpackOutputFs = createFsFromVolume(new Volume());
|
|
238
|
-
|
|
239
|
-
// Extracts necessary settings from config and context.
|
|
240
|
-
const { projectConfig } = config;
|
|
241
|
-
this.rootDir = projectConfig.rootDir;
|
|
242
|
-
this.testFolder = path.dirname(context.testPath);
|
|
243
|
-
this.withSsr = !pragmas['no-ssr'];
|
|
244
|
-
this.ssrRequest = request;
|
|
245
|
-
this.pragmas = pragmas;
|
|
246
|
-
|
|
247
|
-
// The usual "babel-jest" transformation setup does not apply to
|
|
248
|
-
// the environment code and imports from it, this workaround enables it.
|
|
249
|
-
const optionsString = this.pragmas['ssr-options'] as string;
|
|
250
|
-
const options = optionsString
|
|
251
|
-
? JSON.parse(optionsString) as Record<string, unknown>
|
|
252
|
-
: {};
|
|
253
|
-
let root;
|
|
254
|
-
switch (options.root) {
|
|
255
|
-
case 'TEST':
|
|
256
|
-
root = this.testFolder;
|
|
257
|
-
break;
|
|
258
|
-
default: root = process.cwd();
|
|
259
|
-
}
|
|
260
|
-
register({
|
|
261
|
-
envName: options.babelEnv as string,
|
|
262
|
-
extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],
|
|
263
|
-
root,
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
async setup(): Promise<void> {
|
|
268
|
-
await super.setup();
|
|
269
|
-
await this.runWebpack();
|
|
270
|
-
|
|
271
|
-
// NOTE: It is possible that the Webpack run above, and the SSR run below
|
|
272
|
-
// load different versions of the same module (CommonJS, and ES), and it may
|
|
273
|
-
// cause very confusing problems (e.g. see:
|
|
274
|
-
// https://github.com/birdofpreyru/react-utils/issues/413).
|
|
275
|
-
// It seems we can't reset the cache of ES modules, and Jest's module reset
|
|
276
|
-
// does not reset modules loaded in this enviroment module, and also only
|
|
277
|
-
// replacing entire cache object by and empty {} seems to help (in contrast
|
|
278
|
-
// to deleting all entries by their keys, as it is done within .teardown()
|
|
279
|
-
// method below). Thus, for now we do this as a hotfix, and we also reset
|
|
280
|
-
// build info to undefined, because ES module version not beeing reset
|
|
281
|
-
// triggers an error on the subsequent test using the environment.
|
|
282
|
-
// TODO: Look for a cleaner solution.
|
|
283
|
-
require.cache = {};
|
|
284
|
-
setBuildInfo(undefined, true);
|
|
285
|
-
|
|
286
|
-
if (this.withSsr) await this.runSsr();
|
|
287
|
-
this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
async teardown(): Promise<void> {
|
|
291
|
-
delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;
|
|
292
|
-
|
|
293
|
-
// Resets module cache and @babel/register. Effectively this ensures that
|
|
294
|
-
// the next time an instance of this environment is set up, all modules are
|
|
295
|
-
// transformed by Babel from scratch, thus taking into account the latest
|
|
296
|
-
// Babel config (which may change between different environment instances,
|
|
297
|
-
// which does not seem to be taken into account by Babel / Node caches
|
|
298
|
-
// automatically).
|
|
299
|
-
Object.keys(require.cache).forEach((key) => {
|
|
300
|
-
delete require.cache[key];
|
|
301
|
-
});
|
|
302
|
-
register.revert();
|
|
303
|
-
await super.teardown();
|
|
304
|
-
}
|
|
305
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { IFs } from 'memfs';
|
|
2
|
-
import type { Configuration, StatsCompilation } from 'webpack';
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
6
|
-
interface Window {
|
|
7
|
-
ssrMarkup: string | undefined;
|
|
8
|
-
ssrStatus: number | undefined;
|
|
9
|
-
webpackConfig: Configuration | undefined;
|
|
10
|
-
webpackOutputFs: IFs;
|
|
11
|
-
webpackStats?: StatsCompilation;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default function getGlobal(): Window {
|
|
16
|
-
return global as unknown as Window;
|
|
17
|
-
}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/* global jest, document */
|
|
2
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
AxiosRequestConfig,
|
|
6
|
-
AxiosResponse,
|
|
7
|
-
AxiosStatic,
|
|
8
|
-
InternalAxiosRequestConfig,
|
|
9
|
-
} from 'axios';
|
|
10
|
-
|
|
11
|
-
import mockdate from 'mockdate';
|
|
12
|
-
import { type ReactElement, type ReactNode, act } from 'react';
|
|
13
|
-
import { type Root, createRoot } from 'react-dom/client';
|
|
14
|
-
|
|
15
|
-
import { type RenderResult, render } from '@testing-library/react';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)
|
|
19
|
-
* from `react`.
|
|
20
|
-
*/
|
|
21
|
-
export { act };
|
|
22
|
-
|
|
23
|
-
export { default as getGlobal } from './global';
|
|
24
|
-
|
|
25
|
-
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
26
|
-
|
|
27
|
-
const originalProcessVersions = process.versions;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Tricks **react-utils** into thinking the test is running within client-side
|
|
31
|
-
* (browser) environment.
|
|
32
|
-
*/
|
|
33
|
-
export function mockClientSide(): void {
|
|
34
|
-
Object.defineProperty(process, 'versions', { value: undefined });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.
|
|
39
|
-
*/
|
|
40
|
-
export function unmockClientSide(): void {
|
|
41
|
-
Object.defineProperty(process, 'versions', {
|
|
42
|
-
value: originalProcessVersions,
|
|
43
|
-
writable: false,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Generates a mock UUID, or better said it determenistically transforms given
|
|
49
|
-
* `seed` number into a UUID-formatted string.
|
|
50
|
-
* @param {number} seed
|
|
51
|
-
* @return {string}
|
|
52
|
-
*/
|
|
53
|
-
export function getMockUuid(seed = 0): string {
|
|
54
|
-
const x = seed.toString(16).padStart(32, '0');
|
|
55
|
-
return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type AxiosRequestHandlerT = (
|
|
59
|
-
config: AxiosRequestConfig,
|
|
60
|
-
) => Partial<AxiosResponse> | null | undefined;
|
|
61
|
-
|
|
62
|
-
export function mockAxios(handlers: AxiosRequestHandlerT[]): AxiosStatic {
|
|
63
|
-
const axios: AxiosStatic = jest.requireActual('axios');
|
|
64
|
-
|
|
65
|
-
axios.defaults.adapter = async (
|
|
66
|
-
config: AxiosRequestConfig,
|
|
67
|
-
): Promise<AxiosResponse> => {
|
|
68
|
-
for (const handler of handlers) {
|
|
69
|
-
const res = handler(config);
|
|
70
|
-
if (res) {
|
|
71
|
-
return {
|
|
72
|
-
config: config as InternalAxiosRequestConfig,
|
|
73
|
-
data: null,
|
|
74
|
-
headers: {},
|
|
75
|
-
status: 200,
|
|
76
|
-
statusText: 'OK',
|
|
77
|
-
...res,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Fallback to the regular network request.
|
|
83
|
-
let res: AxiosResponse;
|
|
84
|
-
try {
|
|
85
|
-
res = await axios({ ...config, adapter: ['xhr', 'http', 'fetch'] });
|
|
86
|
-
// eslint-disable-next-line no-console
|
|
87
|
-
console.warn(
|
|
88
|
-
'Network request has not been mocked for a test.\n\nConfig:\n',
|
|
89
|
-
config,
|
|
90
|
-
'\n\nResult:\n',
|
|
91
|
-
JSON.stringify(res, null, 2),
|
|
92
|
-
);
|
|
93
|
-
} catch (e) {
|
|
94
|
-
// eslint-disable-next-line no-console
|
|
95
|
-
console.warn(
|
|
96
|
-
'Network request has not been mocked for a test, and failed.\n\nConfig:\n',
|
|
97
|
-
config,
|
|
98
|
-
'\n\nError\n',
|
|
99
|
-
JSON.stringify(e, null, 2),
|
|
100
|
-
);
|
|
101
|
-
throw e;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return res;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
return axios;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Advances mock timers, and mock date by the specified time.
|
|
112
|
-
* @param {number} time Time step [ms].
|
|
113
|
-
* @returns {Promise} Wait for this to "jump after" any async code which should
|
|
114
|
-
* be executed because of the mock time movement.
|
|
115
|
-
*/
|
|
116
|
-
export async function mockTimer(time: number): Promise<void> {
|
|
117
|
-
mockdate.set(time + Date.now());
|
|
118
|
-
await jest.advanceTimersByTimeAsync(time);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export type MountedSceneT = HTMLElement & {
|
|
122
|
-
destroy: () => void;
|
|
123
|
-
snapshot: () => void;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Mounts `scene` to the DOM, and returns the root scene element.
|
|
128
|
-
* @param scene
|
|
129
|
-
* @return Created container DOM element with destroy() function
|
|
130
|
-
* attached.
|
|
131
|
-
*/
|
|
132
|
-
export function mount(scene: ReactNode): MountedSceneT {
|
|
133
|
-
let root: Root;
|
|
134
|
-
const element = document.createElement('div');
|
|
135
|
-
document.body.appendChild(element);
|
|
136
|
-
|
|
137
|
-
const res: MountedSceneT = (element as unknown) as MountedSceneT;
|
|
138
|
-
res.destroy = () => {
|
|
139
|
-
// NOTE: As it seems @testing-library may reset this flag to false
|
|
140
|
-
// when it is simulating user events.
|
|
141
|
-
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
142
|
-
|
|
143
|
-
act(() => {
|
|
144
|
-
root.unmount();
|
|
145
|
-
});
|
|
146
|
-
res.remove();
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
res.snapshot = () => {
|
|
150
|
-
expect(res).toMatchSnapshot();
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
// NOTE: As it seems @testing-library may reset this flag to false
|
|
154
|
-
// when it is simulating user events.
|
|
155
|
-
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
156
|
-
|
|
157
|
-
act(() => {
|
|
158
|
-
root = createRoot(res);
|
|
159
|
-
root.render(scene);
|
|
160
|
-
});
|
|
161
|
-
return res;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// NOTE: If in future we have additional options here, they should be distributed
|
|
165
|
-
// across two objects, depending whether they are applicable to the sync, or async
|
|
166
|
-
// versions of snapshot(), or both.
|
|
167
|
-
type AsyncSnapshotOptionsT = {
|
|
168
|
-
await?: Promise<void>;
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
export function snapshot(element: ReactElement): RenderResult;
|
|
172
|
-
|
|
173
|
-
export async function snapshot(
|
|
174
|
-
element: ReactElement,
|
|
175
|
-
options: AsyncSnapshotOptionsT,
|
|
176
|
-
): Promise<RenderResult>;
|
|
177
|
-
|
|
178
|
-
export function snapshot(
|
|
179
|
-
element: React.ReactElement,
|
|
180
|
-
options?: AsyncSnapshotOptionsT,
|
|
181
|
-
): Promise<RenderResult> | RenderResult {
|
|
182
|
-
let res: RenderResult | undefined;
|
|
183
|
-
|
|
184
|
-
// TODO: Just adding async to the actor function breaks stuff, as it makes
|
|
185
|
-
// act() asynchronous no matter the `options.await` value, thus breaking all
|
|
186
|
-
// calls that do not await for snapshot() result... thus... perhaps we need
|
|
187
|
-
// to have a more complex typing to ensure it all works as intended in all
|
|
188
|
-
// cases, and while being correctly enforced by TypeScript.
|
|
189
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
190
|
-
const promise = act(() => {
|
|
191
|
-
res = render(element);
|
|
192
|
-
return options?.await;
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
if (res === undefined) throw Error('Render failed');
|
|
196
|
-
if (options?.await) {
|
|
197
|
-
// BEWARE: Although `promise` is thenable (i.e. it has .then() method),
|
|
198
|
-
// it is not an instance of proper Promise class, and returning it directly
|
|
199
|
-
// breaks some async logic in Jest test or React test functions... thus, we
|
|
200
|
-
// wrap it into Promise instance here.
|
|
201
|
-
return new Promise((resolve) => {
|
|
202
|
-
void promise.then(() => {
|
|
203
|
-
// TODO: These lines are the same as the lines below for sync variant of
|
|
204
|
-
// the function. We should split and reuse them in both places.
|
|
205
|
-
const nodes = res!.asFragment().childNodes;
|
|
206
|
-
expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();
|
|
207
|
-
resolve(res!);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const nodes = res.asFragment().childNodes;
|
|
213
|
-
expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();
|
|
214
|
-
return res;
|
|
215
|
-
}
|