-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsdom-extended.js
35 lines (31 loc) · 1.09 KB
/
jsdom-extended.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* eslint-disable @typescript-eslint/no-var-requires */
// eslint-disable-next-line import/no-extraneous-dependencies
const JSDOMEnvironment = require("jest-environment-jsdom").default;
const { Blob, File } = require("node:buffer");
/**
*
* This is a superset of the JSDOM environment for Jest that respects Node.js globals.
* It extends JSDOM environment to include what we need to run our tests.
*/
class JSDOMEnvironmentExtended extends JSDOMEnvironment {
constructor(...args) {
super(...args);
this.global.ReadableStream = ReadableStream;
this.global.TextDecoder = TextDecoder;
this.global.TextEncoder = TextEncoder;
this.global.Blob = Blob;
this.global.File = File;
this.global.Headers = Headers;
this.global.FormData = FormData;
this.global.Request = Request;
this.global.Response = Response;
this.global.Request = Request;
this.global.Response = Response;
Object.defineProperty(this.global, "fetch", {
value: fetch,
writable: true,
});
this.global.structuredClone = structuredClone;
}
}
module.exports = JSDOMEnvironmentExtended;