From f411e8990ff2a6d5ea5e0813489f11747e518d7b Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Sat, 11 Mar 2023 15:46:16 -0500 Subject: [PATCH] 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. --- ... ReactDOMServerIntegrationUntrustedURL-test.js} | 14 ++++++++++++++ scripts/jest/setupTests.www.js | 11 +---------- 2 files changed, 15 insertions(+), 10 deletions(-) rename packages/react-dom/src/__tests__/{ReactDOMServerIntegrationUntrustedURL-test.internal.js => ReactDOMServerIntegrationUntrustedURL-test.js} (94%) diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.js similarity index 94% rename from packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.internal.js rename to packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.js index c9c875f8b8..6aadcb7574 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.js @@ -149,6 +149,13 @@ function runTests(itRenders, itRejectsRendering, expectToReject) { } describe('ReactDOMServerIntegration - Untrusted URLs', () => { + // The `itRenders` helpers don't work with the gate pragma, so we have to do + // this instead. + if (gate(flags => flags.disableJavaScriptURLs)) { + it("empty test so Jest doesn't complain", () => {}); + return; + } + function initModules() { jest.resetModules(); React = require('react'); @@ -181,6 +188,13 @@ describe('ReactDOMServerIntegration - Untrusted URLs', () => { }); describe('ReactDOMServerIntegration - Untrusted URLs - disableJavaScriptURLs', () => { + // The `itRenders` helpers don't work with the gate pragma, so we have to do + // this instead. + if (gate(flags => !flags.disableJavaScriptURLs)) { + it("empty test so Jest doesn't complain", () => {}); + return; + } + function initModules() { jest.resetModules(); const ReactFeatureFlags = require('shared/ReactFeatureFlags'); diff --git a/scripts/jest/setupTests.www.js b/scripts/jest/setupTests.www.js index a9ce345e04..99d77429a3 100644 --- a/scripts/jest/setupTests.www.js +++ b/scripts/jest/setupTests.www.js @@ -6,16 +6,7 @@ jest.mock('shared/ReactFeatureFlags', () => { () => jest.requireActual('shared/forks/ReactFeatureFlags.www-dynamic'), {virtual: true} ); - - const wwwFlags = jest.requireActual('shared/forks/ReactFeatureFlags.www'); - const defaultFlags = jest.requireActual('shared/ReactFeatureFlags'); - - // TODO: Many tests were written before we started running them against the - // www configuration. Update those tests so that they work against the www - // configuration, too. Then remove these overrides. - wwwFlags.disableJavaScriptURLs = defaultFlags.disableJavaScriptURLs; - - return wwwFlags; + return jest.requireActual('shared/forks/ReactFeatureFlags.www'); }); jest.mock('scheduler/src/SchedulerFeatureFlags', () => {