overleaf/libraries/stream-utils/test/unit/LoggerStreamTests.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

36 lines
1 KiB
JavaScript

const { expect } = require('chai')
const { LoggerStream } = require('../../index')
describe('LoggerStream', function () {
it('should log the size of the stream when it exceeds the limit', function (done) {
const maxSize = 10
const loggedSizes = []
const loggerStream = new LoggerStream(maxSize, (size, isFlush) => {
loggedSizes.push([size, isFlush])
if (isFlush) {
expect(loggedSizes).to.deep.equal([
[11, undefined],
[11, true],
])
done()
}
})
loggerStream.write(Buffer.alloc(maxSize))
loggerStream.write(Buffer.alloc(1))
loggerStream.end()
})
it('should not log the size of the stream if it does not exceed the limit', function (done) {
const maxSize = 10
const loggedSizes = []
const loggerStream = new LoggerStream(maxSize, (size, isFlush) => {
loggedSizes.push(size)
})
loggerStream.write(Buffer.alloc(maxSize))
loggerStream.end()
loggerStream.on('finish', () => {
expect(loggedSizes).to.deep.equal([])
done()
})
})
})