Skip to content
Closed
Changes from all commits
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
21 changes: 21 additions & 0 deletions src/converter/blobSizePreflight.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, it, vi } from 'vitest';

import { Base64SizeError, blobToDataUri } from './index.js';

describe('Blob conversion resource preflight', () => {
it('rejects a known oversized Blob before reading its payload bytes', async () => {
const blob = new Blob([new Uint8Array(32)], { type: 'application/octet-stream' });
const read = vi.fn(async () => new Uint8Array(32).buffer);
Object.defineProperty(blob, 'arrayBuffer', {
configurable: true,
value: read,
});

await expect(blobToDataUri(blob, { maxBytes: 4 })).rejects.toMatchObject({
name: 'Base64SizeError',
bytes: 32,
maxBytes: 4,
} satisfies Partial<Base64SizeError>);
expect(read).not.toHaveBeenCalled();

Check failure on line 19 in src/converter/blobSizePreflight.test.ts

View workflow job for this annotation

GitHub Actions / build-and-test

src/converter/blobSizePreflight.test.ts > Blob conversion resource preflight > rejects a known oversized Blob before reading its payload bytes

AssertionError: expected "spy" to not be called at all, but actually been called 1 times Received: 1st spy call: Array [] Number of calls: 1 ❯ src/converter/blobSizePreflight.test.ts:19:22
});
});
Loading