Skip to content

Commit

Permalink
fix: jest
Browse files Browse the repository at this point in the history
  • Loading branch information
vgorkavenko committed Feb 12, 2024
1 parent b22f982 commit e8b7442
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"moduleNameMapper": {
"^build-info$": "<rootDir>/build-info.json"
},
"setupFiles": ["<rootDir>/test/jest.polyfills.js"],
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
Expand Down
31 changes: 31 additions & 0 deletions test/jest.polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// jest.polyfills.js
/**
* @note The block below contains polyfills for Node.js globals
* required for Jest to function when running JSDOM tests.
* These HAVE to be require's and HAVE to be in this exact
* order, since "undici" depends on the "TextEncoder" global API.
*
* Consider migrating to a more modern test runner if
* you don't want to deal with this.
*/

const { TextDecoder, TextEncoder, ReadableStream } = require("node:util")

Object.defineProperties(globalThis, {
TextDecoder: { value: TextDecoder },
TextEncoder: { value: TextEncoder },
ReadableStream: { value: ReadableStream },
})

const { Blob, File } = require("node:buffer")
const { fetch, Headers, FormData, Request, Response } = require("undici")

Object.defineProperties(globalThis, {
fetch: { value: fetch, writable: true },
Blob: { value: Blob },
File: { value: File },
Headers: { value: Headers },
FormData: { value: FormData },
Request: { value: Request },
Response: { value: Response },
})

0 comments on commit e8b7442

Please sign in to comment.