From 6118840a4af6b4e7120754555c01b8d41436625b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 30 Oct 2024 12:37:09 +0300 Subject: Fix test environments --- jest.config.js | 2 +- setupTests.js | 22 ++++++++++++---------- vnext/server/middleware/android.spec.js | 4 ++++ vnext/server/middleware/mastodon.spec.js | 4 ++++ vnext/server/middleware/webfinger.spec.js | 4 ++++ 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/jest.config.js b/jest.config.js index 69b061e1..abaffdbd 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,6 +8,6 @@ module.exports = { '^.+\\.js$': '@swc/jest' }, transformIgnorePatterns: ['!node_modules/'], - testEnvironment: 'node', + testEnvironment: 'jsdom', setupFilesAfterEnv: ['/setupTests.js'] } diff --git a/setupTests.js b/setupTests.js index 1b4e29f8..7658559c 100644 --- a/setupTests.js +++ b/setupTests.js @@ -1,14 +1,16 @@ import '@testing-library/jest-dom' -window.matchMedia = window.matchMedia || function() { - return { - matches: true, - media: '', - addListener: function() { return true }, - removeListener: function() { return true }, - addEventListener: function() { return true }, - removeEventListener: function() { return true }, - dispatchEvent: function() { return true }, - onchange: function() { return true } +if (typeof window !== 'undefined') { + window.matchMedia = window.matchMedia || function() { + return { + matches: true, + media: '', + addListener: function() { return true }, + removeListener: function() { return true }, + addEventListener: function() { return true }, + removeEventListener: function() { return true }, + dispatchEvent: function() { return true }, + onchange: function() { return true } + } } } diff --git a/vnext/server/middleware/android.spec.js b/vnext/server/middleware/android.spec.js index 19d380d7..f5b9792a 100644 --- a/vnext/server/middleware/android.spec.js +++ b/vnext/server/middleware/android.spec.js @@ -1,3 +1,7 @@ +/** + * @jest-environment node + */ + import request from 'supertest' import { app } from '../app' diff --git a/vnext/server/middleware/mastodon.spec.js b/vnext/server/middleware/mastodon.spec.js index 561303bc..7f30d027 100644 --- a/vnext/server/middleware/mastodon.spec.js +++ b/vnext/server/middleware/mastodon.spec.js @@ -1,3 +1,7 @@ +/** + * @jest-environment node + */ + import request from 'supertest' import { app } from '../app' diff --git a/vnext/server/middleware/webfinger.spec.js b/vnext/server/middleware/webfinger.spec.js index d1b198e6..c36c4571 100644 --- a/vnext/server/middleware/webfinger.spec.js +++ b/vnext/server/middleware/webfinger.spec.js @@ -1,3 +1,7 @@ +/** + * @jest-environment node + */ + import request from 'supertest' import { app } from '../app' -- cgit v1.2.3