diff --git a/package-lock.json b/package-lock.json index 3578ca89..5e04c8e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -106,8 +106,7 @@ "sass-loader": "^13.3.2", "stylelint": "15.11.0", "ts-jest": "^27.0.7", - "typescript": "^4.5.2", - "web-streams-polyfill": "4.0.0" + "typescript": "^4.5.2" }, "peerDependencies": { "@diplodoc/cut-extension": "^0.3.1", @@ -28587,15 +28586,6 @@ "defaults": "^1.0.3" } }, - "node_modules/web-streams-polyfill": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0.tgz", - "integrity": "sha512-0zJXHRAYEjM2tUfZ2DiSOHAa2aw1tisnnhU3ufD57R8iefL+DcdJyRBRyJpG+NUimDgbTI/lH+gAE1PAvV3Cgw==", - "dev": true, - "engines": { - "node": ">= 8" - } - }, "node_modules/web-worker": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.3.0.tgz", diff --git a/package.json b/package.json index abbdb117..7f71b1d9 100644 --- a/package.json +++ b/package.json @@ -254,8 +254,7 @@ "sass-loader": "^13.3.2", "stylelint": "15.11.0", "ts-jest": "^27.0.7", - "typescript": "^4.5.2", - "web-streams-polyfill": "4.0.0" + "typescript": "^4.5.2" }, "peerDependenciesMeta": { "@diplodoc/folding-headings-extension": { diff --git a/tests/pollyfills.ts b/tests/pollyfills.ts new file mode 100644 index 00000000..03853a3e --- /dev/null +++ b/tests/pollyfills.ts @@ -0,0 +1,30 @@ +/* eslint-disable @typescript-eslint/no-redeclare */ +import {Blob} from 'node:buffer'; +import {ReadableStream} from 'node:stream/web'; +import {TextDecoder, TextEncoder} from 'node:util'; + +Object.assign(global, {Blob, ReadableStream, TextDecoder, TextEncoder}); + +// fix from https://github.com/jsdom/jsdom/issues/3002 +document.createRange = () => { + const range = new Range(); + range.getBoundingClientRect = () => ({ + x: 0, + y: 0, + width: 0, + height: 0, + top: 0, + right: 0, + bottom: 0, + left: 0, + toJSON() { + return JSON.stringify(this); + }, + }); + range.getClientRects = () => ({ + length: 0, + item: () => null, + [Symbol.iterator]: jest.fn(), + }); + return range; +}; diff --git a/tests/setup.ts b/tests/setup.ts index 444f4df3..dc40722b 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -1,33 +1,2 @@ -import {TextDecoder as TextDecoderUtil, TextEncoder as TextEncoderUtil} from 'util'; - -import {ReadableStream as ReadableStreamPolyfill} from 'web-streams-polyfill'; - +import './pollyfills'; import './toMatchNode'; - -global.TextDecoder = TextDecoderUtil as any; // TS error in global.TextDecoder -global.TextEncoder = TextEncoderUtil; -global.ReadableStream = ReadableStreamPolyfill; - -// fix from https://github.com/jsdom/jsdom/issues/3002 -document.createRange = () => { - const range = new Range(); - range.getBoundingClientRect = () => ({ - x: 0, - y: 0, - width: 0, - height: 0, - top: 0, - right: 0, - bottom: 0, - left: 0, - toJSON() { - return JSON.stringify(this); - }, - }); - range.getClientRects = () => ({ - length: 0, - item: () => null, - [Symbol.iterator]: jest.fn(), - }); - return range; -};