Skip to content

Commit

Permalink
screenshot: replace the unit test for CaptureScreenshot
Browse files Browse the repository at this point in the history
This unit test is copied from puppeteer:
- testdata/screenshots/sanity.png
  • Loading branch information
ZekeLu committed Jun 17, 2021
1 parent e5f5a89 commit 7df884a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions screenshot_test.go
Expand Up @@ -88,30 +88,23 @@ func TestScreenshotHighDPI(t *testing.T) {
func TestCaptureScreenshot(t *testing.T) {
t.Parallel()

ctx, cancel := testAllocate(t, "image.html")
ctx, cancel := testAllocate(t, "grid.html")
defer cancel()

const width, height = 650, 450

// set the viewport size, to know what screenshot size to expect
var buf []byte
if err := Run(ctx,
EmulateViewport(width, height),
EmulateViewport(500, 500),
CaptureScreenshot(&buf),
); err != nil {
t.Fatal(err)
}

config, format, err := image.DecodeConfig(bytes.NewReader(buf))
diff, err := matchPixel(buf, "sanity.png")
if err != nil {
t.Fatal(err)
}
if want := "png"; format != want {
t.Fatalf("expected format to be %q, got %q", want, format)
}
if config.Width != width || config.Height != height {
t.Fatalf("expected dimensions to be %d*%d, got %d*%d",
width, height, config.Width, config.Height)
if diff != 0 {
t.Fatalf("screenshot does not match. diff: %v", diff)
}
}

Expand Down
Binary file added testdata/screenshots/sanity.png
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 7df884a

Please sign in to comment.