From da04d7c7184e3de8571f34a6f1063341fa37767b Mon Sep 17 00:00:00 2001 From: Nils Ingwersen Date: Wed, 16 Oct 2024 16:56:20 +0200 Subject: [PATCH] refactor: changed back to @strapi/admin-test-utils/environment testEnvironment and removed jest-fixed-jsdom --- jest-preset.front.js | 2 +- package.json | 1 - packages/admin-test-utils/src/environment.ts | 14 ++++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/jest-preset.front.js b/jest-preset.front.js index a554b64ad28..981abb8d562 100644 --- a/jest-preset.front.js +++ b/jest-preset.front.js @@ -29,7 +29,7 @@ module.exports = { globalSetup: '@strapi/admin-test-utils/global-setup', setupFiles: ['@strapi/admin-test-utils/setup'], setupFilesAfterEnv: ['@strapi/admin-test-utils/after-env'], - testEnvironment: 'jest-fixed-jsdom', + testEnvironment: '@strapi/admin-test-utils/environment', prettierPath: require.resolve('prettier-2'), transform: { '^.+\\.js(x)?$': [ diff --git a/package.json b/package.json index c7f35ecd109..cc3e8e3af2f 100644 --- a/package.json +++ b/package.json @@ -134,7 +134,6 @@ "jest-circus": "29.6.0", "jest-cli": "29.6.0", "jest-environment-jsdom": "29.6.1", - "jest-fixed-jsdom": "0.0.4", "jest-watch-typeahead": "2.2.2", "lerna": "8.1.2", "lint-staged": "15.2.10", diff --git a/packages/admin-test-utils/src/environment.ts b/packages/admin-test-utils/src/environment.ts index dbb2504ef20..ca34766e735 100644 --- a/packages/admin-test-utils/src/environment.ts +++ b/packages/admin-test-utils/src/environment.ts @@ -11,5 +11,19 @@ export default class CustomJSDOMEnvironment extends JSDOMEnvironment { // TODO: remove once https://github.com/jsdom/jsdom/issues/3363 is closed. this.global.structuredClone = structuredClone; + + // fixing these global APIs according to https://github.com/mswjs/jest-fixed-jsdom/blob/main/index.js + this.global.TextDecoder = TextDecoder; + this.global.TextEncoder = TextEncoder; + this.global.ReadableStream = ReadableStream; + + this.global.Blob = Blob; + this.global.Headers = Headers; + this.global.FormData = FormData; + this.global.Request = Request; + this.global.Response = Response; + this.global.fetch = fetch; + + this.global.URL = URL; } }