@samitouri / QOS-React-2 / commits / f411e8990f

Remote `.internal` override from untrusted URL tests (#26372)

Adding `.internal` to a test file prevents it from being tested in build mode. The best practice is to instead gate the test based on whether the feature is enabled. Ideally we'd use the `@gate` pragma in these tests, but the `itRenders` test helpers don't support that.

Andrew Clark committed Mar 11, 2023 at 15:46 UTC f411e8990ff2a6d5ea5e0813489f11747e518d7b
2 files changed +15 -10
packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.js renamed
+14
@@ -149,6 +149,13 @@ function runTests(itRenders, itRejectsRendering, expectToReject) {
149 }
150
151 describe('ReactDOMServerIntegration - Untrusted URLs', () => {
152 + // The `itRenders` helpers don't work with the gate pragma, so we have to do
153 + // this instead.
154 + if (gate(flags => flags.disableJavaScriptURLs)) {
155 + it("empty test so Jest doesn't complain", () => {});
156 + return;
157 + }
158 +
159 function initModules() {
160 jest.resetModules();
161 React = require('react');
@@ -181,6 +188,13 @@ describe('ReactDOMServerIntegration - Untrusted URLs', () => {
188 });
189
190 describe('ReactDOMServerIntegration - Untrusted URLs - disableJavaScriptURLs', () => {
191 + // The `itRenders` helpers don't work with the gate pragma, so we have to do
192 + // this instead.
193 + if (gate(flags => !flags.disableJavaScriptURLs)) {
194 + it("empty test so Jest doesn't complain", () => {});
195 + return;
196 + }
197 +
198 function initModules() {
199 jest.resetModules();
200 const ReactFeatureFlags = require('shared/ReactFeatureFlags');
scripts/jest/setupTests.www.js
+1 -10
@@ -6,16 +6,7 @@ jest.mock('shared/ReactFeatureFlags', () => {
6 () => jest.requireActual('shared/forks/ReactFeatureFlags.www-dynamic'),
7 {virtual: true}
8 );
9 -
10 - const wwwFlags = jest.requireActual('shared/forks/ReactFeatureFlags.www');
11 - const defaultFlags = jest.requireActual('shared/ReactFeatureFlags');
12 -
13 - // TODO: Many tests were written before we started running them against the
14 - // www configuration. Update those tests so that they work against the www
15 - // configuration, too. Then remove these overrides.
16 - wwwFlags.disableJavaScriptURLs = defaultFlags.disableJavaScriptURLs;
17 -
18 - return wwwFlags;
9 + return jest.requireActual('shared/forks/ReactFeatureFlags.www');
10 });
11
12 jest.mock('scheduler/src/SchedulerFeatureFlags', () => {