1
1
import process from 'node:process' ;
2
2
import { inherits } from 'node:util' ;
3
- import clearModule from 'clear-module' ;
4
3
import FixtureStdout from 'fixture-stdout' ;
5
4
import stripAnsi from 'strip-ansi' ;
6
5
import test from 'ava' ;
7
- import mock from 'mock-require ' ;
6
+ import esmock from 'esmock ' ;
8
7
9
8
const stderr = new FixtureStdout ( {
10
9
stream : process . stderr ,
@@ -20,16 +19,12 @@ function Control(shouldNotifyInNpmScript) {
20
19
}
21
20
22
21
const setupTest = async isNpmReturnValue => {
23
- for ( const name of [ '..' , 'is-npm' ] ) {
24
- clearModule ( name ) ;
25
- }
26
-
27
22
process . stdout . isTTY = true ;
28
23
29
- // TODO: Switch to https://github.com/iambumblehead/esmock
30
- mock ( 'is-npm' , { isNpmOrYarn : isNpmReturnValue || false } ) ;
24
+ const UpdateNotifier = await esmock ( '../update-notifier.js' , {
25
+ 'is-npm' : { isNpmOrYarn : isNpmReturnValue || false } ,
26
+ } ) ;
31
27
32
- const { default : UpdateNotifier } = await import ( '../update-notifier.js' ) ;
33
28
inherits ( Control , UpdateNotifier ) ;
34
29
} ;
35
30
@@ -45,12 +40,11 @@ test.beforeEach(async () => {
45
40
} ) ;
46
41
47
42
test . afterEach ( ( ) => {
48
- mock . stopAll ( ) ;
49
43
stderr . release ( ) ;
50
44
errorLogs = '' ;
51
45
} ) ;
52
46
53
- test . failing ( 'use pretty boxen message by default' , t => {
47
+ test ( 'use pretty boxen message by default' , t => {
54
48
const notifier = new Control ( ) ;
55
49
notifier . notify ( { defer : false , isGlobal : true } ) ;
56
50
@@ -67,7 +61,7 @@ test.failing('use pretty boxen message by default', t => {
67
61
` ) ;
68
62
} ) ;
69
63
70
- test . failing ( 'supports custom message' , t => {
64
+ test ( 'supports custom message' , t => {
71
65
const notifier = new Control ( ) ;
72
66
notifier . notify ( {
73
67
defer : false ,
@@ -78,7 +72,7 @@ test.failing('supports custom message', t => {
78
72
t . true ( stripAnsi ( errorLogs ) . includes ( 'custom message' ) ) ;
79
73
} ) ;
80
74
81
- test . failing ( 'supports message with placeholders' , t => {
75
+ test ( 'supports message with placeholders' , t => {
82
76
const notifier = new Control ( ) ;
83
77
notifier . notify ( {
84
78
defer : false ,
@@ -104,42 +98,42 @@ test.failing('supports message with placeholders', t => {
104
98
` ) ;
105
99
} ) ;
106
100
107
- test . failing ( 'exclude -g argument when `isGlobal` option is `false`' , t => {
101
+ test ( 'exclude -g argument when `isGlobal` option is `false`' , t => {
108
102
const notifier = new Control ( ) ;
109
103
notifier . notify ( { defer : false , isGlobal : false } ) ;
110
104
t . not ( stripAnsi ( errorLogs ) . indexOf ( 'Run npm i update-notifier-tester to update' ) , - 1 ) ;
111
105
} ) ;
112
106
113
- test . failing ( 'shouldNotifyInNpmScript should default to false' , t => {
107
+ test ( 'shouldNotifyInNpmScript should default to false' , t => {
114
108
const notifier = new Control ( ) ;
115
109
notifier . notify ( { defer : false } ) ;
116
110
t . not ( stripAnsi ( errorLogs ) . indexOf ( 'Update available' ) , - 1 ) ;
117
111
} ) ;
118
112
119
- test ( 'suppress output when running as npm script' , t => {
120
- setupTest ( true ) ;
113
+ test ( 'suppress output when running as npm script' , async t => {
114
+ await setupTest ( true ) ;
121
115
const notifier = new Control ( ) ;
122
116
notifier . notify ( { defer : false } ) ;
123
117
t . false ( stripAnsi ( errorLogs ) . includes ( 'Update available' ) ) ;
124
118
} ) ;
125
119
126
- test ( 'should output if running as npm script and shouldNotifyInNpmScript option set' , t => {
127
- setupTest ( true ) ;
120
+ test ( 'should output if running as npm script and shouldNotifyInNpmScript option set' , async t => {
121
+ await setupTest ( true ) ;
128
122
const notifier = new Control ( true ) ;
129
123
notifier . notify ( { defer : false } ) ;
130
124
t . true ( stripAnsi ( errorLogs ) . includes ( 'Update available' ) ) ;
131
125
} ) ;
132
126
133
- test ( 'should not output if current version is the latest' , t => {
134
- setupTest ( true ) ;
127
+ test ( 'should not output if current version is the latest' , async t => {
128
+ await setupTest ( true ) ;
135
129
const notifier = new Control ( true ) ;
136
130
notifier . update . current = '1.0.0' ;
137
131
notifier . notify ( { defer : false } ) ;
138
132
t . false ( stripAnsi ( errorLogs ) . includes ( 'Update available' ) ) ;
139
133
} ) ;
140
134
141
- test ( 'should not output if current version is more recent than the reported latest' , t => {
142
- setupTest ( true ) ;
135
+ test ( 'should not output if current version is more recent than the reported latest' , async t => {
136
+ await setupTest ( true ) ;
143
137
const notifier = new Control ( true ) ;
144
138
notifier . update . current = '1.0.1' ;
145
139
notifier . notify ( { defer : false } ) ;
0 commit comments