Skip to content

Conversation

@everettbu
Copy link

Mirror of facebook/react#35358
Original author: HM-23-HM


Summary

Annotations like // @reactVersion >= 16.9 were not being handled properly by the jest preprocessor on a Windows computer. This resulted in tests running that should have been skipped.

The root cause was that the relevant regular expressions in preprocessor.js were not matching the backslashes in Windows paths, so I updated them.

How did you test this change?

I isolated some of the test cases that were running (and failing), but should have been skipped. One example is the "should handle stress test with reordering" test in the following file:
react\packages\react-devtools-shared\src\__tests__\storeStressSync-test.js which has the following annotations:

  // `@reactVersion` >= 16.9
  // `@reactVersion` <= 18.2

Here's the command I used to evaluate the fix:
yarn test-build-devtools --testNamePattern="should handle stress test with reordering"

Output (Before):

 FAIL  packages/react-devtools-shared/src/__tests__/storeStressSync-test.js (19.716 s)
  ● StoreStress (Legacy Mode) › should handle stress test with reordering (Legacy Mode)

    TypeError: ReactDOM.render is not a function

      154 |       ['ReactDOM.render has not been supported since React 18'],
      155 |       () => {
    > 156 |         ReactDOM.render(elements, container);
          |                  ^
      157 |       },
      158 |     );
      159 |

      at packages/react-devtools-shared/src/__tests__/utils.js:156:18
      at withErrorsOrWarningsIgnored (packages/react-devtools-shared/src/__tests__/utils.js:459:25)
      at render (packages/react-devtools-shared/src/__tests__/utils.js:153:5)
      at packages/react-devtools-shared/src/__tests__/storeStressSync-test.js:358:31
      at packages/react-devtools-shared/src/__tests__/utils.js:78:7
      at Object.<anonymous>.process.env.NODE_ENV.exports.act (build/oss-experimental/react/cjs/react.development.js:907:22)
      at packages/react-devtools-shared/src/__tests__/utils.js:77:5
      at Object.<anonymous>.process.env.NODE_ENV.exports.act (build/oss-experimental/react/cjs/react.development.js:907:22)
      at act (packages/react-devtools-shared/src/__tests__/utils.js:76:3)
      at _loop3 (packages/react-devtools-shared/src/__tests__/storeStressSync-test.js:358:7)    
      at Object.<anonymous> (packages/react-devtools-shared/src/__tests__/storeStressSync-test.js:363:301)

 PASS  packages/react-devtools-shared/src/__tests__/storeStressTestConcurrent-test.js (16.505 s)

Summary of all failing tests
 FAIL  packages/react-devtools-shared/src/__tests__/storeStressSync-test.js (19.716 s)
  ● StoreStress (Legacy Mode) › should handle stress test with reordering (Legacy Mode)

    TypeError: ReactDOM.render is not a function

      154 |       ['ReactDOM.render has not been supported since React 18'],
      155 |       () => {
    > 156 |         ReactDOM.render(elements, container);
          |                  ^
      157 |       },
      158 |     );
      159 |

      at packages/react-devtools-shared/src/__tests__/utils.js:156:18
      at withErrorsOrWarningsIgnored (packages/react-devtools-shared/src/__tests__/utils.js:459:25)
      at render (packages/react-devtools-shared/src/__tests__/utils.js:153:5)
      at packages/react-devtools-shared/src/__tests__/storeStressSync-test.js:358:31
      at packages/react-devtools-shared/src/__tests__/utils.js:78:7
      at Object.<anonymous>.process.env.NODE_ENV.exports.act (build/oss-experimental/react/cjs/react.development.js:907:22)
      at packages/react-devtools-shared/src/__tests__/utils.js:77:5
      at Object.<anonymous>.process.env.NODE_ENV.exports.act (build/oss-experimental/react/cjs/react.development.js:907:22)
      at act (packages/react-devtools-shared/src/__tests__/utils.js:76:3)
      at _loop3 (packages/react-devtools-shared/src/__tests__/storeStressSync-test.js:358:7)    
      at Object.<anonymous> (packages/react-devtools-shared/src/__tests__/storeStressSync-test.js:363:301)


Test Suites: 1 failed, 41 skipped, 1 passed, 2 of 43 total
Tests:       1 failed, 517 skipped, 1 passed, 519 total
Snapshots:   1 passed, 1 total
Time:        30.984 s, estimated 123 s
Ran all test suites with tests matching "should handle stress test with reordering".
error Command failed with exit code 1.

Output (After):

 PASS  packages/react-devtools-shared/src/__tests__/storeStressTestConcurrent-test.js (16.079 s)

Test Suites: 42 skipped, 1 passed, 1 of 43 total
Tests:       518 skipped, 1 passed, 519 total
Snapshots:   1 passed, 1 total
Time:        30.221 s, estimated 123 s
Ran all test suites with tests matching "should handle stress test with reordering".
Done in 33.55s.

@greptile-apps
Copy link

greptile-apps bot commented Dec 14, 2025

Greptile Overview

Greptile Summary

Fixed Windows path compatibility in Jest preprocessor by updating three regex patterns to handle both forward slashes and backslashes. This ensures that React version pragmas (e.g., @reactVersion >= 16.9) are properly processed on Windows systems, preventing tests that should be skipped from running incorrectly.

  • Changed /third_party/[/\\]third_party[/\\] to exclude third-party files on Windows
  • Changed /__tests__/[/\\]__tests__[/\\] to correctly identify test files on Windows
  • Changed /packages/react-devtools.*/[/\\]packages[/\\]react-devtools.*[/\\] to identify DevTools packages on Windows

The PR author verified the fix by testing a specific case where tests with version constraints were incorrectly running on Windows and failing, and confirmed that after the fix, these tests are properly skipped.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are minimal, well-tested, and address a clear cross-platform compatibility issue. The regex patterns are straightforward character class additions that preserve the original matching logic while adding Windows backslash support. The author provided concrete evidence that the fix works correctly.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
scripts/jest/preprocessor.js 5/5 Updated three regex patterns to handle both forward slashes and backslashes for Windows path compatibility, enabling proper test filtering based on React version pragmas

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants