@@ -6,69 +6,54 @@ import { installIndexedDBMock } from './test-utils/indexeddb-mock';
66
77// jsdom does not provide TextEncoder/TextDecoder globally; back them with Node's.
88if ( typeof globalThis . TextEncoder === 'undefined' ) {
9- globalThis . TextEncoder = TextEncoder ;
9+ globalThis . TextEncoder = TextEncoder ;
1010}
1111if ( typeof globalThis . TextDecoder === 'undefined' ) {
12- globalThis . TextDecoder = TextDecoder ;
12+ globalThis . TextDecoder = TextDecoder ;
1313}
1414
1515// jsdom does not implement the Web Crypto SubtleCrypto API; back it with Node's
1616// webcrypto so code paths that encrypt/decrypt (e.g. session storage) work.
1717if ( typeof globalThis . crypto === 'undefined' ) {
18- Object . defineProperty ( globalThis , 'crypto' , { value : webcrypto , configurable : true } ) ;
18+ Object . defineProperty ( globalThis , 'crypto' , { value : webcrypto , configurable : true } ) ;
1919} else if ( ! globalThis . crypto . subtle ) {
20- try {
21- Object . defineProperty ( globalThis . crypto , 'subtle' , { value : webcrypto . subtle , configurable : true } ) ;
22- } catch {
23- Object . defineProperty ( globalThis , 'crypto' , { value : webcrypto , configurable : true } ) ;
24- }
25- // Polyfill crypto.subtle and TextEncoder/TextDecoder for jsdom
26- if ( typeof globalThis . crypto !== 'undefined' && ! globalThis . crypto . subtle ) {
27- const { webcrypto } = require ( 'crypto' ) ;
28- Object . defineProperty ( globalThis , 'crypto' , {
29- value : webcrypto ,
30- writable : false ,
31- configurable : true ,
32- } ) ;
33- }
34- const { TextEncoder, TextDecoder } = require ( 'util' ) ;
35- if ( typeof globalThis . TextEncoder === 'undefined' ) {
36- globalThis . TextEncoder = TextEncoder ;
37- }
38- if ( typeof globalThis . TextDecoder === 'undefined' ) {
39- globalThis . TextDecoder = TextDecoder ;
20+ try {
21+ Object . defineProperty ( globalThis . crypto , 'subtle' , { value : webcrypto . subtle , configurable : true } ) ;
22+ } catch {
23+ Object . defineProperty ( globalThis , 'crypto' , { value : webcrypto , configurable : true } ) ;
24+ }
4025}
4126
4227// Mock File System Access API (showSaveFilePicker)
4328if ( typeof globalThis . window === 'undefined' ) {
44- // running in node - provide a minimal window and document
45- globalThis . window = globalThis ;
29+ // running in node - provide a minimal window and document
30+ globalThis . window = globalThis ;
4631}
4732
4833if ( ! ( 'showSaveFilePicker' in globalThis ) ) {
49- globalThis . showSaveFilePicker = async ( options = { } ) => {
50- const chunks = [ ] ;
51- return {
52- createWritable : async ( ) => ( {
53- write : async ( data ) => {
54- // accept Blob or write request
55- if ( data instanceof Blob ) {
56- const array = new Uint8Array ( await data . arrayBuffer ( ) ) ;
57- chunks . push ( array ) ;
58- } else if ( data && data . data instanceof Blob ) {
59- const array = new Uint8Array ( await data . data . arrayBuffer ( ) ) ;
60- chunks . push ( array ) ;
61- }
62- } ,
63- close : async ( ) => { } ,
64- } ) ,
65- } ;
66- } ;
34+ globalThis . showSaveFilePicker = async ( options = { } ) => {
35+ const chunks = [ ] ;
36+ return {
37+ createWritable : async ( ) => ( {
38+ write : async ( data ) => {
39+ // accept Blob or write request
40+ if ( data instanceof Blob ) {
41+ const array = new Uint8Array ( await data . arrayBuffer ( ) ) ;
42+ chunks . push ( array ) ;
43+ } else if ( data && data . data instanceof Blob ) {
44+ const array = new Uint8Array ( await data . data . arrayBuffer ( ) ) ;
45+ chunks . push ( array ) ;
46+ }
47+ } ,
48+ close : async ( ) => { } ,
49+ } ) ,
50+ } ;
51+ } ;
6752}
6853
6954// Install enhanced IndexedDB mock for tests
7055try {
71- installIndexedDBMock ( ) ;
56+ installIndexedDBMock ( ) ;
7257} catch ( e ) {
73- // ignore if already installed or environment prevents it
58+ // ignore if already installed or environment prevents it
7459}
0 commit comments