-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call "onStepFinished" on error, and send error as parameter to callback
- Loading branch information
Pedro Kehl
committed
Mar 13, 2024
1 parent
2d6eb84
commit 29d48c2
Showing
12 changed files
with
248 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,59 @@ | ||
import { fromGenerator } from '../../src' | ||
import { getMockedGenerator } from '../mocks/generator.mock' | ||
import { getMockedGenerator, getThrowingGenerator } from '../mocks/generator.mock' | ||
|
||
describe('Error Handling', () => { | ||
test('Should pass generator error to run call stack', () => { | ||
// eslint-disable-next-line require-yield | ||
async function* generator(): AsyncGenerator<number> { | ||
throw new Error('Generator error') | ||
} | ||
|
||
const caminho = fromGenerator({ fn: generator, provides: 'generatedData' }) | ||
.pipe({ fn: jest.fn() }) | ||
test('Should pass "generator" error to run call stack', async () => { | ||
const caminho = fromGenerator({ fn: getThrowingGenerator(new Error('Generator error')), provides: 'generatedData' }) | ||
await expect(caminho.run()).rejects.toMatchObject({ message: 'Generator error' }) | ||
}) | ||
|
||
return expect(caminho.run()).rejects.toMatchObject({ message: 'Generator error' }) | ||
test('Should pass "generator with backpressure" error to run call stack', async () => { | ||
const onStepFinished = jest.fn() | ||
const options = { maxItemsFlowing: 1, onStepFinished } | ||
const throwingGenerator = getThrowingGenerator(new Error('Generator error')) | ||
const caminho = fromGenerator({ fn: throwingGenerator, provides: 'generatedData' }, options) | ||
await expect(caminho.run()).rejects.toMatchObject({ message: 'Generator error' }) | ||
}) | ||
|
||
test('Should pass operator error to run call stack', () => { | ||
test('Should pass "pipe" error to run call stack', async () => { | ||
const operator = jest.fn().mockRejectedValue(new Error('Operator error')) | ||
const caminho = fromGenerator({ fn: getMockedGenerator([1, 2]), provides: 'number' }) | ||
.pipe({ fn: operator }) | ||
|
||
return expect(caminho.run()).rejects.toMatchObject({ message: 'Operator error' }) | ||
await expect(caminho.run()).rejects.toMatchObject({ message: 'Operator error' }) | ||
}) | ||
|
||
test('Should pass "batch" error to run call stack', async () => { | ||
const operator = jest.fn().mockRejectedValue(new Error('Operator error')) | ||
const caminho = fromGenerator({ fn: getMockedGenerator([1, 2]), provides: 'number' }) | ||
.pipe({ fn: operator, batch: { maxSize: 10, timeoutMs: 1 } }) | ||
|
||
await expect(caminho.run()).rejects.toMatchObject({ message: 'Operator error' }) | ||
}) | ||
|
||
test('Should pass "parallel" error to run call stack', async () => { | ||
const operator = jest.fn().mockRejectedValue(new Error('Operator error')) | ||
const caminho = fromGenerator({ fn: getMockedGenerator([1, 2]), provides: 'number' }) | ||
.parallel([{ fn: operator }]) | ||
|
||
await expect(caminho.run()).rejects.toMatchObject({ message: 'Operator error' }) | ||
}) | ||
|
||
test('Should pass filter error to run call stack', () => { | ||
test('Should pass "filter" error to run call stack', async () => { | ||
const caminho = fromGenerator({ fn: getMockedGenerator([1, 2]), provides: 'number' }) | ||
.filter(() => { throw new Error('Filter error') }) | ||
|
||
return expect(caminho.run()).rejects.toMatchObject({ message: 'Filter error' }) | ||
await expect(caminho.run()).rejects.toMatchObject({ message: 'Filter error' }) | ||
}) | ||
|
||
test('Should pass reduce error to run call stack', () => { | ||
test('Should pass "reduce" error to run call stack', async () => { | ||
const caminho = fromGenerator({ fn: getMockedGenerator([1, 2]), provides: 'number' }) | ||
.reduce({ | ||
fn: () => { throw new Error('Reduce error') }, | ||
seed: 0, | ||
provides: 'doesntMatter', | ||
}) | ||
|
||
return expect(caminho.run()).rejects.toMatchObject({ message: 'Reduce error' }) | ||
await expect(caminho.run()).rejects.toMatchObject({ message: 'Reduce error' }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.