@@ -4,8 +4,14 @@ import { resolveTaskFn } from '../lib/resolveTaskFn'
4
4
import { getInitialState } from '../lib/state'
5
5
import { TaskError } from '../lib/symbols'
6
6
7
+ import { createExecaReturnValue } from './utils/createExecaReturnValue'
8
+
7
9
const defaultOpts = { files : [ 'test.js' ] }
8
10
11
+ function mockExecaImplementationOnce ( value ) {
12
+ execa . mockImplementationOnce ( ( ) => createExecaReturnValue ( value ) )
13
+ }
14
+
9
15
describe ( 'resolveTaskFn' , ( ) => {
10
16
beforeEach ( ( ) => {
11
17
execa . mockClear ( )
@@ -135,7 +141,7 @@ describe('resolveTaskFn', () => {
135
141
136
142
it ( 'should throw error for failed linters' , async ( ) => {
137
143
expect . assertions ( 1 )
138
- execa . mockResolvedValueOnce ( {
144
+ mockExecaImplementationOnce ( {
139
145
stdout : 'Mock error' ,
140
146
stderr : '' ,
141
147
code : 0 ,
@@ -149,7 +155,7 @@ describe('resolveTaskFn', () => {
149
155
150
156
it ( 'should throw error for interrupted processes' , async ( ) => {
151
157
expect . assertions ( 1 )
152
- execa . mockResolvedValueOnce ( {
158
+ mockExecaImplementationOnce ( {
153
159
stdout : 'Mock error' ,
154
160
stderr : '' ,
155
161
code : 0 ,
@@ -167,7 +173,7 @@ describe('resolveTaskFn', () => {
167
173
168
174
it ( 'should throw error for killed processes without signal' , async ( ) => {
169
175
expect . assertions ( 1 )
170
- execa . mockResolvedValueOnce ( {
176
+ mockExecaImplementationOnce ( {
171
177
stdout : 'Mock error' ,
172
178
stderr : '' ,
173
179
code : 0 ,
@@ -192,7 +198,7 @@ describe('resolveTaskFn', () => {
192
198
} )
193
199
194
200
it ( 'should add TaskError on error' , async ( ) => {
195
- execa . mockResolvedValueOnce ( {
201
+ mockExecaImplementationOnce ( {
196
202
stdout : 'Mock error' ,
197
203
stderr : '' ,
198
204
code : 0 ,
@@ -210,7 +216,7 @@ describe('resolveTaskFn', () => {
210
216
211
217
it ( 'should not add output when there is none' , async ( ) => {
212
218
expect . assertions ( 2 )
213
- execa . mockResolvedValueOnce ( {
219
+ mockExecaImplementationOnce ( {
214
220
stdout : '' ,
215
221
stderr : '' ,
216
222
code : 0 ,
@@ -236,7 +242,7 @@ describe('resolveTaskFn', () => {
236
242
237
243
it ( 'should add output even when task succeeds if `verbose: true`' , async ( ) => {
238
244
expect . assertions ( 2 )
239
- execa . mockResolvedValueOnce ( {
245
+ mockExecaImplementationOnce ( {
240
246
stdout : 'Mock success' ,
241
247
stderr : '' ,
242
248
code : 0 ,
@@ -266,7 +272,7 @@ describe('resolveTaskFn', () => {
266
272
267
273
it ( 'should not add title to output when task errors while quiet' , async ( ) => {
268
274
expect . assertions ( 2 )
269
- execa . mockResolvedValueOnce ( {
275
+ mockExecaImplementationOnce ( {
270
276
stdout : '' ,
271
277
stderr : 'stderr' ,
272
278
code : 1 ,
@@ -296,7 +302,7 @@ describe('resolveTaskFn', () => {
296
302
297
303
it ( 'should not print anything when task errors without output while quiet' , async ( ) => {
298
304
expect . assertions ( 2 )
299
- execa . mockResolvedValueOnce ( {
305
+ mockExecaImplementationOnce ( {
300
306
stdout : '' ,
301
307
stderr : '' ,
302
308
code : 1 ,
@@ -321,4 +327,29 @@ describe('resolveTaskFn', () => {
321
327
}
322
328
` )
323
329
} )
330
+
331
+ it ( 'should kill a long running task when an error is added to the context' , async ( ) => {
332
+ execa . mockImplementationOnce ( ( ) =>
333
+ createExecaReturnValue (
334
+ {
335
+ stdout : 'a-ok' ,
336
+ stderr : '' ,
337
+ code : 0 ,
338
+ cmd : 'mock cmd' ,
339
+ failed : false ,
340
+ killed : false ,
341
+ signal : null ,
342
+ } ,
343
+ 1000
344
+ )
345
+ )
346
+
347
+ const context = getInitialState ( )
348
+ const taskFn = resolveTaskFn ( { command : 'node' } )
349
+ const taskPromise = taskFn ( context )
350
+
351
+ context . errors . add ( { } )
352
+
353
+ await expect ( taskPromise ) . rejects . toThrowErrorMatchingInlineSnapshot ( `"node [KILLED]"` )
354
+ } )
324
355
} )
0 commit comments