overleaf/libraries/stream-utils/test/unit/TimeoutStreamTests.js
Eric Mc Sween 12e7471213 Merge pull request #12916 from overleaf/bg-move-stream-buffer-code-to-library
move stream-related code to separate  `@overleaf/stream-utils` library

GitOrigin-RevId: a79a873109b927b4fc0ae36f47d5c67e0df58041
2023-06-02 08:05:57 +00:00

22 lines
639 B
JavaScript

const { expect } = require('chai')
const { TimeoutStream, AbortError } = require('../../index')
describe('TimeoutStream', function () {
it('should emit an error if the stream times out', function (done) {
const timeout = 10
const timeoutStream = new TimeoutStream(timeout)
timeoutStream.on('error', err => {
expect(err).to.be.an.instanceOf(AbortError)
done()
})
})
it('should not emit an error if the stream does not time out', function (done) {
const timeout = 100
const timeoutStream = new TimeoutStream(timeout)
setTimeout(() => {
timeoutStream.end()
done()
}, 1)
})
})