1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

improve decoder tests coverage, use actual private ("#") instead of TypeScript private

This commit is contained in:
Leibale
2023-12-18 16:00:19 -05:00
parent f3631f8e73
commit d1f50df192
2 changed files with 377 additions and 344 deletions

View File

@@ -18,7 +18,7 @@ function test(name: string, config: Test) {
it('single chunk', () => {
const setup = setupTest(config);
setup.decoder.write(config.toWrite);
assertCalls(config, setup);
assertSpiesCalls(config, setup);
});
it('byte by byte', () => {
@@ -26,7 +26,7 @@ function test(name: string, config: Test) {
for (let i = 0; i < config.toWrite.length; i++) {
setup.decoder.write(config.toWrite.subarray(i, i + 1));
}
assertCalls(config, setup);
assertSpiesCalls(config, setup);
});
})
}
@@ -49,7 +49,7 @@ function setupTest(config: Test) {
};
}
function assertCalls(config: Test, spies: ReturnType<typeof setupTest>) {
function assertSpiesCalls(config: Test, spies: ReturnType<typeof setupTest>) {
assertSpyCalls(spies.onReplySpy, config.replies);
assertSpyCalls(spies.onErrorReplySpy, config.errorReplies);
assertSpyCalls(spies.onPushSpy, config.pushReplies);
@@ -302,6 +302,40 @@ describe('RESP Decoder', () => {
replies: [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
});
test('with all types', {
toWrite: Buffer.from([
'*13\r\n',
'_\r\n',
'#f\r\n',
':0\r\n',
'(0\r\n',
',0\r\n',
'+\r\n',
'$0\r\n\r\n',
'=4\r\ntxt:\r\n',
'-\r\n',
'!0\r\n\r\n',
'*0\r\n',
'~0\r\n',
'%0\r\n'
].join('')),
replies: [[
null,
false,
0,
0n,
0,
'',
'',
'',
new SimpleError(''),
new BlobError(''),
[],
[],
Object.create(null)
]]
});
test('null (RESP2 backwards compatibility)', {
toWrite: Buffer.from('*-1\r\n'),
replies: [null]

File diff suppressed because it is too large Load Diff