Skip to content

Commit

Permalink
fix: produce screenshots data always (#623)
Browse files Browse the repository at this point in the history
* fix: produce screenshots data always

* add comment
  • Loading branch information
vigneshshanmugam authored Oct 6, 2022
1 parent 3372f03 commit 622a35e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"micromatch": "^4.0.5",
"playwright-chromium": "=1.26.0",
"playwright-core": "=1.26.0",
"sharp": "^0.31.0",
"sharp": "^0.31.1",
"snakecase-keys": "^4.0.0",
"sonic-boom": "^3.2.0",
"ts-node": "^10.9.1",
Expand Down
7 changes: 4 additions & 3 deletions src/reporters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ function stepInfo(
}

export async function getScreenshotBlocks(screenshot: Buffer) {
const img = sharp(screenshot, { sequentialRead: true });
const { width, height } = await img.metadata();
const { width, height } = await sharp(screenshot).metadata();
/**
* Chop the screenshot image (1280*720) which is the default
* viewport size in to 64 equal blocks for a given image
Expand All @@ -248,7 +247,9 @@ export async function getScreenshotBlocks(screenshot: Buffer) {
const top = row * blockHeight;
for (let col = 0; col < divisions; col++) {
const left = col * blockWidth;
const buf = await img
// We create a new sharp instance for each block to avoid
// running in to extraction/orientation issues
const buf = await sharp(screenshot, { sequentialRead: true })
.extract({ top, left, width: blockWidth, height: blockHeight })
.jpeg()
.toBuffer();
Expand Down

0 comments on commit 622a35e

Please sign in to comment.