Skip to content

Commit 0372fbe

Browse files
justin808claude
andcommitted
Fix RSC test infrastructure: Convert jest.setup.js to ESM and re-enable tests
- Convert jest.setup.js from CommonJS require() to ESM imports for compatibility with ESM mode - Re-enable RSC tests with automatic React version detection: - Tests run normally on React 19+ where RSC features are available - Tests skip gracefully on React 18 with informative message - Remove unnecessary script/convert override since package.json now handles version checking automatically 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ba7b11b commit 0372fbe

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

packages/react-on-rails-pro/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"clean": "rm -rf ./lib",
1010
"test": "pnpm run test:non-rsc && pnpm run test:rsc",
1111
"test:non-rsc": "jest tests --testPathIgnorePatterns=\".*(RSC|stream|registerServerComponent|serverRenderReactComponent|SuspenseHydration).*\"",
12-
"test:rsc": "echo 'TODO: RSC tests disabled - jest.setup.js uses require() incompatible with ESM mode. Re-enable after converting setup to ESM.' && exit 0",
12+
"test:rsc": "node scripts/check-react-version.cjs || NODE_CONDITIONS=react-server jest tests/*.rsc.test.*",
1313
"type-check": "tsc --noEmit --noErrorTruncation",
1414
"prepare": "[ -f lib/ReactOnRails.full.js ] || (rm -rf ./lib && tsc)",
1515
"prepublishOnly": "pnpm run build",

packages/react-on-rails-pro/tests/jest.setup.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import { TextEncoder, TextDecoder } from 'util';
2+
import { Readable } from 'stream';
3+
import { ReadableStream, ReadableStreamDefaultReader } from 'stream/web';
4+
import { jest } from '@jest/globals';
5+
16
// If jsdom environment is set and TextEncoder is not defined, then define TextEncoder and TextDecoder
27
// The current version of jsdom does not support TextEncoder and TextDecoder
38
// The following code will tell us when jsdom supports TextEncoder and TextDecoder
@@ -11,13 +16,6 @@ if (typeof window !== 'undefined' && typeof window.MessageChannel !== 'undefined
1116
}
1217

1318
if (typeof window !== 'undefined') {
14-
// eslint-disable-next-line global-require
15-
const { TextEncoder, TextDecoder } = require('util');
16-
// eslint-disable-next-line global-require
17-
const { Readable } = require('stream');
18-
// eslint-disable-next-line global-require
19-
const { ReadableStream, ReadableStreamDefaultReader } = require('stream/web');
20-
2119
// Mock the fetch function to return a ReadableStream instead of Node's Readable stream
2220
// This matches browser behavior where fetch responses have ReadableStream bodies
2321
// Node's fetch and polyfills like jest-fetch-mock return Node's Readable stream,

script/convert

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,8 @@ gsub_file_content(
5353
'"test:non-rsc": "jest tests --testPathIgnorePatterns=\".*(RSC|stream|' \
5454
'registerServerComponent|serverRenderReactComponent|SuspenseHydration).*\"",'
5555
)
56-
# Make test:rsc script do nothing
57-
gsub_file_content(
58-
"../packages/react-on-rails-pro/package.json",
59-
/"test:rsc": "(?:\\"|[^"])*",/,
60-
'"test:rsc": "exit 0",'
61-
)
56+
# test:rsc script now automatically detects React version and skips on React 18
57+
# No override needed - the script checks React version and exits cleanly if < 19
6258
# Keep modern JSX transform for React 18+
6359
# gsub_file_content("../tsconfig.json", "react-jsx", "react")
6460
# gsub_file_content("../spec/dummy/babel.config.js", "runtime: 'automatic'", "runtime: 'classic'")

0 commit comments

Comments
 (0)