@dr.pogodin/react-utils 1.17.2 → 1.17.3

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.
@@ -87,13 +87,25 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
87
87
 
88
88
  async runSsr() {
89
89
  let options = this.pragmas['ssr-options'];
90
- options = options ? JSON.parse(options) : {}; // Note: This enables Babel transformation for the code dynamically loaded
90
+ options = options ? JSON.parse(options) : {};
91
+ let root;
92
+
93
+ switch (options.root) {
94
+ case 'TEST':
95
+ root = this.testFolder;
96
+ break;
97
+
98
+ default:
99
+ root = process.cwd();
100
+ } // Note: This enables Babel transformation for the code dynamically loaded
91
101
  // below, as the usual Jest Babel setup does not seem to apply to
92
102
  // the environment code, and imports from it.
93
103
 
104
+
94
105
  (0, _register.default)({
95
106
  envName: options.babelEnv,
96
- extensions: ['.js', '.jsx', '.svg']
107
+ extensions: ['.js', '.jsx', '.svg'],
108
+ root
97
109
  });
98
110
  if (!options.buildInfo) options.buildInfo = this.global.buildInfo;
99
111
 
@@ -1 +1 @@
1
- {"version":3,"file":"E2eSsrEnv.js","names":["E2eSsrEnv","JsdomEnv","loadWebpackConfig","options","pragmas","JSON","parse","context","testFolder","dontEmitBuildInfo","factory","require","path","resolve","rootDir","global","webpackConfig","buildInfo","runWebpack","compiler","fs","Volume","outputFileSystem","Promise","done","fail","run","err","stats","webpackOutputFs","webpackStats","toJson","runSsr","envName","babelEnv","extensions","entry","p","Application","entryExportName","renderer","markup","ssrRequest","send","set","noop","locals","webpack","devMiddleware","error","ssrMarkup","ssrOptions","constructor","config","docblockPragmas","request","url","projectConfig","dom","dirname","testPath","withSsr","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","register","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 dontEmitBuildInfo: true,\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 this.global.buildInfo = factory.buildInfo;\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 const fs = createFsFromVolume(new Volume());\n compiler.outputFileSystem = fs;\n return new Promise((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n this.global.webpackOutputFs = fs;\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 // 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 });\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 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 send: done,\n set: noop,\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 }\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\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\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,sBAASA,OAAT,EAAkB;MAChBI,OAAO,EAAE,KAAKC,UADE;MAEhBC,iBAAiB,EAAE;IAFH,CAAlB;IAKA,IAAIC,OAAO,GAAG,KAAKN,OAAL,CAAa,wBAAb,KAA0C,EAAxD;IACAM,OAAO,GAAGC,OAAO,CAACC,cAAKC,OAAL,CAAa,KAAKC,OAAlB,EAA2BJ,OAA3B,CAAD,CAAjB;IACA,KAAKK,MAAL,CAAYC,aAAZ,GAA4BN,OAAO,CAACP,OAAD,CAAnC;IACA,KAAKY,MAAL,CAAYE,SAAZ,GAAwBP,OAAO,CAACO,SAAhC;EACD;EAED;AACF;AACA;AACA;;;EACkB,MAAVC,UAAU,GAAG;IACjB,KAAKhB,iBAAL;IAEA,MAAMiB,QAAQ,GAAG,sBAAQ,KAAKJ,MAAL,CAAYC,aAApB,CAAjB;IACA,MAAMI,EAAE,GAAG,+BAAmB,IAAIC,aAAJ,EAAnB,CAAX;IACAF,QAAQ,CAACG,gBAAT,GAA4BF,EAA5B;IACA,OAAO,IAAIG,OAAJ,CAAY,CAACC,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B;IACA,KAAKnD,OAAL,GAAeA,OAAf;EACD;;EAEU,MAAL0D,KAAK,GAAG;IACZ,MAAM,MAAMA,KAAN,EAAN;IACA,MAAM,KAAK5C,UAAL,EAAN;IACA,IAAI,KAAK2C,OAAT,EAAkB,MAAM,KAAK7B,MAAL,EAAN;IAClB,KAAKjB,MAAL,CAAYgD,6BAAZ,GAA4C,IAA5C;EACD;;EAEa,MAARC,QAAQ,GAAG;IACf,OAAO,KAAKjD,MAAL,CAAYgD,6BAAnB,CADe,CAGf;IACA;IACA;IACA;IACA;IACA;;IACAE,MAAM,CAACC,IAAP,CAAYvD,OAAO,CAACwD,KAApB,EAA2BC,OAA3B,CAAoCC,GAAD,IAAS;MAC1C,OAAO1D,OAAO,CAACwD,KAAR,CAAcE,GAAd,CAAP;IACD,CAFD;;IAGAC,kBAASC,MAAT;;IACA,MAAMP,QAAN;EACD;;AAlJ6C"}
1
+ {"version":3,"file":"E2eSsrEnv.js","names":["E2eSsrEnv","JsdomEnv","loadWebpackConfig","options","pragmas","JSON","parse","context","testFolder","dontEmitBuildInfo","factory","require","path","resolve","rootDir","global","webpackConfig","buildInfo","runWebpack","compiler","fs","Volume","outputFileSystem","Promise","done","fail","run","err","stats","webpackOutputFs","webpackStats","toJson","runSsr","root","process","cwd","envName","babelEnv","extensions","entry","p","Application","entryExportName","renderer","markup","ssrRequest","send","set","noop","locals","webpack","devMiddleware","error","ssrMarkup","ssrOptions","constructor","config","docblockPragmas","request","url","projectConfig","dom","dirname","testPath","withSsr","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","register","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 dontEmitBuildInfo: true,\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 this.global.buildInfo = factory.buildInfo;\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 const fs = createFsFromVolume(new Volume());\n compiler.outputFileSystem = fs;\n return new Promise((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n this.global.webpackOutputFs = fs;\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 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 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 send: done,\n set: noop,\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 }\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\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\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,sBAASA,OAAT,EAAkB;MAChBI,OAAO,EAAE,KAAKC,UADE;MAEhBC,iBAAiB,EAAE;IAFH,CAAlB;IAKA,IAAIC,OAAO,GAAG,KAAKN,OAAL,CAAa,wBAAb,KAA0C,EAAxD;IACAM,OAAO,GAAGC,OAAO,CAACC,cAAKC,OAAL,CAAa,KAAKC,OAAlB,EAA2BJ,OAA3B,CAAD,CAAjB;IACA,KAAKK,MAAL,CAAYC,aAAZ,GAA4BN,OAAO,CAACP,OAAD,CAAnC;IACA,KAAKY,MAAL,CAAYE,SAAZ,GAAwBP,OAAO,CAACO,SAAhC;EACD;EAED;AACF;AACA;AACA;;;EACkB,MAAVC,UAAU,GAAG;IACjB,KAAKhB,iBAAL;IAEA,MAAMiB,QAAQ,GAAG,sBAAQ,KAAKJ,MAAL,CAAYC,aAApB,CAAjB;IACA,MAAMI,EAAE,GAAG,+BAAmB,IAAIC,aAAJ,EAAnB,CAAX;IACAF,QAAQ,CAACG,gBAAT,GAA4BF,EAA5B;IACA,OAAO,IAAIG,OAAJ,CAAY,CAACC,IAAD,EAAOC,IAAP,KAAgB;MACjCN,QAAQ,C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AkBI,cAAKkD,OAAL,CAAavD,OAAO,CAACwD,QAArB,CAAlB;IACA,KAAKC,OAAL,GAAe,CAAC5D,OAAO,CAAC,QAAD,CAAvB;IACA,KAAKyC,UAAL,GAAkBa,OAAlB;IACA,KAAKtD,OAAL,GAAeA,OAAf;EACD;;EAEU,MAAL6D,KAAK,GAAG;IACZ,MAAM,MAAMA,KAAN,EAAN;IACA,MAAM,KAAK/C,UAAL,EAAN;IACA,IAAI,KAAK8C,OAAT,EAAkB,MAAM,KAAKhC,MAAL,EAAN;IAClB,KAAKjB,MAAL,CAAYmD,6BAAZ,GAA4C,IAA5C;EACD;;EAEa,MAARC,QAAQ,GAAG;IACf,OAAO,KAAKpD,MAAL,CAAYmD,6BAAnB,CADe,CAGf;IACA;IACA;IACA;IACA;IACA;;IACAE,MAAM,CAACC,IAAP,CAAY1D,OAAO,CAAC2D,KAApB,EAA2BC,OAA3B,CAAoCC,GAAD,IAAS;MAC1C,OAAO7D,OAAO,CAAC2D,KAAR,CAAcE,GAAd,CAAP;IACD,CAFD;;IAGAC,kBAASC,MAAT;;IACA,MAAMP,QAAN;EACD;;AAzJ6C"}
@@ -22,10 +22,10 @@
22
22
  */async runWebpack(){this.loadWebpackConfig();const compiler=(0,_webpack.default)(this.global.webpackConfig);const fs=(0,_memfs.createFsFromVolume)(new _memfs.Volume);compiler.outputFileSystem=fs;return new Promise((done,fail)=>{compiler.run((err,stats)=>{if(err)fail(err);this.global.webpackOutputFs=fs;this.global.webpackStats=stats.toJson();// Keeps reference to the raw Webpack stats object, which should be
23
23
  // explicitly passed to the server-side renderer alongside the request,
24
24
  // so that it can to pick up asset paths for different named chunks.
25
- this.webpackStats=stats;done()})})}async runSsr(){let options=this.pragmas["ssr-options"];options=options?JSON.parse(options):{};// Note: This enables Babel transformation for the code dynamically loaded
25
+ this.webpackStats=stats;done()})})}async runSsr(){let options=this.pragmas["ssr-options"];options=options?JSON.parse(options):{};let root;switch(options.root){case"TEST":root=this.testFolder;break;default:root=process.cwd();}// Note: This enables Babel transformation for the code dynamically loaded
26
26
  // below, as the usual Jest Babel setup does not seem to apply to
27
27
  // the environment code, and imports from it.
28
- (0,_register.default)({envName:options.babelEnv,extensions:[".js",".jsx",".svg"]});if(!options.buildInfo)options.buildInfo=this.global.buildInfo;if(options.entry){const p=_path.default.resolve(this.testFolder,options.entry);options.Application=require(p)[options.entryExportName||"default"]}const renderer=(0,_renderer.default)(this.global.webpackConfig,options);const markup=await new Promise((done,fail)=>{renderer(this.ssrRequest,// TODO: This will do for now, with the current implementation of
28
+ (0,_register.default)({envName:options.babelEnv,extensions:[".js",".jsx",".svg"],root});if(!options.buildInfo)options.buildInfo=this.global.buildInfo;if(options.entry){const p=_path.default.resolve(this.testFolder,options.entry);options.Application=require(p)[options.entryExportName||"default"]}const renderer=(0,_renderer.default)(this.global.webpackConfig,options);const markup=await new Promise((done,fail)=>{renderer(this.ssrRequest,// TODO: This will do for now, with the current implementation of
29
29
  // the renderer, but it will require a rework once the renderer is
30
30
  // updated to do streaming.
31
31
  {send:done,set:_lodash.noop,// This is how up-to-date Webpack stats are passed to the server in
@@ -1 +1 @@
1
- {"version":3,"file":"E2eSsrEnv.js","names":["E2eSsrEnv","JsdomEnv","loadWebpackConfig","options","pragmas","JSON","parse","context","testFolder","dontEmitBuildInfo","factory","require","path","resolve","rootDir","global","webpackConfig","buildInfo","runWebpack","compiler","fs","Volume","outputFileSystem","Promise","done","fail","run","err","stats","webpackOutputFs","webpackStats","toJson","runSsr","envName","babelEnv","extensions","entry","p","Application","entryExportName","renderer","markup","ssrRequest","send","set","noop","locals","webpack","devMiddleware","error","ssrMarkup","ssrOptions","constructor","config","docblockPragmas","request","url","projectConfig","dom","dirname","testPath","withSsr","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","register","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 dontEmitBuildInfo: true,\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 this.global.buildInfo = factory.buildInfo;\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 const fs = createFsFromVolume(new Volume());\n compiler.outputFileSystem = fs;\n return new Promise((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n this.global.webpackOutputFs = fs;\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 // 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 });\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 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 send: done,\n set: noop,\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 }\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\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\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":"gLAiBA,kDACA,0EAEA,8BAKA,iEACA,oFACA,4BACA,wDA5BA;AACA;AACA;AACA;AACA;AACA,G,CACA,8D,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA;AACA;AACA,sD,CAKA,qDAEe,KAAMA,CAAAA,SAAN,QAAwBC,8BAAS,CAC9C;AACF;AACA;AACA,KACEC,iBAAiB,EAAG,CAClB,GAAIC,CAAAA,OAAO,CAAG,KAAKC,OAAL,CAAa,wBAAb,CAAd,CACAD,OAAO,CAAGA,OAAO,CAAGE,IAAI,CAACC,KAAL,CAAWH,OAAX,CAAH,CAAyB,EAA1C,CACA,qBAASA,OAAT,CAAkB,CAChBI,OAAO,CAAE,KAAKC,UADE,CAEhBC,iBAAiB,CAAE,IAFH,CAAlB,EAKA,GAAIC,CAAAA,OAAO,CAAG,KAAKN,OAAL,CAAa,wBAAb,GAA0C,EAAxD,CACAM,OAAO,CAAGC,OAAO,CAACC,cAAKC,OAAL,CAAa,KAAKC,OAAlB,CAA2BJ,OAA3B,CAAD,CAAjB,CACA,KAAKK,MAAL,CAAYC,aAAZ,CAA4BN,OAAO,CAACP,OAAD,CAAnC,CACA,KAAKY,MAAL,CAAYE,SAAZ,CAAwBP,OAAO,CAACO,SACjC,CAED;AACF;AACA;AACA,KACkB,KAAVC,CAAAA,UAAU,EAAG,CACjB,KAAKhB,iBAAL,GAEA,KAAMiB,CAAAA,QAAQ,CAAG,qBAAQ,KAAKJ,MAAL,CAAYC,aAApB,CAAjB,CACA,KAAMI,CAAAA,EAAE,CAAG,8BAAmB,GAAIC,cAAvB,CAAX,CACAF,QAAQ,CAACG,gBAAT,CAA4BF,EAA5B,C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vB,CACA,KAAKsC,UAAL,CAAkBa,OAAlB,CACA,KAAKnD,OAAL,CAAeA,OAChB,CAEU,KAAL0D,CAAAA,KAAK,EAAG,CACZ,KAAM,OAAMA,KAAN,EAAN,CACA,KAAM,MAAK5C,UAAL,EAAN,CACA,GAAI,KAAK2C,OAAT,CAAkB,KAAM,MAAK7B,MAAL,EAAN,CAClB,KAAKjB,MAAL,CAAYgD,6BAAZ,CAA4C,IAC7C,CAEa,KAARC,CAAAA,QAAQ,EAAG,CACf,MAAO,MAAKjD,MAAL,CAAYgD,6BAAnB,CAEA;AACA;AACA;AACA;AACA;AACA;AACAE,MAAM,CAACC,IAAP,CAAYvD,OAAO,CAACwD,KAApB,EAA2BC,OAA3B,CAAoCC,GAAD,EAAS,CAC1C,MAAO1D,CAAAA,OAAO,CAACwD,KAAR,CAAcE,GAAd,CACR,CAFD,EAGAC,kBAASC,MAAT,GACA,MAAMP,QAAN,EACD,CAlJ6C,C"}
1
+ {"version":3,"file":"E2eSsrEnv.js","names":["E2eSsrEnv","JsdomEnv","loadWebpackConfig","options","pragmas","JSON","parse","context","testFolder","dontEmitBuildInfo","factory","require","path","resolve","rootDir","global","webpackConfig","buildInfo","runWebpack","compiler","fs","Volume","outputFileSystem","Promise","done","fail","run","err","stats","webpackOutputFs","webpackStats","toJson","runSsr","root","process","cwd","envName","babelEnv","extensions","entry","p","Application","entryExportName","renderer","markup","ssrRequest","send","set","noop","locals","webpack","devMiddleware","error","ssrMarkup","ssrOptions","constructor","config","docblockPragmas","request","url","projectConfig","dom","dirname","testPath","withSsr","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","register","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 dontEmitBuildInfo: true,\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 this.global.buildInfo = factory.buildInfo;\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 const fs = createFsFromVolume(new Volume());\n compiler.outputFileSystem = fs;\n return new Promise((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n this.global.webpackOutputFs = fs;\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 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 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 send: done,\n set: noop,\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 }\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\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\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":"gLAiBA,kDACA,0EAEA,8BAKA,iEACA,oFACA,4BACA,wDA5BA;AACA;AACA;AACA;AACA;AACA,G,CACA,8D,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA;AACA;AACA,sD,CAKA,qDAEe,KAAMA,CAAAA,SAAN,QAAwBC,8BAAS,CAC9C;AACF;AACA;AACA,KACEC,iBAAiB,EAAG,CAClB,GAAIC,CAAAA,OAAO,CAAG,KAAKC,OAAL,CAAa,wBAAb,CAAd,CACAD,OAAO,CAAGA,OAAO,CAAGE,IAAI,CAACC,KAAL,CAAWH,OAAX,CAAH,CAAyB,EAA1C,CACA,qBAASA,OAAT,CAAkB,CAChBI,OAAO,CAAE,KAAKC,UADE,CAEhBC,iBAAiB,CAAE,IAFH,CAAlB,EAKA,GAAIC,CAAAA,OAAO,CAAG,KAAKN,OAAL,CAAa,wBAAb,GAA0C,EAAxD,CACAM,OAAO,CAAGC,OAAO,CAACC,cAAKC,OAAL,CAAa,KAAKC,OAAlB,CAA2BJ,OAA3B,CAAD,CAAjB,CACA,KAAKK,MAAL,CAAYC,aAAZ,CAA4BN,OAAO,CAACP,OAAD,CAAnC,CACA,KAAKY,MAAL,CAAYE,SAAZ,CAAwBP,OAAO,CAACO,SACjC,CAED;AACF;AACA;AACA,KACkB,KAAVC,CAAAA,UAAU,EAAG,CACjB,KAAKhB,iBAAL,GAEA,KAAMiB,CAAAA,QAAQ,CAAG,qBAAQ,KAAKJ,MAAL,CAAYC,aAApB,CAAjB,CACA,KAAMI,CAAAA,EAAE,CAAG,8BAAmB,GAAIC,cAAvB,CAAX,CACAF,QAAQ,CAACG,gBAAT,CAA4BF,EAA5B,CACA,MAAO,IAAIG,CAAAA,OAA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AAL,CAAe8C,aAAa,CAAC9C,OAA7B,CACA,KAAKN,UAAL,CAAkBI,cAAKkD,OAAL,CAAavD,OAAO,CAACwD,QAArB,CAAlB,CACA,KAAKC,OAAL,CAAe,CAAC5D,OAAO,CAAC,QAAD,CAAvB,CACA,KAAKyC,UAAL,CAAkBa,OAAlB,CACA,KAAKtD,OAAL,CAAeA,OAChB,CAEU,KAAL6D,CAAAA,KAAK,EAAG,CACZ,KAAM,OAAMA,KAAN,EAAN,CACA,KAAM,MAAK/C,UAAL,EAAN,CACA,GAAI,KAAK8C,OAAT,CAAkB,KAAM,MAAKhC,MAAL,EAAN,CAClB,KAAKjB,MAAL,CAAYmD,6BAAZ,CAA4C,IAC7C,CAEa,KAARC,CAAAA,QAAQ,EAAG,CACf,MAAO,MAAKpD,MAAL,CAAYmD,6BAAnB,CAEA;AACA;AACA;AACA;AACA;AACA;AACAE,MAAM,CAACC,IAAP,CAAY1D,OAAO,CAAC2D,KAApB,EAA2BC,OAA3B,CAAoCC,GAAD,EAAS,CAC1C,MAAO7D,CAAAA,OAAO,CAAC2D,KAAR,CAAcE,GAAd,CACR,CAFD,EAGAC,kBAASC,MAAT,GACA,MAAMP,QAAN,EACD,CAzJ6C,C"}
@@ -10,6 +10,7 @@
10
10
  "rules": {
11
11
  "global-require": 0,
12
12
  "import/no-dynamic-require": 0,
13
+ "import/no-extraneous-dependencies": 0,
13
14
  "no-console": 0
14
15
  }
15
16
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.17.2",
2
+ "version": "1.17.3",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -55,11 +55,11 @@
55
55
  "@dr.pogodin/babel-plugin-transform-assets": "^1.1.1",
56
56
  "@dr.pogodin/babel-preset-svgr": "^1.4.0",
57
57
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
58
- "autoprefixer": "^10.4.5",
58
+ "autoprefixer": "^10.4.7",
59
59
  "babel-jest": "^28.0.3",
60
60
  "babel-loader": "^8.2.5",
61
61
  "babel-plugin-module-resolver": "^4.1.0",
62
- "core-js": "^3.22.3",
62
+ "core-js": "^3.22.4",
63
63
  "css-loader": "^6.7.1",
64
64
  "css-minimizer-webpack-plugin": "^3.4.1",
65
65
  "eslint": "^8.14.0",
@@ -88,7 +88,7 @@
88
88
  "sass": "^1.51.0",
89
89
  "sass-loader": "^12.6.0",
90
90
  "sitemap": "^7.1.1",
91
- "stylelint": "^14.8.1",
91
+ "stylelint": "^14.8.2",
92
92
  "stylelint-config-standard-scss": "^3.0.0",
93
93
  "supertest": "^6.2.3",
94
94
  "webpack": "^5.72.0",