@@ -5,32 +5,61 @@ process.noDeprecation = false
5
5
const warnings = [ ]
6
6
process . emitWarning = ( ...w ) => warnings . push ( w )
7
7
8
- const c = new LRU ( {
9
- max : 100 ,
10
- maxSize : 100 ,
11
- maxAge : 1000 ,
12
- stale : true ,
13
- length : n => 1 ,
14
- } )
15
- c . reset ( )
16
- t . equal ( c . length , 0 )
17
- t . equal ( c . prune , c . purgeStale )
18
- t . equal ( c . reset , c . clear )
19
- t . equal ( c . del , c . delete )
20
-
21
- t . matchSnapshot ( warnings )
22
-
23
- warnings . length = 0
24
- const d = new LRU ( {
25
- max : 100 ,
26
- maxSize : 100 ,
27
- maxAge : 1000 ,
28
- stale : true ,
29
- length : n => 1 ,
8
+ t . test ( 'warns exactly once for a given deprecation' , t => {
9
+ const c = new LRU ( {
10
+ max : 100 ,
11
+ maxSize : 100 ,
12
+ maxAge : 1000 ,
13
+ stale : true ,
14
+ length : n => 1 ,
15
+ } )
16
+ c . reset ( )
17
+ t . equal ( c . length , 0 )
18
+ t . equal ( c . prune , c . purgeStale )
19
+ t . equal ( c . reset , c . clear )
20
+ t . equal ( c . del , c . delete )
21
+
22
+ t . matchSnapshot ( warnings )
23
+
24
+ warnings . length = 0
25
+ const d = new LRU ( {
26
+ max : 100 ,
27
+ maxSize : 100 ,
28
+ maxAge : 1000 ,
29
+ stale : true ,
30
+ length : n => 1 ,
31
+ } )
32
+ d . reset ( )
33
+
34
+ t . equal ( d . length , 0 )
35
+ t . equal ( d . prune , d . purgeStale )
36
+ t . equal ( d . reset , d . clear )
37
+ t . strictSame ( warnings , [ ] , 'only warn once' )
38
+
39
+ warnings . length = 0
40
+ t . end ( )
30
41
} )
31
- d . reset ( )
32
42
33
- t . equal ( d . length , 0 )
34
- t . equal ( d . prune , d . purgeStale )
35
- t . equal ( d . reset , d . clear )
36
- t . strictSame ( warnings , [ ] , 'only warn once' )
43
+ t . test ( 'does not do deprecation warning without process object' , t => {
44
+ // set process to null (emulate a browser)
45
+ const proc = process
46
+ t . teardown ( ( ) => global . process = proc )
47
+ global . process = null
48
+
49
+ const c = new LRU ( {
50
+ max : 100 ,
51
+ maxSize : 100 ,
52
+ maxAge : 1000 ,
53
+ stale : true ,
54
+ length : n => 1 ,
55
+ } )
56
+ c . reset ( )
57
+ t . equal ( c . length , 0 )
58
+ t . equal ( c . prune , c . purgeStale )
59
+ t . equal ( c . reset , c . clear )
60
+ t . equal ( c . del , c . delete )
61
+
62
+ t . strictSame ( warnings , [ ] , 'no process exists' )
63
+
64
+ t . end ( )
65
+ } )
0 commit comments