react/scripts/jest/ReactDOMServerIntegrationEnvironment.js
Sebastian Markbåge 64d6be7122
Use require() to implement script src in tests (#26717)
We currently use rollup to make an adhoc bundle from the file system
when we're testing an import of an external file.

This doesn't follow all the interception rules that we use in jest and
in our actual builds.

This switches to just using jest require() to load these. This means
that they effectively have to load into the global document so this only
works with global document tests which is all we have now anyway.
2023-04-25 09:12:16 -04:00

35 lines
1.1 KiB
JavaScript

'use strict';
const {TestEnvironment: JSDOMEnvironment} = require('jest-environment-jsdom');
const {TestEnvironment: NodeEnvironment} = require('jest-environment-node');
/**
* Test environment for testing integration of react-dom (browser) with react-dom/server (node)
*/
class ReactDOMServerIntegrationEnvironment extends NodeEnvironment {
constructor(config, context) {
super(config, context);
this.domEnvironment = new JSDOMEnvironment(config, context);
this.global.window = this.domEnvironment.dom.window;
this.global.document = this.global.window.document;
this.global.navigator = this.global.window.navigator;
this.global.Node = this.global.window.Node;
this.global.addEventListener = this.global.window.addEventListener;
this.global.MutationObserver = this.global.window.MutationObserver;
}
async setup() {
await super.setup();
await this.domEnvironment.setup();
}
async teardown() {
await this.domEnvironment.teardown();
await super.teardown();
}
}
module.exports = ReactDOMServerIntegrationEnvironment;