Skip to content

Commit 97b447f

Browse files
committed
internal: Ensure jsdom test env has modern globals
1 parent 70eb3e0 commit 97b447f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

docs/core/guides/unit-testing-hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ to `renderDataHook()` will result in a completely fresh cache state as well as m
3838

3939
:::
4040

41-
### Polyfill fetch in node
41+
### Polyfill fetch in node < 18
4242

4343
Node doesn't come with fetch out of the box, so we need to be sure to polyfill it.
4444

scripts/testSetup.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,24 @@ require('core-js/stable');
33
window.requestIdleCallback = jest.fn().mockImplementation(cb => {
44
cb();
55
});
6+
if (!globalThis.TextEncoder || !globalThis.TextDecoder) {
7+
const { TextDecoder, TextEncoder } = require('node:util');
8+
globalThis.TextEncoder = TextEncoder;
9+
globalThis.TextDecoder = TextDecoder;
10+
}
11+
12+
if (!globalThis.ReadableStream || !globalThis.WritableStream) {
13+
const { ReadableStream, WritableStream } = require('node:stream/web');
14+
globalThis.ReadableStream = ReadableStream;
15+
globalThis.WritableStream = WritableStream;
16+
}
17+
18+
if (!globalThis.TextEncoderStream) {
19+
const { TextEncoderStream } = require('node:stream/web');
20+
globalThis.TextEncoderStream = TextEncoderStream;
21+
}
22+
23+
if (!globalThis.TransformStream) {
24+
const { TransformStream } = require('node:stream/web');
25+
globalThis.TransformStream = TransformStream;
26+
}

0 commit comments

Comments
 (0)