Skip to content

Commit dcc32be

Browse files
Test fetch function only with node version 18+
1 parent dc0c0c3 commit dcc32be

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

node_package/tests/RSCClientRoot.test.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ import { render, screen, act } from '@testing-library/react';
1414
import '@testing-library/jest-dom';
1515
import path from 'path';
1616
import fs from 'fs';
17-
import { createNodeReadableStream } from './testUtils';
17+
import { createNodeReadableStream, getNodeVersion } from './testUtils';
1818

1919
import RSCClientRoot, { resetRenderCache } from '../src/RSCClientRoot';
2020

2121
enableFetchMocks();
2222

23-
const nodeVersion = parseInt(process.version.slice(1), 10);
24-
2523
// React Server Components tests are not compatible with Experimental React 18 and React 19
2624
// That only run with node version 18 and above
27-
(nodeVersion >= 18 ? describe : describe.skip)('RSCClientRoot', () => {
25+
(getNodeVersion() >= 18 ? describe : describe.skip)('RSCClientRoot', () => {
2826
beforeEach(() => {
2927
jest.clearAllMocks();
3028

node_package/tests/testUtils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { Readable } from 'stream';
88
* push: (chunk: any) => void
99
* }} Object containing the stream and push function
1010
*/
11-
// eslint-disable-next-line import/prefer-default-export
1211
export const createNodeReadableStream = () => {
1312
const pendingChunks = [];
1413
let pushFn;
@@ -31,3 +30,5 @@ export const createNodeReadableStream = () => {
3130

3231
return { stream, push };
3332
};
33+
34+
export const getNodeVersion = () => parseInt(process.version.slice(1), 10);

node_package/tests/utils.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { enableFetchMocks } from 'jest-fetch-mock';
22

33
import { fetch } from '../src/utils';
4-
import { createNodeReadableStream } from './testUtils';
4+
import { createNodeReadableStream, getNodeVersion } from './testUtils';
55

66
enableFetchMocks();
77

8-
describe('fetch', () => {
8+
// The fetch mock functionality that returns a ReadableStream is not supported in Node.js v16.
9+
// Additionally, fetch function is used in RSCClientRoot only that is compatible with Node.js v18+,
10+
// so these tests are conditionally skipped on older Node versions.
11+
(getNodeVersion() >= 18 ? describe : describe.skip)('fetch', () => {
912
it('streams body as ReadableStream', async () => {
1013
// create Readable stream that emits 5 chunks with 10ms delay between each chunk
1114
const { stream, push } = createNodeReadableStream();

0 commit comments

Comments
 (0)