@dr.pogodin/react-utils 1.8.5 → 1.10.0

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 (142) hide show
  1. package/bin/build.js +0 -129
  2. package/bin/release.sh +1 -1
  3. package/bin/setup.js +0 -44
  4. package/build/development/client/index.js +0 -6
  5. package/build/development/client/index.js.map +1 -1
  6. package/build/development/client/init.js +3 -1
  7. package/build/development/client/init.js.map +1 -1
  8. package/build/development/index.js +14 -19
  9. package/build/development/index.js.map +1 -1
  10. package/build/development/server/index.js +1 -51
  11. package/build/development/server/index.js.map +1 -1
  12. package/build/development/server/renderer.js +10 -4
  13. package/build/development/server/renderer.js.map +1 -1
  14. package/build/development/server/server.js +1 -1
  15. package/build/development/server/utils/errors.js +3 -3
  16. package/build/development/shared/components/Button/index.js +7 -42
  17. package/build/development/shared/components/Button/index.js.map +1 -1
  18. package/build/development/shared/components/Checkbox/index.js +7 -14
  19. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  20. package/build/development/shared/components/CodeSplit/index.js +9 -66
  21. package/build/development/shared/components/CodeSplit/index.js.map +1 -1
  22. package/build/development/shared/components/Dropdown/index.js +9 -35
  23. package/build/development/shared/components/Dropdown/index.js.map +1 -1
  24. package/build/development/shared/components/GenericLink/index.js +1 -23
  25. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  26. package/build/development/shared/components/Input/index.js +6 -19
  27. package/build/development/shared/components/Input/index.js.map +1 -1
  28. package/build/development/shared/components/MetaTags.js +0 -21
  29. package/build/development/shared/components/MetaTags.js.map +1 -1
  30. package/build/development/shared/components/Modal/index.js +5 -39
  31. package/build/development/shared/components/Modal/index.js.map +1 -1
  32. package/build/development/shared/components/NavLink.js +0 -10
  33. package/build/development/shared/components/NavLink.js.map +1 -1
  34. package/build/development/shared/components/PageLayout/index.js +6 -31
  35. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  36. package/build/development/shared/components/ScalableRect/index.js +2 -8
  37. package/build/development/shared/components/ScalableRect/index.js.map +1 -1
  38. package/build/development/shared/components/Throbber/index.js +10 -22
  39. package/build/development/shared/components/Throbber/index.js.map +1 -1
  40. package/build/development/shared/components/WithTooltip/index.js +7 -13
  41. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  42. package/build/development/shared/components/YouTubeVideo/index.js +9 -15
  43. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  44. package/build/development/shared/components/index.js +18 -18
  45. package/build/development/shared/components/index.js.map +1 -1
  46. package/build/development/shared/utils/config.js +0 -22
  47. package/build/development/shared/utils/config.js.map +1 -1
  48. package/build/development/shared/utils/index.js +11 -29
  49. package/build/development/shared/utils/index.js.map +1 -1
  50. package/build/development/shared/utils/isomorphy.js +3 -44
  51. package/build/development/shared/utils/isomorphy.js.map +1 -1
  52. package/build/development/shared/utils/jest.js +12 -126
  53. package/build/development/shared/utils/jest.js.map +1 -1
  54. package/build/development/shared/utils/url.js +1 -1
  55. package/build/development/shared/utils/webpack.js +0 -4
  56. package/build/development/shared/utils/webpack.js.map +1 -1
  57. package/build/development/style.css +149 -149
  58. package/build/development/web.bundle.js +33 -33
  59. package/build/production/client/index.js +0 -6
  60. package/build/production/client/index.js.map +1 -1
  61. package/build/production/client/init.js +2 -1
  62. package/build/production/client/init.js.map +1 -1
  63. package/build/production/index.js +2 -11
  64. package/build/production/index.js.map +1 -1
  65. package/build/production/server/index.js +1 -49
  66. package/build/production/server/index.js.map +1 -1
  67. package/build/production/server/renderer.js +2 -2
  68. package/build/production/server/renderer.js.map +1 -1
  69. package/build/production/server/server.js +1 -1
  70. package/build/production/server/utils/errors.js +1 -1
  71. package/build/production/shared/components/Button/index.js +2 -37
  72. package/build/production/shared/components/Button/index.js.map +1 -1
  73. package/build/production/shared/components/Checkbox/index.js +2 -9
  74. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  75. package/build/production/shared/components/CodeSplit/index.js +2 -65
  76. package/build/production/shared/components/CodeSplit/index.js.map +1 -1
  77. package/build/production/shared/components/Dropdown/index.js +2 -24
  78. package/build/production/shared/components/Dropdown/index.js.map +1 -1
  79. package/build/production/shared/components/GenericLink/index.js +1 -23
  80. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  81. package/build/production/shared/components/Input/index.js +2 -13
  82. package/build/production/shared/components/Input/index.js.map +1 -1
  83. package/build/production/shared/components/MetaTags.js +0 -21
  84. package/build/production/shared/components/MetaTags.js.map +1 -1
  85. package/build/production/shared/components/Modal/index.js +2 -34
  86. package/build/production/shared/components/Modal/index.js.map +1 -1
  87. package/build/production/shared/components/NavLink.js +1 -10
  88. package/build/production/shared/components/NavLink.js.map +1 -1
  89. package/build/production/shared/components/PageLayout/index.js +2 -25
  90. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  91. package/build/production/shared/components/ScalableRect/index.js +1 -7
  92. package/build/production/shared/components/ScalableRect/index.js.map +1 -1
  93. package/build/production/shared/components/Throbber/index.js +2 -13
  94. package/build/production/shared/components/Throbber/index.js.map +1 -1
  95. package/build/production/shared/components/WithTooltip/index.js +1 -7
  96. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  97. package/build/production/shared/components/YouTubeVideo/index.js +1 -7
  98. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  99. package/build/production/shared/components/index.js +1 -1
  100. package/build/production/shared/components/index.js.map +1 -1
  101. package/build/production/shared/utils/config.js +1 -21
  102. package/build/production/shared/utils/config.js.map +1 -1
  103. package/build/production/shared/utils/index.js +1 -20
  104. package/build/production/shared/utils/index.js.map +1 -1
  105. package/build/production/shared/utils/isomorphy.js +1 -40
  106. package/build/production/shared/utils/isomorphy.js.map +1 -1
  107. package/build/production/shared/utils/jest.js +2 -112
  108. package/build/production/shared/utils/jest.js.map +1 -1
  109. package/build/production/shared/utils/url.js +1 -1
  110. package/build/production/shared/utils/webpack.js +0 -4
  111. package/build/production/shared/utils/webpack.js.map +1 -1
  112. package/build/production/style.css +1 -1
  113. package/build/production/style.css.map +1 -1
  114. package/build/production/web.bundle.js +1 -1
  115. package/build/production/web.bundle.js.map +1 -1
  116. package/config/babel/node-ssr.js +1 -8
  117. package/config/babel/webpack.js +1 -8
  118. package/config/jest/default.js +0 -34
  119. package/config/shared/utils.js +9 -100
  120. package/config/stylelint/default.js +2 -19
  121. package/config/webpack/app-base.js +3 -6
  122. package/config/webpack/app-development.js +0 -23
  123. package/config/webpack/app-production.js +0 -20
  124. package/config/webpack/lib-base.js +3 -66
  125. package/config/webpack/lib-development.js +0 -10
  126. package/config/webpack/lib-production.js +0 -9
  127. package/index.js +21 -10
  128. package/package.json +34 -36
  129. package/src/index.js +6 -61
  130. package/src/styles/_mixins/fonts.scss +4 -4
  131. package/src/styles/mixins.scss +1 -1
  132. package/build/development/styles/global-docs.js +0 -29
  133. package/build/development/styles/global-docs.js.map +0 -1
  134. package/build/development/styles/mixins.js +0 -103
  135. package/build/development/styles/mixins.js.map +0 -1
  136. package/build/production/styles/global-docs.js +0 -28
  137. package/build/production/styles/global-docs.js.map +0 -1
  138. package/build/production/styles/mixins.js +0 -101
  139. package/build/production/styles/mixins.js.map +0 -1
  140. package/config/eslint/docs.js +0 -40
  141. package/config/jsdoc/config.js +0 -34
  142. package/src/README.md +0 -130
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/utils/jest.jsx"],"names":["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","res","document","createElement","body","appendChild","unmount","remove","findInDomByClass","dom","className","TU","findRenderedDOMComponentWithClass","findInDomManyByClass","scryRenderedDOMComponentsWithClass","render","component","Renderer","create","toJSON","Wrapper","Component","componentDidMount","children","props","propTypes","PT","node","isRequired","renderDom","renderIntoDocument","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","Simulate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;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AACP,UAAM;AAAEQ,MAAAA;AAAF,QAAe,KAAKC,KAA1B;AACA,WAAOD,QAAP;AACD;;AAN6B;;AAShCH,OAAO,CAACK,SAAR,GAAoB;AAClBF,EAAAA,QAAQ,EAAEG,mBAAGC,IAAH,CAAQC;AADA,CAApB;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,SAAT,CAAmBb,SAAnB,EAA8B;AACnC,SAAOL,mBAAGmB,kBAAH,eACL,qBAAC,OAAD;AAAA,cACGd;AADH,IADK,CAAP;AAKD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASe,aAAT,CAAuBf,SAAvB,EAAkC;AACvC,QAAMgB,QAAQ,GAAG,IAAIC,gBAAJ,EAAjB;AACAD,EAAAA,QAAQ,CAACjB,MAAT,CAAgBC,SAAhB;AACA,SAAOgB,QAAQ,CAACE,eAAT,EAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,eAAT,CAAyBnB,SAAzB,EAAoC;AACzC,QAAMf,GAAG,GAAG8B,aAAa,CAACf,SAAD,CAAzB;AACAoB,EAAAA,MAAM,CAACnC,GAAD,CAAN,CAAYoC,eAAZ;AACA,SAAOpC,GAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASqC,QAAT,CAAkBtB,SAAlB,EAA6B;AAClC,QAAMf,GAAG,GAAGc,MAAM,CAACC,SAAD,CAAlB;AACAoB,EAAAA,MAAM,CAACnC,GAAD,CAAN,CAAYoC,eAAZ;AACA,SAAOpC,GAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMsC,QAAQ,GAAG5B,mBAAG6B,QAApB","sourcesContent":["/**\n * @category Utilities\n * @module JU\n * @desc\n * ```js\n * import { JU } from '@dr.pogodin/react-utils`;\n * ```\n * The `JU` module (short for `jest-utils`) provides helpers useful in Jest\n * tests.\n *\n * **BEWARE:** This module is exported and functional only within development,\n * Jest environment.\n */\n/* global expect, jest, document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport { Component } from 'react';\n\nimport mockdate from 'mockdate';\nimport PT from 'prop-types';\nimport { render as newRender, unmountComponentAtNode } from 'react-dom';\nimport TU 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 * @static\n * @func act\n * @desc\n * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { act } = JU;\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 } from 'react-dom/test-utils';\n\nconst originalProcessVersions = process.versions;\n\n/**\n * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { mockClientSide } = JU;\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 * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { unmockClientSide } = JU;\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 * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { getMockUuid } = JU;\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 * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { mockTimer } = JU;\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 * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { mount } = JU;\n * ```\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param {React.ReactNode} scene\n * @return {HTMLElement}\n */\nexport function mount(scene) {\n const res = document.createElement('div');\n document.body.appendChild(res);\n newRender(scene, res);\n return res;\n}\n\n/**\n * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { unmount } = JU;\n * ```\n * Unmounts `scene` from the DOM.\n * @param {HTMLElement} scene\n */\nexport function unmount(scene) {\n unmountComponentAtNode(scene);\n scene.remove();\n}\n\n/* OLD STUFF BELOW THIS MARK */\n\n/**\n * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { findInDomByClass } = JU;\n * ```\n * Just an alias for\n * [findRenderedDOMComponentWithClass(..)](https://reactjs.org/docs/test-utils.html#findrendereddomcomponentwithclass).\n * @param {object} dom\n * @param {string} className\n * @return {object}\n */\nexport function findInDomByClass(dom, className) {\n return TU.findRenderedDOMComponentWithClass(dom, className);\n}\n\n/**\n * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { findInDomManyByClass } = JU;\n * ```\n * Just an alias for\n * [scryRenderedDOMComponentsWithClass(..)](https://reactjs.org/docs/test-utils.html#scryrendereddomcomponentswithclass).\n * @param {object} dom\n * @param {stirng} className\n * @return {array}\n */\nexport function findInDomManyByClass(dom, className) {\n return TU.scryRenderedDOMComponentsWithClass(dom, className);\n}\n\n/**\n * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { render } = JU;\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// The Wrapper is necessary for the \"renderDom(..)\" function, because\n// the \"renderIntoDocument(..)\" function from \"react-dom/test-utils\" works\n// only with state components, so we have to wrap our ReactJS components into\n// such Wrapper.\nclass Wrapper extends Component {\n componentDidMount() {}\n\n render() {\n const { children } = this.props;\n return children;\n }\n}\n\nWrapper.propTypes = {\n children: PT.node.isRequired,\n};\n\n/**\n * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { renderDom } = JU;\n * ```\n * Renders given ReactJS component into DOM, using `react-dom/test-utils`.\n * @param {object} component ReactJS component to render.\n * @return {object} Rendered DOM.\n * @example\n * // In many cases you will want to render and find\n * // a rendered node in the resulting tree, you can do it like this:\n *\n * import React from 'react';\n * import { JU } from '@dr.pogodin/react-utils/jest-utils';\n *\n * const dom = JU.renderDom(\n * <div>\n * Example component, containing a button you want to find in the render.\n * <button className=\"BUTTON\">Click me!</button>\n * </div>\n * );\n *\n * const button = JU.findInDomByClass(dom, 'BUTTON');\n */\nexport function renderDom(component) {\n return TU.renderIntoDocument((\n <Wrapper>\n {component}\n </Wrapper>\n ));\n}\n\n/**\n * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { shallowRender } = JU;\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 * @example\n * import { JU } from '@dr.pogodin/react-utils/jest-utils';\n * console.log(JU.shallowRender(<div>Example</div>));\n */\nexport function shallowRender(component) {\n const renderer = new ShallowRenderer();\n renderer.render(component);\n return renderer.getRenderOutput();\n}\n\n/**\n * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { shallowSnapshot } = JU;\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 * @example\n * import { JU } from '@dr.pogodin/react-utils/jest-utils';\n * test('A snapshot test', () => {\n * console.log(JU.shallowSnapshot(<div>Example</div>));\n * });\n */\nexport function shallowSnapshot(component) {\n const res = shallowRender(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\n/**\n * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { shallow } = JU;\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 * @example\n * import { JU } from '@dr.pogodin/react-utils/jest-utils';\n * test('A snapshot test', () => {\n * console.log(JU.snapshot(<div>Example</div>));\n * });\n */\nexport function snapshot(component) {\n const res = render(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\n/**\n * @static\n * @func simulate\n * @desc\n * ```js\n * import { JU } from '@dr.pogodin/react-utils';\n * const { simulate } = JU;\n * ```\n * An alias for\n * [Simulate](https://reactjs.org/docs/test-utils.html#simulate) from\n `react-dom/test-utils`.\n */\nexport const simulate = TU.Simulate;\n"],"file":"jest.js"}
1
+ {"version":3,"sources":["../../../../src/shared/utils/jest.jsx"],"names":["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","res","document","createElement","body","appendChild","unmount","remove","findInDomByClass","dom","className","TU","findRenderedDOMComponentWithClass","findInDomManyByClass","scryRenderedDOMComponentsWithClass","render","component","Renderer","create","toJSON","Wrapper","Component","componentDidMount","children","props","propTypes","PT","node","isRequired","renderDom","renderIntoDocument","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","Simulate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAEA;;AACA;;AACA;;AACA;;AAGA;;AACA;;;;;;;;AAZA;;AACA;;AASA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AAGA,MAAMA,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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sBC,gBAAtB,CAAgC;AAC9BC,EAAAA,iBAAiB,GAAG,CAAE;;AAEtBP,EAAAA,MAAM,GAAG;AACP,UAAM;AAAEQ,MAAAA;AAAF,QAAe,KAAKC,KAA1B;AACA,WAAOD,QAAP;AACD;;AAN6B;;AAShCH,OAAO,CAACK,SAAR,GAAoB;AAClBF,EAAAA,QAAQ,EAAEG,mBAAGC,IAAH,CAAQC;AADA,CAApB;AAIA;AACA;AACA;AACA;AACA;;AACO,SAASC,SAAT,CAAmBb,SAAnB,EAA8B;AACnC,SAAOL,mBAAGmB,kBAAH,eACL,qBAAC,OAAD;AAAA,cACGd;AADH,IADK,CAAP;AAKD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASe,aAAT,CAAuBf,SAAvB,EAAkC;AACvC,QAAMgB,QAAQ,GAAG,IAAIC,gBAAJ,EAAjB;AACAD,EAAAA,QAAQ,CAACjB,MAAT,CAAgBC,SAAhB;AACA,SAAOgB,QAAQ,CAACE,eAAT,EAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,eAAT,CAAyBnB,SAAzB,EAAoC;AACzC,QAAMf,GAAG,GAAG8B,aAAa,CAACf,SAAD,CAAzB;AACAoB,EAAAA,MAAM,CAACnC,GAAD,CAAN,CAAYoC,eAAZ;AACA,SAAOpC,GAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASqC,QAAT,CAAkBtB,SAAlB,EAA6B;AAClC,QAAMf,GAAG,GAAGc,MAAM,CAACC,SAAD,CAAlB;AACAoB,EAAAA,MAAM,CAACnC,GAAD,CAAN,CAAYoC,eAAZ;AACA,SAAOpC,GAAP;AACD;;AAEM,MAAMsC,QAAQ,GAAG5B,mBAAG6B,QAApB","sourcesContent":["/* global expect, jest, document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport { Component } from 'react';\n\nimport mockdate from 'mockdate';\nimport PT from 'prop-types';\nimport { render as newRender, unmountComponentAtNode } from 'react-dom';\nimport TU 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 } from 'react-dom/test-utils';\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}\n */\nexport function mount(scene) {\n const res = document.createElement('div');\n document.body.appendChild(res);\n newRender(scene, res);\n return res;\n}\n\n/**\n * Unmounts `scene` from the DOM.\n * @param {HTMLElement} scene\n */\nexport function unmount(scene) {\n unmountComponentAtNode(scene);\n scene.remove();\n}\n\n/* OLD STUFF BELOW THIS MARK */\n\n/**\n * Just an alias for\n * [findRenderedDOMComponentWithClass(..)](https://reactjs.org/docs/test-utils.html#findrendereddomcomponentwithclass).\n * @param {object} dom\n * @param {string} className\n * @return {object}\n */\nexport function findInDomByClass(dom, className) {\n return TU.findRenderedDOMComponentWithClass(dom, className);\n}\n\n/**\n * Just an alias for\n * [scryRenderedDOMComponentsWithClass(..)](https://reactjs.org/docs/test-utils.html#scryrendereddomcomponentswithclass).\n * @param {object} dom\n * @param {stirng} className\n * @return {array}\n */\nexport function findInDomManyByClass(dom, className) {\n return TU.scryRenderedDOMComponentsWithClass(dom, className);\n}\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// The Wrapper is necessary for the \"renderDom(..)\" function, because\n// the \"renderIntoDocument(..)\" function from \"react-dom/test-utils\" works\n// only with state components, so we have to wrap our ReactJS components into\n// such Wrapper.\nclass Wrapper extends Component {\n componentDidMount() {}\n\n render() {\n const { children } = this.props;\n return children;\n }\n}\n\nWrapper.propTypes = {\n children: PT.node.isRequired,\n};\n\n/**\n * Renders given ReactJS component into DOM, using `react-dom/test-utils`.\n * @param {object} component ReactJS component to render.\n * @return {object} Rendered DOM.\n */\nexport function renderDom(component) {\n return TU.renderIntoDocument((\n <Wrapper>\n {component}\n </Wrapper>\n ));\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"}
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.parent = parent;
7
6
  exports.default = void 0;
7
+ exports.parent = parent;
8
8
 
9
9
  var _lodash = require("lodash");
10
10
 
@@ -54,10 +54,6 @@ function requireWeak(modulePath) {
54
54
  return def;
55
55
  }
56
56
  /**
57
- * ```js
58
- * import { webpack } from '@dr.pogodin/react-utils';
59
- * const { resolveWeak } = webpack;
60
- * ```
61
57
  * Resolves specified module path with help of Babel's module resolver.
62
58
  * Yes, the function itself just returns its argument to the caller, but Babel
63
59
  * is configured to resolve the first argument of resolveWeak(..) function, thus
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/shared/utils/webpack.js"],"names":["requireWeak","modulePath","default","def","named","eval","Object","entries","forEach","key","value","Error","resolveWeak"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,WAAT,CAAqBC,UAArB,EAAiC;AACtC;AACA,QAAM;AAAEC,IAAAA,OAAO,EAAEC,GAAX;AAAgB,OAAGC;AAAnB,MAA6BC,IAAI,CAAC,SAAD,CAAJ,CAAgBJ,UAAhB,CAAnC;AACA;;AAEA,MAAI,CAACE,GAAL,EAAU,OAAOC,KAAP;AAEVE,EAAAA,MAAM,CAACC,OAAP,CAAeH,KAAf,EAAsBI,OAAtB,CAA8B,CAAC,CAACC,GAAD,EAAMC,KAAN,CAAD,KAAkB;AAC9C,QAAIP,GAAG,CAACM,GAAD,CAAP,EAAc,MAAME,KAAK,CAAC,4CAAD,CAAX;AACdR,IAAAA,GAAG,CAACM,GAAD,CAAH,GAAWC,KAAX;AACD,GAHD;AAIA,SAAOP,GAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASS,WAAT,CAAqBX,UAArB,EAAiC;AACtC,SAAOA,UAAP;AACD","sourcesContent":["/**\n * @category Utilities\n * @module webpack\n * @desc\n * ```js\n * import { webpack } from '@dr.pogodin/react-utils';\n * ```\n * Webpack-related utilities.\n */\n\n/**\n * ```js\n * import { webpack } from '@dr.pogodin/react-utils';\n * const { requireWeak } = webpack;\n * ```\n * Requires the specified module without including it into the bundle during\n * Webpack build. This function should be executed only server-side.\n *\n * WARNING: Beware to pass in relative paths: they will be resolved relative\n * to the library distribution function, this is not what you want in most of\n * cases. To convert a relative path to the absolute one, do in the caller code\n * ```\n * import path from 'path';\n * const p = path.resolve(__dirname, './relative/path');\n * const module = requireWeak(p);\n * ```\n * In case you use an absolute path that relies on Babel module resolver,\n * pass it through resolveWeak function below.\n *\n * @param {string} modulePath\n * @return {object} Required module.\n */\nexport function requireWeak(modulePath) {\n /* eslint-disable no-eval */\n const { default: def, ...named } = eval('require')(modulePath);\n /* eslint-enable no-eval */\n\n if (!def) return named;\n\n Object.entries(named).forEach(([key, value]) => {\n if (def[key]) throw Error('Conflict between default and named exports');\n def[key] = value;\n });\n return def;\n}\n\n/**\n * ```js\n * import { webpack } from '@dr.pogodin/react-utils';\n * const { resolveWeak } = webpack;\n * ```\n * Resolves specified module path with help of Babel's module resolver.\n * Yes, the function itself just returns its argument to the caller, but Babel\n * is configured to resolve the first argument of resolveWeak(..) function, thus\n * the result will be the resolved path.\n * @param {string} modulePath\n * @return {string} Absolute or relative path to the module.\n */\nexport function resolveWeak(modulePath) {\n return modulePath;\n}\n"],"file":"webpack.js"}
1
+ {"version":3,"sources":["../../../../src/shared/utils/webpack.js"],"names":["requireWeak","modulePath","default","def","named","eval","Object","entries","forEach","key","value","Error","resolveWeak"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,WAAT,CAAqBC,UAArB,EAAiC;AACtC;AACA,QAAM;AAAEC,IAAAA,OAAO,EAAEC,GAAX;AAAgB,OAAGC;AAAnB,MAA6BC,IAAI,CAAC,SAAD,CAAJ,CAAgBJ,UAAhB,CAAnC;AACA;;AAEA,MAAI,CAACE,GAAL,EAAU,OAAOC,KAAP;AAEVE,EAAAA,MAAM,CAACC,OAAP,CAAeH,KAAf,EAAsBI,OAAtB,CAA8B,CAAC,CAACC,GAAD,EAAMC,KAAN,CAAD,KAAkB;AAC9C,QAAIP,GAAG,CAACM,GAAD,CAAP,EAAc,MAAME,KAAK,CAAC,4CAAD,CAAX;AACdR,IAAAA,GAAG,CAACM,GAAD,CAAH,GAAWC,KAAX;AACD,GAHD;AAIA,SAAOP,GAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASS,WAAT,CAAqBX,UAArB,EAAiC;AACtC,SAAOA,UAAP;AACD","sourcesContent":["/**\n * @category Utilities\n * @module webpack\n * @desc\n * ```js\n * import { webpack } from '@dr.pogodin/react-utils';\n * ```\n * Webpack-related utilities.\n */\n\n/**\n * ```js\n * import { webpack } from '@dr.pogodin/react-utils';\n * const { requireWeak } = webpack;\n * ```\n * Requires the specified module without including it into the bundle during\n * Webpack build. This function should be executed only server-side.\n *\n * WARNING: Beware to pass in relative paths: they will be resolved relative\n * to the library distribution function, this is not what you want in most of\n * cases. To convert a relative path to the absolute one, do in the caller code\n * ```\n * import path from 'path';\n * const p = path.resolve(__dirname, './relative/path');\n * const module = requireWeak(p);\n * ```\n * In case you use an absolute path that relies on Babel module resolver,\n * pass it through resolveWeak function below.\n *\n * @param {string} modulePath\n * @return {object} Required module.\n */\nexport function requireWeak(modulePath) {\n /* eslint-disable no-eval */\n const { default: def, ...named } = eval('require')(modulePath);\n /* eslint-enable no-eval */\n\n if (!def) return named;\n\n Object.entries(named).forEach(([key, value]) => {\n if (def[key]) throw Error('Conflict between default and named exports');\n def[key] = value;\n });\n return def;\n}\n\n/**\n * Resolves specified module path with help of Babel's module resolver.\n * Yes, the function itself just returns its argument to the caller, but Babel\n * is configured to resolve the first argument of resolveWeak(..) function, thus\n * the result will be the resolved path.\n * @param {string} modulePath\n * @return {string} Absolute or relative path to the module.\n */\nexport function resolveWeak(modulePath) {\n return modulePath;\n}\n"],"file":"webpack.js"}