@@ -9,13 +9,16 @@ describe('Unit: Commands > Doctor', function () {
9
9
it ( 'doesn\'t do anything if there are no checks to run (with log)' , function ( ) {
10
10
const listrStub = sinon . stub ( ) . resolves ( ) ;
11
11
const logStub = sinon . stub ( ) ;
12
+ const hookStub = sinon . stub ( ) . resolves ( [ ] ) ;
12
13
const DoctorCommand = proxyquire ( modulePath , {
13
14
'./checks' : [ ]
14
15
} ) ;
15
- const instance = new DoctorCommand ( { listr : listrStub , log : logStub } , { } ) ;
16
+ const instance = new DoctorCommand ( { listr : listrStub , log : logStub } , { hook : hookStub } ) ;
16
17
17
18
return instance . run ( { } ) . then ( ( ) => {
18
19
expect ( listrStub . called ) . to . be . false ;
20
+ expect ( hookStub . calledOnce ) . to . be . true ;
21
+ expect ( hookStub . calledWithExactly ( 'doctor' ) ) . to . be . true ;
19
22
expect ( logStub . calledOnce ) . to . be . true ;
20
23
expect ( logStub . args [ 0 ] [ 0 ] ) . to . equal ( 'No checks found to run.' ) ;
21
24
} ) ;
@@ -24,36 +27,48 @@ describe('Unit: Commands > Doctor', function () {
24
27
it ( 'doesn\'t do anything if there are no checks to run (with log + specific categories)' , function ( ) {
25
28
const listrStub = sinon . stub ( ) . resolves ( ) ;
26
29
const logStub = sinon . stub ( ) ;
30
+ const hookStub = sinon . stub ( ) . resolves ( [ ] ) ;
27
31
const DoctorCommand = proxyquire ( modulePath , {
28
32
'./checks' : [ ]
29
33
} ) ;
30
- const instance = new DoctorCommand ( { listr : listrStub , log : logStub } , { } ) ;
34
+ const instance = new DoctorCommand ( { listr : listrStub , log : logStub } , { hook : hookStub } ) ;
31
35
32
36
return instance . run ( { categories : [ 'testing' , 'validity' ] } ) . then ( ( ) => {
33
37
expect ( listrStub . called ) . to . be . false ;
34
38
expect ( logStub . calledOnce ) . to . be . true ;
39
+ expect ( hookStub . calledOnce ) . to . be . true ;
40
+ expect ( hookStub . calledWithExactly ( 'doctor' ) ) . to . be . true ;
35
41
expect ( logStub . args [ 0 ] [ 0 ] ) . to . equal ( 'No checks found to run for categories "testing, validity".' ) ;
36
42
} ) ;
37
43
} ) ;
38
44
39
45
it ( 'doesn\'t do anything if there are no checks to run (without log)' , function ( ) {
40
46
const listrStub = sinon . stub ( ) . resolves ( ) ;
41
47
const logStub = sinon . stub ( ) ;
48
+ const hookStub = sinon . stub ( ) . resolves ( [ ] ) ;
42
49
const DoctorCommand = proxyquire ( modulePath , {
43
50
'./checks' : [ ]
44
51
} ) ;
45
- const instance = new DoctorCommand ( { listr : listrStub , log : logStub } , { } ) ;
52
+ const instance = new DoctorCommand ( { listr : listrStub , log : logStub } , { hook : hookStub } ) ;
46
53
47
54
return instance . run ( { quiet : true } ) . then ( ( ) => {
48
55
expect ( listrStub . called ) . to . be . false ;
56
+ expect ( hookStub . calledOnce ) . to . be . true ;
57
+ expect ( hookStub . calledWithExactly ( 'doctor' ) ) . to . be . true ;
49
58
expect ( logStub . called ) . to . be . false ;
50
59
} ) ;
51
60
} ) ;
52
61
53
62
it ( 'checks instance if skipInstanceCheck not passed, uses correct context' , function ( ) {
54
63
const ui = { listr : sinon . stub ( ) . resolves ( ) } ;
55
64
const instanceStub = { checkEnvironment : sinon . stub ( ) } ;
56
- const system = { getInstance : sinon . stub ( ) . returns ( instanceStub ) } ;
65
+ const system = {
66
+ getInstance : sinon . stub ( ) . returns ( instanceStub ) ,
67
+ hook : sinon . stub ( ) . resolves ( [ {
68
+ title : 'Extension Task 1' ,
69
+ task : 'someTask'
70
+ } ] )
71
+ } ;
57
72
const checkValidStub = sinon . stub ( ) ;
58
73
59
74
const DoctorCommand = proxyquire ( modulePath , {
@@ -65,9 +80,17 @@ describe('Unit: Commands > Doctor', function () {
65
80
return instance . run ( { test : true , a : 'b' } ) . then ( ( ) => {
66
81
expect ( checkValidStub . calledOnce ) . to . be . true ;
67
82
expect ( system . getInstance . calledOnce ) . to . be . true ;
83
+ expect ( system . hook . calledOnce ) . to . be . true ;
84
+ expect ( system . hook . calledWithExactly ( 'doctor' ) ) . to . be . true ;
68
85
expect ( instanceStub . checkEnvironment . calledOnce ) . to . be . true ;
69
86
expect ( ui . listr . calledOnce ) . to . be . true ;
70
- expect ( ui . listr . args [ 0 ] [ 0 ] ) . to . deep . equal ( [ { } ] ) ;
87
+ expect ( ui . listr . args [ 0 ] [ 0 ] ) . to . deep . equal ( [
88
+ { } ,
89
+ {
90
+ title : 'Extension Task 1' ,
91
+ task : 'someTask'
92
+ }
93
+ ] ) ;
71
94
const context = ui . listr . args [ 0 ] [ 1 ] ;
72
95
expect ( context . argv ) . to . deep . equal ( { test : true , a : 'b' } ) ;
73
96
expect ( context . system ) . to . equal ( system ) ;
@@ -81,7 +104,13 @@ describe('Unit: Commands > Doctor', function () {
81
104
it ( 'skips instance check if skipInstanceCheck is true, uses correct context' , function ( ) {
82
105
const ui = { listr : sinon . stub ( ) . resolves ( ) } ;
83
106
const instanceStub = { checkEnvironment : sinon . stub ( ) } ;
84
- const system = { getInstance : sinon . stub ( ) . returns ( instanceStub ) } ;
107
+ const system = {
108
+ getInstance : sinon . stub ( ) . returns ( instanceStub ) ,
109
+ hook : sinon . stub ( ) . resolves ( [ {
110
+ title : 'Extension Task 1' ,
111
+ task : 'someTask'
112
+ } ] )
113
+ } ;
85
114
const checkValidStub = sinon . stub ( ) ;
86
115
87
116
const DoctorCommand = proxyquire ( modulePath , {
@@ -93,9 +122,17 @@ describe('Unit: Commands > Doctor', function () {
93
122
return instance . run ( { skipInstanceCheck : true , local : true , argv : true } ) . then ( ( ) => {
94
123
expect ( checkValidStub . called ) . to . be . false ;
95
124
expect ( system . getInstance . called ) . to . be . false ;
125
+ expect ( system . hook . calledOnce ) . to . be . true ;
126
+ expect ( system . hook . calledWithExactly ( 'doctor' ) ) . to . be . true ;
96
127
expect ( instanceStub . checkEnvironment . called ) . to . be . false ;
97
128
expect ( ui . listr . calledOnce ) . to . be . true ;
98
- expect ( ui . listr . args [ 0 ] [ 0 ] ) . to . deep . equal ( [ { } ] ) ;
129
+ expect ( ui . listr . args [ 0 ] [ 0 ] ) . to . deep . equal ( [
130
+ { } ,
131
+ {
132
+ title : 'Extension Task 1' ,
133
+ task : 'someTask'
134
+ }
135
+ ] ) ;
99
136
const context = ui . listr . args [ 0 ] [ 1 ] ;
100
137
expect ( context . argv ) . to . deep . equal ( { skipInstanceCheck : true , local : true , argv : true } ) ;
101
138
expect ( context . system ) . to . equal ( system ) ;
@@ -109,7 +146,13 @@ describe('Unit: Commands > Doctor', function () {
109
146
it ( 'skips instance check if only category is install, uses correct context' , function ( ) {
110
147
const ui = { listr : sinon . stub ( ) . resolves ( ) } ;
111
148
const instanceStub = { checkEnvironment : sinon . stub ( ) } ;
112
- const system = { getInstance : sinon . stub ( ) . returns ( instanceStub ) } ;
149
+ const system = {
150
+ getInstance : sinon . stub ( ) . returns ( instanceStub ) ,
151
+ hook : sinon . stub ( ) . resolves ( [ {
152
+ title : 'Extension Task 1' ,
153
+ task : 'someTask'
154
+ } ] )
155
+ } ;
113
156
const checkValidStub = sinon . stub ( ) ;
114
157
115
158
const DoctorCommand = proxyquire ( modulePath , {
@@ -127,6 +170,8 @@ describe('Unit: Commands > Doctor', function () {
127
170
} ) . then ( ( ) => {
128
171
expect ( checkValidStub . called ) . to . be . false ;
129
172
expect ( system . getInstance . called ) . to . be . false ;
173
+ expect ( system . hook . calledOnce ) . to . be . true ;
174
+ expect ( system . hook . calledWithExactly ( 'doctor' ) ) . to . be . true ;
130
175
expect ( instanceStub . checkEnvironment . called ) . to . be . false ;
131
176
expect ( ui . listr . calledOnce ) . to . be . true ;
132
177
expect ( ui . listr . args [ 0 ] [ 0 ] ) . to . deep . equal ( [ { category : [ 'install' ] } ] ) ;
@@ -157,33 +202,36 @@ describe('Unit: Commands > Doctor', function () {
157
202
title : 'Check 3' ,
158
203
category : [ 'install' , 'start' ]
159
204
} ] ;
205
+ const listrStub = sinon . stub ( ) . resolves ( ) ;
206
+ const hookStub = sinon . stub ( ) . resolves ( [ ] ) ;
207
+ let instance ;
160
208
161
- let DoctorCommand ;
162
-
163
- before ( ( ) => {
164
- DoctorCommand = proxyquire ( modulePath , {
209
+ beforeEach ( ( ) => {
210
+ const DoctorCommand = proxyquire ( modulePath , {
165
211
'./checks' : testChecks
166
212
} ) ;
167
- } )
213
+ instance = new DoctorCommand ( { listr : listrStub } , { hook : hookStub } ) ;
214
+ } ) ;
168
215
169
- it ( 'doesn\'t filter if no categories passed' , function ( ) {
170
- const listrStub = sinon . stub ( ) . resolves ( ) ;
171
- const instance = new DoctorCommand ( { listr : listrStub } , { system : true } ) ;
216
+ afterEach ( ( ) => {
217
+ listrStub . resetHistory ( ) ;
218
+ hookStub . resetHistory ( ) ;
219
+ } ) ;
172
220
221
+ it ( 'doesn\'t filter if no categories passed' , function ( ) {
173
222
return instance . run ( { skipInstanceCheck : true } ) . then ( ( ) => {
174
223
expect ( listrStub . calledOnce ) . to . be . true ;
224
+ expect ( hookStub . calledOnce ) . to . be . true ;
175
225
const tasks = listrStub . args [ 0 ] [ 0 ] ;
176
226
expect ( tasks ) . to . be . an ( 'array' ) ;
177
227
expect ( tasks . length ) . to . equal ( 3 ) ;
178
228
} ) ;
179
229
} ) ;
180
230
181
231
it ( 'filters with one category passed' , function ( ) {
182
- const listrStub = sinon . stub ( ) . resolves ( ) ;
183
- const instance = new DoctorCommand ( { listr : listrStub } , { system : true } ) ;
184
-
185
232
return instance . run ( { skipInstanceCheck : true , categories : [ 'install' ] } ) . then ( ( ) => {
186
233
expect ( listrStub . calledOnce ) . to . be . true ;
234
+ expect ( hookStub . calledOnce ) . to . be . true ;
187
235
const tasks = listrStub . args [ 0 ] [ 0 ] ;
188
236
expect ( tasks ) . to . be . an ( 'array' ) ;
189
237
expect ( tasks . length ) . to . equal ( 2 ) ;
@@ -193,11 +241,9 @@ describe('Unit: Commands > Doctor', function () {
193
241
} ) ;
194
242
195
243
it ( 'filters with another category passed' , function ( ) {
196
- const listrStub = sinon . stub ( ) . resolves ( ) ;
197
- const instance = new DoctorCommand ( { listr : listrStub } , { system : true } ) ;
198
-
199
244
return instance . run ( { skipInstanceCheck : true , categories : [ 'start' ] } ) . then ( ( ) => {
200
245
expect ( listrStub . calledOnce ) . to . be . true ;
246
+ expect ( hookStub . calledOnce ) . to . be . true ;
201
247
const tasks = listrStub . args [ 0 ] [ 0 ] ;
202
248
expect ( tasks ) . to . be . an ( 'array' ) ;
203
249
expect ( tasks . length ) . to . equal ( 2 ) ;
@@ -207,11 +253,9 @@ describe('Unit: Commands > Doctor', function () {
207
253
} ) ;
208
254
209
255
it ( 'filters with multiple categories passed' , function ( ) {
210
- const listrStub = sinon . stub ( ) . resolves ( ) ;
211
- const instance = new DoctorCommand ( { listr : listrStub } , { system : true } ) ;
212
-
213
256
return instance . run ( { skipInstanceCheck : true , categories : [ 'install' , 'start' ] } ) . then ( ( ) => {
214
257
expect ( listrStub . calledOnce ) . to . be . true ;
258
+ expect ( hookStub . calledOnce ) . to . be . true ;
215
259
const tasks = listrStub . args [ 0 ] [ 0 ] ;
216
260
expect ( tasks ) . to . be . an ( 'array' ) ;
217
261
expect ( tasks . length ) . to . equal ( 3 ) ;
0 commit comments