1
- import { fileURLToPath } from 'url'
1
+ import { createRequire } from 'module'
2
+ import { fileURLToPath } from 'url'
2
3
3
- export { }
4
4
const __filename = fileURLToPath ( import . meta. url )
5
5
const main = async ( ) => {
6
6
const { default : t } = await import ( 'tap' )
@@ -9,32 +9,46 @@ const main = async () => {
9
9
// need to run both tests in parallel so we don't miss the close event
10
10
t . jobs = 3
11
11
12
- const warn = spawn ( process . execPath , [
13
- ...process . execArgv ,
14
- __filename ,
15
- 'child' ,
16
- ] )
12
+ const argv = process . execArgv . filter (
13
+ a => ! a . startsWith ( '--no-warnings' )
14
+ )
15
+ const warn = spawn (
16
+ process . execPath ,
17
+ [ ...argv , __filename , 'child' ] ,
18
+ {
19
+ env : {
20
+ ...process . env ,
21
+ NODE_OPTIONS : '' ,
22
+ } ,
23
+ }
24
+ )
17
25
const warnErr : Buffer [ ] = [ ]
18
26
warn . stderr . on ( 'data' , c => warnErr . push ( c ) )
19
27
20
28
const noWarn = spawn (
21
29
process . execPath ,
22
- [ ...process . execArgv , __filename , 'child' ] ,
30
+ [ ...argv , __filename , 'child' ] ,
23
31
{
24
32
env : {
25
33
...process . env ,
26
34
LRU_CACHE_IGNORE_AC_WARNING : '1' ,
35
+ NODE_OPTIONS : '' ,
27
36
} ,
28
37
}
29
38
)
30
39
const noWarnErr : Buffer [ ] = [ ]
31
40
noWarn . stderr . on ( 'data' , c => noWarnErr . push ( c ) )
32
41
33
- const noFetch = spawn ( process . execPath , [
34
- ...process . execArgv ,
35
- __filename ,
36
- 'child-no-fetch' ,
37
- ] )
42
+ const noFetch = spawn (
43
+ process . execPath ,
44
+ [ ...argv , __filename , 'child-no-fetch' ] ,
45
+ {
46
+ env : {
47
+ ...process . env ,
48
+ NODE_OPTIONS : '' ,
49
+ } ,
50
+ }
51
+ )
38
52
const noFetchErr : Buffer [ ] = [ ]
39
53
noFetch . stderr . on ( 'data' , c => noFetchErr . push ( c ) )
40
54
@@ -46,7 +60,10 @@ const main = async () => {
46
60
r ( )
47
61
} )
48
62
)
49
- t . equal ( Buffer . concat ( noWarnErr ) . toString ( ) . trim ( ) , '' )
63
+ t . notMatch (
64
+ Buffer . concat ( noWarnErr ) . toString ( ) . trim ( ) ,
65
+ 'NO_ABORT_CONTROLLER'
66
+ )
50
67
} )
51
68
52
69
t . test ( 'no warning (because no fetch)' , async t => {
@@ -57,7 +74,10 @@ const main = async () => {
57
74
r ( )
58
75
} )
59
76
)
60
- t . equal ( Buffer . concat ( noFetchErr ) . toString ( ) . trim ( ) , '' )
77
+ t . notMatch (
78
+ Buffer . concat ( noWarnErr ) . toString ( ) . trim ( ) ,
79
+ 'NO_ABORT_CONTROLLER'
80
+ )
61
81
} )
62
82
63
83
t . test ( 'warning' , async t => {
@@ -68,24 +88,29 @@ const main = async () => {
68
88
r ( )
69
89
} )
70
90
)
71
- t . not ( Buffer . concat ( warnErr ) . toString ( ) . trim ( ) , '' )
91
+ t . match (
92
+ Buffer . concat ( warnErr ) . toString ( ) . trim ( ) ,
93
+ / N O _ A B O R T _ C O N T R O L L E R /
94
+ )
72
95
} )
73
96
}
74
97
75
98
switch ( process . argv [ 2 ] ) {
76
99
case 'child' :
77
- //@ts -ignore
100
+ //@ts -expect-error
101
+ process . emitWarning = null
102
+ //@ts -expect-error
78
103
globalThis . AbortController = undefined
79
- //@ts -ignore
104
+ //@ts -expect-error
80
105
globalThis . AbortSignal = undefined
81
- import ( '../dist/esm/index.js' ) . then ( ( { LRUCache } ) => {
82
- new LRUCache ( { max : 1 , fetchMethod : async ( ) => 1 } ) . fetch ( 1 )
83
- } )
106
+ const req = createRequire ( import . meta . url )
107
+ const { LRUCache } = req ( '../dist/commonjs/index.js' )
108
+ new LRUCache ( { max : 1 , fetchMethod : async ( ) => 1 } ) . fetch ( 1 )
84
109
break
85
110
case 'child-no-fetch' :
86
- //@ts -ignore
111
+ //@ts -expect-error
87
112
globalThis . AbortController = undefined
88
- //@ts -ignore
113
+ //@ts -expect-error
89
114
globalThis . AbortSignal = undefined
90
115
import ( '../dist/esm/index.js' )
91
116
break
0 commit comments