Skip to content

Commit

Permalink
add test for pngInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Feb 11, 2024
1 parent 4662181 commit 33d7281
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion web_src/js/utils/image.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function pngChunks(data) {
const view = new DataView(data.buffer, 0);
if (view.getBigUint64(0) !== 9894494448401390090n) throw new Error(`Invalid png header`);
if (view.getBigUint64(0) !== 9894494448401390090n) throw new Error('Invalid png header');

const decoder = new TextDecoder();
const chunks = [];
Expand Down
7 changes: 6 additions & 1 deletion web_src/js/utils/image.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {pngChunks} from './image.js';
import {pngChunks, pngInfo} from './image.js';

test('pngChunks', async () => {
const blob = await (await globalThis.fetch('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAADUlEQVQIHQECAP3/AAAAAgABzePRKwAAAABJRU5ErkJggg==')).blob();
Expand All @@ -8,3 +8,8 @@ test('pngChunks', async () => {
{name: 'IEND', data: new Uint8Array([])},
]);
});

test('pngInfo', async () => {
const blob = await (await globalThis.fetch('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAEElEQVQI12OQNZcAIgYIBQAL8gGxdzzM0A==')).blob();
expect(await pngInfo(blob)).toEqual({dppx: 2, width: 2});
});

0 comments on commit 33d7281

Please sign in to comment.