Skip to content

Commit

Permalink
test: fix blob comparisons that broke or were never worjing properly
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Mar 15, 2024
1 parent 46dc133 commit 36f6c96
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/verified-fetch/test/utils/byte-range-context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,23 @@ describe('ByteRangeContext', () => {
}))
]
validRanges.forEach(({ type, range, expected, body, contentRange }) => {
it(`should correctly slice ${type} body with range ${range}`, () => {
it(`should correctly slice ${type} body with range ${range}`, async () => {
const context = new ByteRangeContext(logger, { Range: range })

context.setBody(body)
const actualBody = context.getBody()

if (actualBody instanceof Blob || type === 'Blob') {
const bodyAsUint8Array = new Uint8Array(await (actualBody as Blob).arrayBuffer())
const expectedAsUint8Array = new Uint8Array(await (expected as Blob).arrayBuffer())
// loop through the bytes and compare them
for (let i = 0; i < bodyAsUint8Array.length; i++) {
expect(bodyAsUint8Array[i]).to.equal(expectedAsUint8Array[i])
}
} else {
expect(actualBody).to.deep.equal(expected)
}

expect(context.getBody()).to.deep.equal(expected)
expect(context.contentRangeHeaderValue).to.equal(contentRange)
})
})
Expand Down

0 comments on commit 36f6c96

Please sign in to comment.