Skip to content

Commit

Permalink
Fix tests mixing environments
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Mar 8, 2022
1 parent 5782002 commit 0166dd3
Show file tree
Hide file tree
Showing 22 changed files with 309 additions and 45 deletions.
24 changes: 13 additions & 11 deletions packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
* @jest-environment node
*/

'use strict';
Expand All @@ -21,8 +22,6 @@ let useSyncExternalStore;
let useSyncExternalStoreWithSelector;
let PropTypes;
let textCache;
let window;
let document;
let writable;
let CSPnonce = null;
let container;
Expand All @@ -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(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
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');
Expand Down Expand Up @@ -64,15 +75,6 @@ describe('ReactDOMFizzServer', () => {

textCache = new Map();

// Test Environment
const jsdom = new JSDOM(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
runScripts: 'dangerously',
},
);
window = jsdom.window;
document = jsdom.window.document;
container = document.getElementById('container');

buffer = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
* @jest-environment node
*/

let JSDOM;
Expand All @@ -14,7 +15,6 @@ let Scheduler;
let clientAct;
let ReactDOMFizzServer;
let Stream;
let document;
let writable;
let container;
let buffer = '';
Expand All @@ -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(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
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');
Expand All @@ -35,14 +47,6 @@ describe('ReactDOMFizzShellHydration', () => {

textCache = new Map();

// Test Environment
const jsdom = new JSDOM(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
runScripts: 'dangerously',
},
);
document = jsdom.window.document;
container = document.getElementById('container');

buffer = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
* @jest-environment node
*/

'use strict';

const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils');
const ReactFeatureFlags = require('shared/ReactFeatureFlags');

let JSDOM;
let React;
let ReactDOM;
let ReactTestUtils;
Expand All @@ -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(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
* @jest-environment node
*/

'use strict';
Expand All @@ -13,6 +14,7 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegratio

const TEXT_NODE_TYPE = 3;

let JSDOM;
let React;
let ReactDOM;
let ReactDOMServer;
Expand All @@ -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(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
* @jest-environment node
*/

'use strict';
Expand All @@ -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;
Expand All @@ -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(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
* @jest-environment node
*/

'use strict';
Expand All @@ -13,13 +14,27 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegratio

const TEXT_NODE_TYPE = 3;

let JSDOM;
let React;
let ReactDOM;
let ReactDOMServer;
let ReactTestUtils;

function initModules() {
jest.resetModules();
// Creating mixed environment for `react-dom` + `react-dom/server`
JSDOM = require('jsdom').JSDOM;
const jsdom = new JSDOM(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -13,6 +14,7 @@

const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils');

let JSDOM;
let React;
let ReactDOM;
let ReactDOMServer;
Expand All @@ -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(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
* @jest-environment node
*/

'use strict';
Expand All @@ -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;
Expand All @@ -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(
'<!DOCTYPE html><html><head></head><body><div id="container">',
{
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');
Expand Down
Loading

0 comments on commit 0166dd3

Please sign in to comment.