From 109019be0f889a5b6df36904aa73d8bf0924c028 Mon Sep 17 00:00:00 2001 From: ameanasad Date: Tue, 17 Oct 2023 14:25:38 -0400 Subject: [PATCH] fix: fallback bug --- src/client.js | 1 + src/utils/url.js | 2 +- test/fallback.spec.js | 10 +++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client.js b/src/client.js index 53456a8..ac12f0f 100644 --- a/src/client.js +++ b/src/client.js @@ -143,6 +143,7 @@ export class Saturn { const remainingBytes = byteCountCheckpoint - byteCount if (remainingBytes < chunk.length) { yield chunk.slice(remainingBytes) + byteCountCheckpoint += chunk.length - remainingBytes } } else { yield chunk diff --git a/src/utils/url.js b/src/utils/url.js index b58b7b5..5a86335 100644 --- a/src/utils/url.js +++ b/src/utils/url.js @@ -9,7 +9,7 @@ export function parseUrl (url) { // This is a temp function to resolve URLs for mock testing // See issue here: https://github.com/mswjs/msw/issues/1597 if (process.env.TESTING) { - return url.href + return url.toJSON() } return url } diff --git a/test/fallback.spec.js b/test/fallback.spec.js index d228a77..cda4e68 100644 --- a/test/fallback.spec.js +++ b/test/fallback.spec.js @@ -5,7 +5,7 @@ import { describe, mock, test } from 'node:test' import { Saturn } from '#src/index.js' import { concatChunks, generateNodes, getMockServer, mockJWT, mockNodesHandlers, mockOrchHandler, mockSaturnOriginHandler, MSW_SERVER_OPTS } from './test-utils.js' -const TEST_DEFAULT_ORCH = 'https://orchestrator.strn.pl/nodes?maxNodes=100' +const TEST_DEFAULT_ORCH = 'https://orchestrator.strn.pl/nodes' const TEST_NODES_LIST_KEY = 'saturn-nodes' const TEST_AUTH = 'https://fz3dyeyxmebszwhuiky7vggmsu0rlkoy.lambda-url.us-west-2.on.aws/' const TEST_ORIGIN_DOMAIN = 'saturn.ms' @@ -277,10 +277,14 @@ describe('Client Fallback', () => { callCount++ if (callCount === 1) { yield Buffer.from('chunk1-') - yield Buffer.from('overlap') throw new Error('First call error') } if (callCount === 2) { + yield Buffer.from('chunk1') + yield Buffer.from('-overlap') + throw new Error('Second call error') + } + if (callCount === 3) { yield Buffer.from('chunk1-overlap') yield Buffer.from('chunk2') } @@ -292,7 +296,7 @@ describe('Client Fallback', () => { buffer = await concatChunks(content) assert.deepEqual(buffer, expectedContent) - assert.strictEqual(fetchContentMock.mock.calls.length, 2) + assert.strictEqual(fetchContentMock.mock.calls.length, 3) server.close() mock.reset()