@@ -4,18 +4,16 @@ import { stripVTControlCharacters } from 'node:util'
4
4
import { processError } from '@vitest/utils/error'
5
5
import { expect , test } from 'vitest'
6
6
7
- const nodeMajor = Number ( process . version . slice ( 1 ) . split ( '.' ) [ 0 ] )
8
-
9
- test . runIf ( nodeMajor >= 15 ) ( 'MessageChannel and MessagePort are available' , ( ) => {
7
+ test ( 'MessageChannel and MessagePort are available' , ( ) => {
10
8
expect ( MessageChannel ) . toBeDefined ( )
11
9
expect ( MessagePort ) . toBeDefined ( )
12
10
} )
13
11
14
- test . runIf ( nodeMajor >= 17 ) ( 'structuredClone is available' , ( ) => {
12
+ test ( 'structuredClone is available' , ( ) => {
15
13
expect ( structuredClone ) . toBeDefined ( )
16
14
} )
17
15
18
- test . runIf ( nodeMajor >= 18 ) ( 'fetch, Request, Response, and BroadcastChannel are available' , ( ) => {
16
+ test ( 'fetch, Request, Response, and BroadcastChannel are available' , ( ) => {
19
17
expect ( fetch ) . toBeDefined ( )
20
18
expect ( Request ) . toBeDefined ( )
21
19
expect ( Response ) . toBeDefined ( )
@@ -24,6 +22,24 @@ test.runIf(nodeMajor >= 18)('fetch, Request, Response, and BroadcastChannel are
24
22
expect ( BroadcastChannel ) . toBeDefined ( )
25
23
} )
26
24
25
+ test ( 'Fetch API accepts other APIs' , ( ) => {
26
+ expect . soft ( ( ) => new Request ( 'http://localhost' , { signal : new AbortController ( ) . signal } ) ) . not . toThrowError ( )
27
+ expect . soft ( ( ) => new Request ( 'http://localhost' , { method : 'POST' , body : new FormData ( ) } ) ) . not . toThrowError ( )
28
+ expect . soft ( ( ) => new Request ( 'http://localhost' , { method : 'POST' , body : new Blob ( ) } ) ) . not . toThrowError ( )
29
+ expect . soft ( ( ) => new Request ( new URL ( 'https://localhost' ) ) ) . not . toThrowError ( )
30
+
31
+ const request = new Request ( 'http://localhost' )
32
+ expect . soft ( request . headers ) . toBeInstanceOf ( Headers )
33
+
34
+ expect . soft (
35
+ ( ) => new Request ( 'http://localhost' , { method : 'POST' , body : new URLSearchParams ( [ [ 'key' , 'value' ] ] ) } ) ,
36
+ ) . not . toThrowError ( )
37
+
38
+ const searchParams = new URLSearchParams ( )
39
+ searchParams . set ( 'key' , 'value' )
40
+ expect . soft ( ( ) => new Request ( 'http://localhost' , { method : 'POST' , body : searchParams } ) ) . not . toThrowError ( )
41
+ } )
42
+
27
43
test ( 'atob and btoa are available' , ( ) => {
28
44
expect ( atob ( 'aGVsbG8gd29ybGQ=' ) ) . toBe ( 'hello world' )
29
45
expect ( btoa ( 'hello world' ) ) . toBe ( 'aGVsbG8gd29ybGQ=' )
0 commit comments