File tree 5 files changed +36
-5
lines changed
packages/vitest/src/integrations/env
5 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { importModule } from 'local-pkg'
2
2
import type { Environment } from '../../types'
3
3
import { populateGlobal } from './utils'
4
+ import { KEYS } from './jsdom-keys'
4
5
5
6
export default < Environment > ( {
6
7
name : 'edge-runtime' ,
@@ -29,6 +30,10 @@ export default <Environment>({
29
30
extend : ( context ) => {
30
31
context . global = context
31
32
context . Buffer = Buffer
33
+ KEYS . forEach ( ( key ) => {
34
+ if ( key in global )
35
+ context [ key ] = global [ key ]
36
+ } )
32
37
return context
33
38
} ,
34
39
} )
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ export default <Environment>({
14
14
15
15
// TODO: browser doesn't expose Buffer, but a lot of dependencies use it
16
16
win . Buffer = Buffer
17
- win . Uint8Array = Uint8Array
18
17
19
18
// inject structuredClone if it exists
20
19
if ( typeof structuredClone !== 'undefined' && ! win . structuredClone )
@@ -24,8 +23,8 @@ export default <Environment>({
24
23
getVmContext ( ) {
25
24
return win
26
25
} ,
27
- teardown ( ) {
28
- win . happyDOM . cancelAsync ( )
26
+ async teardown ( ) {
27
+ await win . happyDOM . cancelAsync ( )
29
28
} ,
30
29
}
31
30
} ,
Original file line number Diff line number Diff line change @@ -163,6 +163,16 @@ const LIVING_KEYS = [
163
163
'Headers' ,
164
164
'AbortController' ,
165
165
'AbortSignal' ,
166
+
167
+ 'Uint8Array' ,
168
+ 'Uint16Array' ,
169
+ 'Uint32Array' ,
170
+ 'Uint8ClampedArray' ,
171
+ 'Int8Array' ,
172
+ 'Int16Array' ,
173
+ 'Int32Array' ,
174
+ 'Float32Array' ,
175
+ 'Float64Array' ,
166
176
'ArrayBuffer' ,
167
177
'DOMRectReadOnly' ,
168
178
'DOMRect' ,
Original file line number Diff line number Diff line change @@ -68,8 +68,6 @@ export default <Environment>({
68
68
69
69
// TODO: browser doesn't expose Buffer, but a lot of dependencies use it
70
70
dom . window . Buffer = Buffer
71
- // Buffer extends Uint8Array
72
- dom . window . Uint8Array = Uint8Array
73
71
74
72
// inject structuredClone if it exists
75
73
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 () => {
164
164
expect ( arraybuffer . constructor === ArrayBuffer ) . toBeTruthy ( )
165
165
} )
166
166
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
+
167
186
it ( 'doesn\'t throw, if listening for error' , ( ) => {
168
187
const spy = vi . fn ( ( e : Event ) => e . preventDefault ( ) )
169
188
window . addEventListener ( 'error' , spy )
You can’t perform that action at this time.
0 commit comments