Skip to content

Commit

Permalink
Remove .internal override from untrusted URL tests
Browse files Browse the repository at this point in the history
Adding `.internal` to a test file override 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.
  • Loading branch information
acdlite committed Mar 11, 2023
1 parent 1d41dd0 commit 4748b3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
11 changes: 1 addition & 10 deletions scripts/jest/setupTests.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 4748b3e

Please sign in to comment.