Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Uncaptured errors in source event stream.
Added a test to illustrate a broken issue and potentially underspecified in spec: If a source event stream emits an *error* instead of an *event*, then that error is passing up through the whole stack and throwing at the consumer of the response event stream. That's very likely not what we want. I have a proposal in this test case for what should happen in that case, similar to what would happen if an error occurred during during the second step of executing an event from the source stream.
- Loading branch information
Showing
7 changed files
with
439 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) 2017, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import asyncIteratorReject from '../asyncIteratorReject'; | ||
|
||
describe('asyncIteratorReject', () => { | ||
|
||
it('creates a failing async iterator', async () => { | ||
const error = new Error('Oh no, Mr. Bill!'); | ||
const iter = asyncIteratorReject(error); | ||
|
||
let caughtError; | ||
try { | ||
await iter.next(); | ||
} catch (thrownError) { | ||
caughtError = thrownError; | ||
} | ||
expect(caughtError).to.equal(error); | ||
|
||
expect(await iter.next()).to.deep.equal({ done: true, value: undefined }); | ||
}); | ||
|
||
it('can be closed before failing', async () => { | ||
const error = new Error('Oh no, Mr. Bill!'); | ||
const iter = asyncIteratorReject(error); | ||
|
||
// Close iterator | ||
expect(await iter.return()).to.deep.equal({ done: true, value: undefined }); | ||
|
||
expect(await iter.next()).to.deep.equal({ done: true, value: undefined }); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright (c) 2017, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import asyncIteratorResolve from '../asyncIteratorResolve'; | ||
|
||
describe('asyncIteratorResolve', () => { | ||
|
||
it('creates a failing async iterator', async () => { | ||
const value = 'Hello world!'; | ||
const iter = asyncIteratorResolve(value); | ||
|
||
expect(await iter.next()).to.deep.equal({ done: false, value }); | ||
expect(await iter.next()).to.deep.equal({ done: true, value: undefined }); | ||
}); | ||
|
||
it('can be closed before failing', async () => { | ||
const value = 'Hello world!'; | ||
const iter = asyncIteratorResolve(value); | ||
|
||
// Close iterator | ||
expect(await iter.return()).to.deep.equal({ done: true, value: undefined }); | ||
|
||
expect(await iter.next()).to.deep.equal({ done: true, value: undefined }); | ||
}); | ||
}); |
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.