File tree Expand file tree Collapse file tree 5 files changed +36
-5
lines changed
packages/vitest/src/integrations/env Expand file tree Collapse file tree 5 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 11import { importModule } from 'local-pkg'
22import type { Environment } from '../../types'
33import { populateGlobal } from './utils'
4+ import { KEYS } from './jsdom-keys'
45
56export default < Environment > ( {
67 name : 'edge-runtime' ,
@@ -29,6 +30,10 @@ export default <Environment>({
2930 extend : ( context ) => {
3031 context . global = context
3132 context . Buffer = Buffer
33+ KEYS . forEach ( ( key ) => {
34+ if ( key in global )
35+ context [ key ] = global [ key ]
36+ } )
3237 return context
3338 } ,
3439 } )
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ export default <Environment>({
1414
1515 // TODO: browser doesn't expose Buffer, but a lot of dependencies use it
1616 win . Buffer = Buffer
17- win . Uint8Array = Uint8Array
1817
1918 // inject structuredClone if it exists
2019 if ( typeof structuredClone !== 'undefined' && ! win . structuredClone )
@@ -24,8 +23,8 @@ export default <Environment>({
2423 getVmContext ( ) {
2524 return win
2625 } ,
27- teardown ( ) {
28- win . happyDOM . cancelAsync ( )
26+ async teardown ( ) {
27+ await win . happyDOM . cancelAsync ( )
2928 } ,
3029 }
3130 } ,
Original file line number Diff line number Diff line change @@ -163,6 +163,16 @@ const LIVING_KEYS = [
163163 'Headers' ,
164164 'AbortController' ,
165165 'AbortSignal' ,
166+
167+ 'Uint8Array' ,
168+ 'Uint16Array' ,
169+ 'Uint32Array' ,
170+ 'Uint8ClampedArray' ,
171+ 'Int8Array' ,
172+ 'Int16Array' ,
173+ 'Int32Array' ,
174+ 'Float32Array' ,
175+ 'Float64Array' ,
166176 'ArrayBuffer' ,
167177 'DOMRectReadOnly' ,
168178 'DOMRect' ,
Original file line number Diff line number Diff line change @@ -68,8 +68,6 @@ export default <Environment>({
6868
6969 // TODO: browser doesn't expose Buffer, but a lot of dependencies use it
7070 dom . window . Buffer = Buffer
71- // Buffer extends Uint8Array
72- dom . window . Uint8Array = Uint8Array
7371
7472 // inject structuredClone if it exists
7573 if ( typeof structuredClone !== 'undefined' && ! dom . window . structuredClone )
Original file line number Diff line number Diff line change @@ -164,6 +164,25 @@ it('uses jsdom ArrayBuffer', async () => {
164164 expect ( arraybuffer . constructor === ArrayBuffer ) . toBeTruthy ( )
165165} )
166166
167+ it . each ( [
168+ 'Uint8Array' ,
169+ 'Uint16Array' ,
170+ 'Uint32Array' ,
171+ 'Uint8ClampedArray' ,
172+ 'Int16Array' ,
173+ 'Int32Array' ,
174+ 'Int8Array' ,
175+ 'Float32Array' ,
176+ 'Float64Array' ,
177+ ] as const ) ( '%s has buffer as ArrayBuffer' , async ( constructorName ) => {
178+ const Constructor = globalThis [ constructorName ]
179+ const typedArray = new Constructor ( [ 1 ] )
180+ expect ( typedArray . constructor . name ) . toBe ( constructorName )
181+ expect ( typedArray instanceof Constructor ) . toBeTruthy ( )
182+ expect ( ArrayBuffer . isView ( typedArray ) ) . toBeTruthy ( )
183+ expect ( typedArray . buffer instanceof ArrayBuffer ) . toBeTruthy ( )
184+ } )
185+
167186it ( 'doesn\'t throw, if listening for error' , ( ) => {
168187 const spy = vi . fn ( ( e : Event ) => e . preventDefault ( ) )
169188 window . addEventListener ( 'error' , spy )
You can’t perform that action at this time.
0 commit comments