Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Test(perMessageDeflate): Add more test cases for maxPayload exceede…
…d error.

- Refer to previous commit
- Ensure Both paths, flush and error are tested
  • Loading branch information
Amirali-Amirifar committed May 2, 2025
commit 7283e3394c867129d168255a3b2abd065145b97c
22 changes: 20 additions & 2 deletions test/permessage-deflate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,27 @@ describe('PerMessageDeflate', () => {
});
});

it("doesn't call the callback twice when `maxPayload` is exceeded", (done) => {
it('calls the callback when `maxPayload` is exceeded (1/2)', (done) => {
const perMessageDeflate = new PerMessageDeflate({}, false, 25);
const buf = Buffer.from('A'.repeat(1024 * 1024));
const buf = Buffer.alloc(50, 'A');

perMessageDeflate.accept([{}]);
perMessageDeflate.compress(buf, true, (err, data) => {
if (err) return done(err);

perMessageDeflate.decompress(data, true, (err) => {
assert.ok(err instanceof RangeError);
assert.strictEqual(err.message, 'Max payload size exceeded');
done();
});
});
});

it('calls the callback when `maxPayload` is exceeded (2/2)', (done) => {
// A copy of the previous test but with a larger input. See
// https://github.com/websockets/ws/pull/2285.
const perMessageDeflate = new PerMessageDeflate({}, false, 25);
const buf = Buffer.alloc(1024 * 1024, 'A');

perMessageDeflate.accept([{}]);
perMessageDeflate.compress(buf, true, (err, data) => {
Expand Down