@@ -4,8 +4,14 @@ import { resolveTaskFn } from '../lib/resolveTaskFn'
44import { getInitialState } from '../lib/state'
55import { TaskError } from '../lib/symbols'
66
7+ import { createExecaReturnValue } from './utils/createExecaReturnValue'
8+
79const defaultOpts = { files : [ 'test.js' ] }
810
11+ function mockExecaImplementationOnce ( value ) {
12+ execa . mockImplementationOnce ( ( ) => createExecaReturnValue ( value ) )
13+ }
14+
915describe ( 'resolveTaskFn' , ( ) => {
1016 beforeEach ( ( ) => {
1117 execa . mockClear ( )
@@ -135,7 +141,7 @@ describe('resolveTaskFn', () => {
135141
136142 it ( 'should throw error for failed linters' , async ( ) => {
137143 expect . assertions ( 1 )
138- execa . mockResolvedValueOnce ( {
144+ mockExecaImplementationOnce ( {
139145 stdout : 'Mock error' ,
140146 stderr : '' ,
141147 code : 0 ,
@@ -149,7 +155,7 @@ describe('resolveTaskFn', () => {
149155
150156 it ( 'should throw error for interrupted processes' , async ( ) => {
151157 expect . assertions ( 1 )
152- execa . mockResolvedValueOnce ( {
158+ mockExecaImplementationOnce ( {
153159 stdout : 'Mock error' ,
154160 stderr : '' ,
155161 code : 0 ,
@@ -167,7 +173,7 @@ describe('resolveTaskFn', () => {
167173
168174 it ( 'should throw error for killed processes without signal' , async ( ) => {
169175 expect . assertions ( 1 )
170- execa . mockResolvedValueOnce ( {
176+ mockExecaImplementationOnce ( {
171177 stdout : 'Mock error' ,
172178 stderr : '' ,
173179 code : 0 ,
@@ -192,7 +198,7 @@ describe('resolveTaskFn', () => {
192198 } )
193199
194200 it ( 'should add TaskError on error' , async ( ) => {
195- execa . mockResolvedValueOnce ( {
201+ mockExecaImplementationOnce ( {
196202 stdout : 'Mock error' ,
197203 stderr : '' ,
198204 code : 0 ,
@@ -210,7 +216,7 @@ describe('resolveTaskFn', () => {
210216
211217 it ( 'should not add output when there is none' , async ( ) => {
212218 expect . assertions ( 2 )
213- execa . mockResolvedValueOnce ( {
219+ mockExecaImplementationOnce ( {
214220 stdout : '' ,
215221 stderr : '' ,
216222 code : 0 ,
@@ -236,7 +242,7 @@ describe('resolveTaskFn', () => {
236242
237243 it ( 'should add output even when task succeeds if `verbose: true`' , async ( ) => {
238244 expect . assertions ( 2 )
239- execa . mockResolvedValueOnce ( {
245+ mockExecaImplementationOnce ( {
240246 stdout : 'Mock success' ,
241247 stderr : '' ,
242248 code : 0 ,
@@ -266,7 +272,7 @@ describe('resolveTaskFn', () => {
266272
267273 it ( 'should not add title to output when task errors while quiet' , async ( ) => {
268274 expect . assertions ( 2 )
269- execa . mockResolvedValueOnce ( {
275+ mockExecaImplementationOnce ( {
270276 stdout : '' ,
271277 stderr : 'stderr' ,
272278 code : 1 ,
@@ -296,7 +302,7 @@ describe('resolveTaskFn', () => {
296302
297303 it ( 'should not print anything when task errors without output while quiet' , async ( ) => {
298304 expect . assertions ( 2 )
299- execa . mockResolvedValueOnce ( {
305+ mockExecaImplementationOnce ( {
300306 stdout : '' ,
301307 stderr : '' ,
302308 code : 1 ,
@@ -321,4 +327,29 @@ describe('resolveTaskFn', () => {
321327 }
322328 ` )
323329 } )
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+ } )
324355} )
0 commit comments