test: disable flaky macOS panel test & refactor screen capture testing (#41441)

* Disable flaky test

* Add helper for storing test artifacts

* Refactor screen capture tests

We have a pattern for inspecting a screen capture, so this refactor codifies that pattern into a helper. This gives us shorter test code, consistency (previously, the display in test code and the display captured could theoretically be different), and better debugging/observability on failure.
This commit is contained in:
Calvin 2024-02-27 20:54:20 -07:00 committed by GitHub
parent 267c0796dd
commit a6133e85d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 215 additions and 141 deletions

View file

@ -1,6 +1,6 @@
import { BrowserWindow, screen } from 'electron';
import { expect, assert } from 'chai';
import { areColorsSimilar, captureScreen, HexColors, getPixelColor } from './lib/screen-helpers';
import { HexColors, ScreenCapture } from './lib/screen-helpers';
import { ifit } from './lib/spec-helpers';
import { closeAllWindows } from './lib/window-helpers';
import { once } from 'node:events';
@ -209,12 +209,8 @@ describe('webContents.setWindowOpenHandler', () => {
childWindow.setBounds(display.bounds);
await childWindow.webContents.executeJavaScript("const meta = document.createElement('meta'); meta.name = 'color-scheme'; meta.content = 'dark'; document.head.appendChild(meta); true;");
await setTimeoutAsync(1000);
const screenCapture = await captureScreen();
const centerColor = getPixelColor(screenCapture, {
x: display.size.width / 2,
y: display.size.height / 2
});
const screenCapture = await ScreenCapture.createForDisplay(display);
// color-scheme is set to dark so background should not be white
expect(areColorsSimilar(centerColor, HexColors.WHITE)).to.be.false();
await screenCapture.expectColorAtCenterDoesNotMatch(HexColors.WHITE);
});
});