diff --git a/src/actions/lifecycle.ts b/src/actions/lifecycle.ts index d4627db7..f1d6dfc0 100644 --- a/src/actions/lifecycle.ts +++ b/src/actions/lifecycle.ts @@ -345,13 +345,7 @@ export abstract class TasksMixin { return; } - try { - this.env.emit('error', error); - } catch (error: unknown) { - setImmediate(() => { - throw error; - }); - } + throw error; } finally { delete this.runningState; } diff --git a/test/base.test.ts b/test/base.test.ts index 7fb39a68..9b252ac9 100644 --- a/test/base.test.ts +++ b/test/base.test.ts @@ -5,6 +5,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url'; import { createRequire } from 'node:module'; import process from 'node:process'; import { Buffer } from 'node:buffer'; +import { esmocha, expect } from 'esmocha'; import { extend } from 'lodash-es'; import { spy as sinonSpy, fake as sinonFake, assert as sinonAssert } from 'sinon'; import { passthrough } from '@yeoman/transform'; @@ -1461,6 +1462,40 @@ describe('Base', () => { await gen.run(); assert.equal(thrown, true); }); + + it('rejecting a task should stop the queue', async function () { + const gen = new Generator({ + resolved: resolveddir, + namespace: 'dummy', + env, + testQueue: 'This value', + }); + + const queueName = 'configuring'; + gen.queueTask({ + method() { + throw new Error('Some error'); + }, + queueName, + taskName: 'foo', + run: false, + }); + + const secondTask = esmocha.fn(); + gen.queueTask({ + method: secondTask, + queueName, + taskName: 'secondTask', + run: false, + }); + + await expect(gen.run()).rejects.toThrow('Some error'); + if (env.runLoop) { + expect(env.runLoop.running).toBe(false); + } + + expect(secondTask).not.toHaveBeenCalled(); + }); }); describe('Custom priorities', () => {