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:
parent
267c0796dd
commit
a6133e85d1
8 changed files with 215 additions and 141 deletions
|
@ -11,7 +11,7 @@ import { app, BrowserWindow, BrowserView, dialog, ipcMain, OnBeforeSendHeadersLi
|
|||
import { emittedUntil, emittedNTimes } from './lib/events-helpers';
|
||||
import { ifit, ifdescribe, defer, listen } from './lib/spec-helpers';
|
||||
import { closeWindow, closeAllWindows } from './lib/window-helpers';
|
||||
import { areColorsSimilar, captureScreen, HexColors, getPixelColor, hasCapturableScreen } from './lib/screen-helpers';
|
||||
import { HexColors, hasCapturableScreen, ScreenCapture } from './lib/screen-helpers';
|
||||
import { once } from 'node:events';
|
||||
import { setTimeout } from 'node:timers/promises';
|
||||
import { setTimeout as syncSetTimeout } from 'node:timers';
|
||||
|
@ -1246,6 +1246,7 @@ describe('BrowserWindow module', () => {
|
|||
}
|
||||
});
|
||||
|
||||
// FIXME: disabled in `disabled-tests.json`
|
||||
ifit(process.platform === 'darwin')('it does not activate the app if focusing an inactive panel', async () => {
|
||||
// Show to focus app, then remove existing window
|
||||
w.show();
|
||||
|
@ -6496,18 +6497,22 @@ describe('BrowserWindow module', () => {
|
|||
await foregroundWindow.loadFile(colorFile);
|
||||
|
||||
await setTimeout(1000);
|
||||
const screenCapture = await captureScreen();
|
||||
const leftHalfColor = getPixelColor(screenCapture, {
|
||||
x: display.size.width / 4,
|
||||
y: display.size.height / 2
|
||||
});
|
||||
const rightHalfColor = getPixelColor(screenCapture, {
|
||||
x: display.size.width - (display.size.width / 4),
|
||||
y: display.size.height / 2
|
||||
});
|
||||
|
||||
expect(areColorsSimilar(leftHalfColor, HexColors.GREEN)).to.be.true();
|
||||
expect(areColorsSimilar(rightHalfColor, HexColors.RED)).to.be.true();
|
||||
const screenCapture = await ScreenCapture.createForDisplay(display);
|
||||
await screenCapture.expectColorAtPointOnDisplayMatches(
|
||||
HexColors.GREEN,
|
||||
(size) => ({
|
||||
x: size.width / 4,
|
||||
y: size.height / 2
|
||||
})
|
||||
);
|
||||
await screenCapture.expectColorAtPointOnDisplayMatches(
|
||||
HexColors.RED,
|
||||
(size) => ({
|
||||
x: size.width * 3 / 4,
|
||||
y: size.height / 2
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
ifit(process.platform === 'darwin')('Allows setting a transparent window via CSS', async () => {
|
||||
|
@ -6537,13 +6542,9 @@ describe('BrowserWindow module', () => {
|
|||
await once(ipcMain, 'set-transparent');
|
||||
|
||||
await setTimeout(1000);
|
||||
const screenCapture = await captureScreen();
|
||||
const centerColor = getPixelColor(screenCapture, {
|
||||
x: display.size.width / 2,
|
||||
y: display.size.height / 2
|
||||
});
|
||||
|
||||
expect(areColorsSimilar(centerColor, HexColors.PURPLE)).to.be.true();
|
||||
const screenCapture = await ScreenCapture.createForDisplay(display);
|
||||
await screenCapture.expectColorAtCenterMatches(HexColors.PURPLE);
|
||||
});
|
||||
|
||||
// Linux and arm64 platforms (WOA and macOS) do not return any capture sources
|
||||
|
@ -6560,15 +6561,11 @@ describe('BrowserWindow module', () => {
|
|||
await window.webContents.loadURL('data:text/html,<head><meta name="color-scheme" content="dark"></head>');
|
||||
|
||||
await setTimeout(1000);
|
||||
const screenCapture = await captureScreen();
|
||||
const centerColor = getPixelColor(screenCapture, {
|
||||
x: display.size.width / 2,
|
||||
y: display.size.height / 2
|
||||
});
|
||||
window.close();
|
||||
|
||||
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);
|
||||
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -6590,13 +6587,9 @@ describe('BrowserWindow module', () => {
|
|||
await once(w, 'ready-to-show');
|
||||
|
||||
await setTimeout(1000);
|
||||
const screenCapture = await captureScreen();
|
||||
const centerColor = getPixelColor(screenCapture, {
|
||||
x: display.size.width / 2,
|
||||
y: display.size.height / 2
|
||||
});
|
||||
|
||||
expect(areColorsSimilar(centerColor, HexColors.BLUE)).to.be.true();
|
||||
const screenCapture = await ScreenCapture.createForDisplay(display);
|
||||
await screenCapture.expectColorAtCenterMatches(HexColors.BLUE);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue