@@ -100,33 +100,121 @@ describe('Unit: Commands > Stop', function () {
100
100
return stop . run . call ( context , { } ) ;
101
101
} ) ;
102
102
103
- it ( 'disables extensions if it needs to' , function ( ) {
104
- class ProcessManager { }
105
- const sEBstub = sinon . stub ( ) . returns ( true ) ;
106
- const disableStub = sinon . stub ( ) . resolves ( ) ;
107
- const gIstub = sinon . stub ( ) . returns ( {
108
- running : ( ) => Promise . resolve ( true ) ,
109
- process : {
110
- disable : disableStub ,
111
- stop : ( ) => true ,
112
- isEnabled : ( ) => true
113
- } ,
114
- loadRunningEnvironment : ( ) => true
103
+ describe ( 'handles disabling' , function ( ) {
104
+ it ( 'skips disabling if disable flag is not set' , function ( ) {
105
+ const instance = {
106
+ running : ( ) => Promise . resolve ( true ) ,
107
+ process : {
108
+ enable : ( ) => Promise . resolve ( ) ,
109
+ disable : sinon . stub ( ) . resolves ( ) ,
110
+ stop : sinon . stub ( ) . resolves ( ) ,
111
+ isEnabled : sinon . stub ( ) . resolves ( true )
112
+ } ,
113
+ loadRunningEnvironment : ( ) => true
114
+ } ;
115
+ const system = {
116
+ getInstance : ( ) => instance
117
+ } ;
118
+ const ui = {
119
+ run : sinon . stub ( ) . resolves ( )
120
+ } ;
121
+
122
+ const StopCommand = proxyquire ( modulePath , {
123
+ '../utils/check-valid-install' : ( ) => true
124
+ } ) ;
125
+ const stop = new StopCommand ( ui , system ) ;
126
+
127
+ return stop . run ( { disable : false } ) . then ( ( ) => {
128
+ expect ( instance . process . isEnabled . called ) . to . be . false ;
129
+ expect ( ui . run . calledOnce ) . to . be . true ;
130
+ } ) ;
115
131
} ) ;
116
- const context = {
117
- system : { getInstance : gIstub } ,
118
- ui : { run : ( ) => Promise . resolve ( ) }
119
- } ;
120
- ProcessManager . supportsEnableBehavior = sEBstub ;
121
- const StopCommand = proxyquire ( modulePath , {
122
- '../utils/check-valid-install' : ( ) => true ,
123
- '../process-manager' : ProcessManager
132
+
133
+ it ( 'skips disabling if process manager doesn\'t support enable behavior' , function ( ) {
134
+ const instance = {
135
+ running : ( ) => Promise . resolve ( true ) ,
136
+ process : {
137
+ stop : sinon . stub ( ) . resolves ( ) ,
138
+ isEnabled : sinon . stub ( ) . resolves ( false )
139
+ } ,
140
+ loadRunningEnvironment : ( ) => true
141
+ } ;
142
+ const system = {
143
+ getInstance : ( ) => instance
144
+ } ;
145
+ const ui = {
146
+ run : sinon . stub ( ) . resolves ( )
147
+ } ;
148
+
149
+ const StopCommand = proxyquire ( modulePath , {
150
+ '../utils/check-valid-install' : ( ) => true
151
+ } ) ;
152
+ const stop = new StopCommand ( ui , system ) ;
153
+
154
+ return stop . run ( { disable : true } ) . then ( ( ) => {
155
+ expect ( ui . run . calledOnce ) . to . be . true ;
156
+ expect ( instance . process . isEnabled . called ) . to . be . false ;
157
+ } ) ;
124
158
} ) ;
125
- const stop = new StopCommand ( ) ;
126
159
127
- return stop . run . call ( context , { disable : true } ) . then ( ( ) => {
128
- expect ( sEBstub . calledOnce ) . to . be . true ;
129
- expect ( disableStub . calledOnce ) . to . be . true ;
160
+ it ( 'skips disabling if isEnabled returns false' , function ( ) {
161
+ const instance = {
162
+ running : ( ) => Promise . resolve ( true ) ,
163
+ process : {
164
+ enable : ( ) => Promise . resolve ( ) ,
165
+ disable : sinon . stub ( ) . resolves ( ) ,
166
+ stop : sinon . stub ( ) . resolves ( ) ,
167
+ isEnabled : sinon . stub ( ) . resolves ( false )
168
+ } ,
169
+ loadRunningEnvironment : ( ) => true
170
+ } ;
171
+ const system = {
172
+ getInstance : ( ) => instance
173
+ } ;
174
+ const ui = {
175
+ run : sinon . stub ( ) . resolves ( )
176
+ } ;
177
+
178
+ const StopCommand = proxyquire ( modulePath , {
179
+ '../utils/check-valid-install' : ( ) => true
180
+ } ) ;
181
+ const stop = new StopCommand ( ui , system ) ;
182
+
183
+ return stop . run ( { disable : true } ) . then ( ( ) => {
184
+ expect ( instance . process . isEnabled . calledOnce ) . to . be . true ;
185
+ expect ( instance . process . disable . called ) . to . be . false ;
186
+ expect ( ui . run . calledOnce ) . to . be . true ;
187
+ } ) ;
188
+ } ) ;
189
+
190
+ it ( 'disables if necessary' , function ( ) {
191
+ const instance = {
192
+ running : ( ) => Promise . resolve ( true ) ,
193
+ process : {
194
+ enable : ( ) => Promise . resolve ( ) ,
195
+ disable : sinon . stub ( ) . resolves ( ) ,
196
+ stop : sinon . stub ( ) . resolves ( ) ,
197
+ isEnabled : sinon . stub ( ) . resolves ( true )
198
+ } ,
199
+ loadRunningEnvironment : ( ) => true
200
+ } ;
201
+ const system = {
202
+ getInstance : ( ) => instance
203
+ } ;
204
+ const ui = {
205
+ run : sinon . stub ( ) . callsFake ( fn => Promise . resolve ( fn ( ) ) )
206
+ } ;
207
+
208
+ const StopCommand = proxyquire ( modulePath , {
209
+ '../utils/check-valid-install' : ( ) => true
210
+ } ) ;
211
+ const stop = new StopCommand ( ui , system ) ;
212
+
213
+ return stop . run ( { disable : true } ) . then ( ( ) => {
214
+ expect ( instance . process . isEnabled . calledOnce ) . to . be . true ;
215
+ expect ( instance . process . disable . calledOnce ) . to . be . true ;
216
+ expect ( ui . run . calledTwice ) . to . be . true ;
217
+ } ) ;
130
218
} ) ;
131
219
} ) ;
132
220
} ) ;
0 commit comments