From 0166dd3f16371e526fbdeda998f3928644353a78 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Tue, 8 Mar 2022 09:34:06 +0100 Subject: [PATCH] Fix tests mixing environments --- .../src/__tests__/ReactDOMFizzServer-test.js | 24 ++++++++-------- .../ReactDOMFizzShellHydration-test.js | 22 +++++++++------ ...eactDOMServerIntegrationAttributes-test.js | 15 ++++++++++ .../ReactDOMServerIntegrationBasic-test.js | 15 ++++++++++ .../ReactDOMServerIntegrationCheckbox-test.js | 15 ++++++++++ ...MServerIntegrationClassContextType-test.js | 15 ++++++++++ .../ReactDOMServerIntegrationElements-test.js | 15 ++++++++++ .../ReactDOMServerIntegrationFragment-test.js | 15 ++++++++++ .../ReactDOMServerIntegrationHooks-test.js | 14 ++++++++++ .../ReactDOMServerIntegrationInput-test.js | 15 ++++++++++ ...tDOMServerIntegrationLegacyContext-test.js | 15 ++++++++++ ...tionLegacyContextDisabled-test.internal.js | 15 ++++++++++ .../ReactDOMServerIntegrationModes-test.js | 15 ++++++++++ ...eactDOMServerIntegrationNewContext-test.js | 15 ++++++++++ .../ReactDOMServerIntegrationSelect-test.js | 15 ++++++++++ ...ctDOMServerIntegrationSpecialTypes-test.js | 15 ++++++++++ .../ReactDOMServerIntegrationTextarea-test.js | 15 ++++++++++ ...erIntegrationUntrustedURL-test.internal.js | 28 +++++++++++++++++++ .../src/__tests__/ReactDOMUseId-test.js | 23 +++++++++------ .../ReactDOMserverIntegrationProgress-test.js | 15 ++++++++++ packages/react-reconciler/src/DebugTracing.js | 1 + packages/shared/ReactVersion.js | 17 +---------- 22 files changed, 309 insertions(+), 45 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js index 0aacf5a755247..25e9263838012 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; @@ -21,8 +22,6 @@ let useSyncExternalStore; let useSyncExternalStoreWithSelector; let PropTypes; let textCache; -let window; -let document; let writable; let CSPnonce = null; let container; @@ -33,7 +32,19 @@ let fatalError = undefined; describe('ReactDOMFizzServer', () => { beforeEach(() => { jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + Scheduler = require('scheduler'); React = require('react'); ReactDOMClient = require('react-dom/client'); @@ -64,15 +75,6 @@ describe('ReactDOMFizzServer', () => { textCache = new Map(); - // Test Environment - const jsdom = new JSDOM( - '
', - { - runScripts: 'dangerously', - }, - ); - window = jsdom.window; - document = jsdom.window.document; container = document.getElementById('container'); buffer = ''; diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzShellHydration-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzShellHydration-test.js index f3ff64daeec43..64cd78021611f 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzShellHydration-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzShellHydration-test.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ let JSDOM; @@ -14,7 +15,6 @@ let Scheduler; let clientAct; let ReactDOMFizzServer; let Stream; -let document; let writable; let container; let buffer = ''; @@ -25,7 +25,19 @@ let textCache; describe('ReactDOMFizzShellHydration', () => { beforeEach(() => { jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOMClient = require('react-dom/client'); Scheduler = require('scheduler'); @@ -35,14 +47,6 @@ describe('ReactDOMFizzShellHydration', () => { textCache = new Map(); - // Test Environment - const jsdom = new JSDOM( - '
', - { - runScripts: 'dangerously', - }, - ); - document = jsdom.window.document; container = document.getElementById('container'); buffer = ''; diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationAttributes-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationAttributes-test.js index 63517899187dd..8b69fd1f4c926 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationAttributes-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationAttributes-test.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; @@ -12,6 +13,7 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); const ReactFeatureFlags = require('shared/ReactFeatureFlags'); +let JSDOM; let React; let ReactDOM; let ReactTestUtils; @@ -20,6 +22,19 @@ let ReactDOMServer; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationBasic-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationBasic-test.js index b29a4fd1e4210..671534c880f16 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationBasic-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationBasic-test.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; @@ -13,6 +14,7 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegratio const TEXT_NODE_TYPE = 3; +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -21,6 +23,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationCheckbox-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationCheckbox-test.js index c3e084ddbf6f5..039eb6415062e 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationCheckbox-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationCheckbox-test.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; @@ -13,6 +14,7 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegratio // Set by `yarn test-fire`. const {disableInputAttributeSyncing} = require('shared/ReactFeatureFlags'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -21,6 +23,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationClassContextType-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationClassContextType-test.js index 0f8c9e7f10367..e0492d42bbd4d 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationClassContextType-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationClassContextType-test.js @@ -5,12 +5,14 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -19,6 +21,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js index 4ec53bca0feb0..758ab3a704ec1 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; @@ -13,6 +14,7 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegratio const TEXT_NODE_TYPE = 3; +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -20,6 +22,19 @@ let ReactTestUtils; function initModules() { jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationFragment-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationFragment-test.js index 14bd0211c9e7f..ead62bb27559a 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationFragment-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationFragment-test.js @@ -5,12 +5,14 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -19,6 +21,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js index c1645f45c51d8..2a9e4e4a22550 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ /* eslint-disable no-func-assign */ @@ -13,6 +14,7 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -36,6 +38,18 @@ let clearYields; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; React = require('react'); ReactDOM = require('react-dom'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationInput-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationInput-test.js index 6bd249008fdfa..502c46ee0e3b9 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationInput-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationInput-test.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; @@ -13,6 +14,7 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegratio // Set by `yarn test-fire`. const {disableInputAttributeSyncing} = require('shared/ReactFeatureFlags'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -21,6 +23,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContext-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContext-test.js index b43daf1c15a1d..3c0a9796acf9d 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContext-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContext-test.js @@ -5,12 +5,14 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let PropTypes; let React; let ReactDOM; @@ -20,6 +22,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + PropTypes = require('prop-types'); React = require('react'); ReactDOM = require('react-dom'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContextDisabled-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContextDisabled-test.internal.js index 80e3fa6c2e677..4aa94075c662e 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContextDisabled-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContextDisabled-test.internal.js @@ -5,12 +5,14 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let React; let ReactDOM; let ReactFeatureFlags; @@ -20,6 +22,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationModes-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationModes-test.js index 5a36d917429f9..af4e8308639b0 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationModes-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationModes-test.js @@ -5,12 +5,14 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -19,6 +21,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js index 4050a3663a2d3..cbba0578cd063 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js @@ -5,12 +5,14 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -19,6 +21,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + JSDOM = require('jsdom').JSDOM; + // Creating mixed environment for `react-dom` + `react-dom/server` + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSelect-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSelect-test.js index cbdfa17d2aac7..4d40454f3a75e 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSelect-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSelect-test.js @@ -5,12 +5,14 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -19,6 +21,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSpecialTypes-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSpecialTypes-test.js index 1c8af62e7a9e6..f0f1763e8d132 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSpecialTypes-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSpecialTypes-test.js @@ -5,12 +5,14 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -24,6 +26,19 @@ let clearYields; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationTextarea-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationTextarea-test.js index 2a4f59ae90c9d..6f98fb2b5fcd9 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationTextarea-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationTextarea-test.js @@ -5,12 +5,14 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -19,6 +21,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.internal.js index 46cf9f0b58e36..ce0e9020130e2 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.internal.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ /* eslint-disable no-script-url */ @@ -13,6 +14,7 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -150,6 +152,19 @@ function runTests(itRenders, itRejectsRendering, expectToReject) { describe('ReactDOMServerIntegration - Untrusted URLs', () => { function initModules() { jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); @@ -185,6 +200,19 @@ describe('ReactDOMServerIntegration - Untrusted URLs - disableJavaScriptURLs', ( const ReactFeatureFlags = require('shared/ReactFeatureFlags'); ReactFeatureFlags.disableJavaScriptURLs = true; + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMUseId-test.js b/packages/react-dom/src/__tests__/ReactDOMUseId-test.js index 4148eeaa2e640..229b4696c28f6 100644 --- a/packages/react-dom/src/__tests__/ReactDOMUseId-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMUseId-test.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ let JSDOM; @@ -17,7 +18,6 @@ let Stream; let Suspense; let useId; let useState; -let document; let writable; let container; let buffer = ''; @@ -28,6 +28,19 @@ describe('useId', () => { beforeEach(() => { jest.resetModules(); JSDOM = require('jsdom').JSDOM; + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOMClient = require('react-dom/client'); Scheduler = require('scheduler'); @@ -38,14 +51,6 @@ describe('useId', () => { useId = React.useId; useState = React.useState; - // Test Environment - const jsdom = new JSDOM( - '
', - { - runScripts: 'dangerously', - }, - ); - document = jsdom.window.document; container = document.getElementById('container'); buffer = ''; diff --git a/packages/react-dom/src/__tests__/ReactDOMserverIntegrationProgress-test.js b/packages/react-dom/src/__tests__/ReactDOMserverIntegrationProgress-test.js index e4b165836cc37..b05df4ae06276 100644 --- a/packages/react-dom/src/__tests__/ReactDOMserverIntegrationProgress-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMserverIntegrationProgress-test.js @@ -5,12 +5,14 @@ * LICENSE file in the root directory of this source tree. * * @emails react-core + * @jest-environment node */ 'use strict'; const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); +let JSDOM; let React; let ReactDOM; let ReactDOMServer; @@ -19,6 +21,19 @@ let ReactTestUtils; function initModules() { // Reset warning cache. jest.resetModules(); + // Creating mixed environment for `react-dom` + `react-dom/server` + JSDOM = require('jsdom').JSDOM; + const jsdom = new JSDOM( + '
', + { + runScripts: 'dangerously', + }, + ); + global.window = jsdom.window; + global.document = jsdom.window.document; + global.navigator = jsdom.window.navigator; + global.Node = jsdom.window.Node; + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-reconciler/src/DebugTracing.js b/packages/react-reconciler/src/DebugTracing.js index ac13410c36231..74f74e24702fb 100644 --- a/packages/react-reconciler/src/DebugTracing.js +++ b/packages/react-reconciler/src/DebugTracing.js @@ -49,6 +49,7 @@ function log(...logArgs): void { for (let i = printedGroupIndex + 1; i < pendingGroupArgs.length; i++) { const groupArgs = pendingGroupArgs[i]; nativeConsole.group(...groupArgs); + // nativeConsoleLog(new Error().stack) } printedGroupIndex = pendingGroupArgs.length - 1; } diff --git a/packages/shared/ReactVersion.js b/packages/shared/ReactVersion.js index 8d357322ca3ac..07e036ff32996 100644 --- a/packages/shared/ReactVersion.js +++ b/packages/shared/ReactVersion.js @@ -1,16 +1 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// TODO: this is special because it gets imported during build. -// -// TODO: 17.0.3 has not been released to NPM; -// It exists as a placeholder so that DevTools can support work tag changes between releases. -// When we next publish a release (either 17.0.3 or 17.1.0), update the matching TODO in backend/renderer.js -// TODO: This module is used both by the release scripts and to expose a version -// at runtime. We should instead inject the version number as part of the build -// process, and use the ReactVersions.js module as the single source of truth. -export default '17.0.3'; +export default '18.0.0-rc.1-experimental-57820024ad-20220308';