Skip to content

Commit 37ac0ea

Browse files
authored
test(monorepo): update MSW and other dependencies to latest (#1629)
1 parent 4e1d279 commit 37ac0ea

File tree

30 files changed

+900
-554
lines changed

30 files changed

+900
-554
lines changed

jest.preset.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module.exports = {
7474
},
7575
setupFilesAfterEnv: ['../../jest/jest.setup-dom.js'],
7676
setupFiles: ['core-js', 'jest-date-mock', '../../jest/jest.polyfills.js'],
77-
testEnvironment: 'jest-environment-jsdom',
77+
testEnvironment: '../../jest/jsdom-extended.js',
7878
testRunner: 'jest-circus/runner',
7979
cacheDirectory: '../../node_modules/.cache/unit-tests',
8080
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],

jest/jest.polyfills.js

-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable import/no-extraneous-dependencies */
2-
31
require('isomorphic-fetch');
42

53
// Mocking Math random
@@ -18,7 +16,3 @@ console.warn = jest.fn();
1816
console.error = jest.fn();
1917
// Mock browsers sendBeacon utility
2018
navigator.sendBeacon = jest.fn();
21-
22-
import { TextEncoder, TextDecoder } from 'util';
23-
24-
Object.assign(global, { TextDecoder, TextEncoder });

jest/jsdom-extended.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import JSDOMEnvironment from 'jest-environment-jsdom';
2+
3+
// Adding relevant polyfilled extensions in the JSDOm to have msw v2 working
4+
// More on: https://github.com/mswjs/msw/issues/1916#issuecomment-1919965699
5+
class JSDOMEnvironmentExtended extends JSDOMEnvironment {
6+
constructor(...args) {
7+
super(...args);
8+
9+
this.global.ReadableStream = ReadableStream;
10+
this.global.TextDecoder = TextDecoder;
11+
this.global.TextEncoder = TextEncoder;
12+
13+
this.global.Blob = Blob;
14+
this.global.File = File;
15+
this.global.Headers = Headers;
16+
this.global.FormData = FormData;
17+
this.global.Request = Request;
18+
this.global.Response = Response;
19+
this.global.Request = Request;
20+
this.global.Response = Response;
21+
this.global.fetch = fetch;
22+
this.global.structuredClone = structuredClone;
23+
}
24+
}
25+
26+
module.exports = JSDOMEnvironmentExtended;

0 commit comments

Comments
 (0)