mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 10:43:33 -05:00
12e7471213
move stream-related code to separate `@overleaf/stream-utils` library GitOrigin-RevId: a79a873109b927b4fc0ae36f47d5c67e0df58041
30 lines
943 B
JavaScript
30 lines
943 B
JavaScript
const { expect } = require('chai')
|
|
const { LimitedStream, SizeExceededError } = require('../../index')
|
|
|
|
describe('LimitedStream', function () {
|
|
it('should emit an error if the stream size exceeds the limit', function (done) {
|
|
const maxSize = 10
|
|
const limitedStream = new LimitedStream(maxSize)
|
|
limitedStream.on('error', err => {
|
|
expect(err).to.be.an.instanceOf(SizeExceededError)
|
|
done()
|
|
})
|
|
limitedStream.write(Buffer.alloc(maxSize + 1))
|
|
})
|
|
|
|
it('should pass through data if the stream size does not exceed the limit', function (done) {
|
|
const maxSize = 15
|
|
const limitedStream = new LimitedStream(maxSize)
|
|
let data = ''
|
|
limitedStream.on('data', chunk => {
|
|
data += chunk.toString()
|
|
})
|
|
limitedStream.on('end', () => {
|
|
expect(data).to.equal('hello world')
|
|
done()
|
|
})
|
|
limitedStream.write('hello')
|
|
limitedStream.write(' world')
|
|
limitedStream.end()
|
|
})
|
|
})
|