Skip to content

Commit

Permalink
fix(babel): actions' runner should process parallel throws
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Sep 11, 2023
1 parent 2ee2b26 commit 9c09f84
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/babel/src/transform/actions/BaseAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ export class BaseAction<TAction extends ActionQueueItem>
};

const processError = (e: unknown) => {
if (this.activeScenarioNextResults.length > nextIdx) {
return;
}

try {
const nextResult = throwFn(e);
processNextResult(nextResult as IterationResult, processError);
Expand Down
31 changes: 31 additions & 0 deletions packages/babel/src/transform/actions/__tests__/BaseAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,36 @@ describe('BaseAction', () => {
expect(() => generator1.next()).toThrow(error);
expect(() => generator2.next()).toThrow(error);
});

it('should process parallel throws', () => {
const handler: Handler<'sync', ITransformAction> = function* handler() {
try {
yield ['resolveImports', entrypoint, { imports: new Map() }, null];
} catch (e) {
onError(e);
}

return null;
};

const generator1 = action.run(handler);
const generator2 = action.run(handler);

expect(generator1.next()).toEqual({
done: false,
value: ['resolveImports', entrypoint, { imports: new Map() }, null],
});
expect(generator2.next()).toEqual({
done: false,
value: ['resolveImports', entrypoint, { imports: new Map() }, null],
});

const error1 = new Error('foo');
const error2 = new Error('bar');
expect(generator1.throw(error1)).toEqual({ done: true, value: null });
expect(generator2.throw(error2)).toEqual({ done: true, value: null });
expect(onError).toHaveBeenCalledTimes(1);
expect(onError).toHaveBeenCalledWith(error1);
});
});
});

0 comments on commit 9c09f84

Please sign in to comment.