Skip to content

Commit

Permalink
fix(test) reduce memory usage test pixel limit, add hard limit
Browse files Browse the repository at this point in the history
  • Loading branch information
gugu committed Jun 5, 2024
1 parent 86222aa commit a5a5847
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/png.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export async function generateImage({
}: ImageOptions & { matrix: Matrix }) {
const marginPx = margin * size;
const imageSize = matrix.length * size + marginPx * 2;
if (size > 200) {
throw new Error('Module size is too big, resulting image is too large: ' + imageSize);
}
const svg = await createSVG({
matrix, size, margin, color, bgColor,
imageWidth: imageSize, imageHeight: imageSize,
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ interface TestParams {
name: "PNG memory usage",
fn: getPNG,
filename: "qr_large.png",
params: { size: 300, margin: 10 },
params: { size: 199, margin: 10 },
}
] as TestParams[]).forEach((testData) => {
test.serial(testData.name, async (t) => {
Expand Down
Binary file modified test_data/golden/qr_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a5a5847

Please sign in to comment.