test: remove redundant color diffing dependency (#33215)

This commit is contained in:
Shelley Vohr 2022-10-11 10:11:58 -07:00 committed by GitHub
parent b3fd5eb258
commit e8ae0571b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 93 additions and 572 deletions

View file

@ -1,15 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>test-color-window</title>
<style>
body {
background: green;
}
</style>
</head>
<body id="body">
<script src="./renderer.js"></script>
</body>
</html>

View file

@ -1,61 +0,0 @@
const { app, BrowserWindow, desktopCapturer, ipcMain } = require('electron');
const getColors = require('get-image-colors');
const colors = {};
// Fetch the test window.
const getWindow = async () => {
const sources = await desktopCapturer.getSources({ types: ['window'] });
const filtered = sources.filter(s => s.name === 'test-color-window');
if (filtered.length === 0) {
throw new Error('Could not find test window');
}
return filtered[0];
};
async function createWindow () {
const mainWindow = new BrowserWindow({
frame: false,
transparent: true,
vibrancy: 'under-window',
webPreferences: {
backgroundThrottling: false,
contextIsolation: false,
nodeIntegration: true
}
});
await mainWindow.loadFile('index.html');
// Get initial green background color.
const window = await getWindow();
const buf = window.thumbnail.toPNG();
const result = await getColors(buf, { count: 1, type: 'image/png' });
colors.green = result[0].hex();
}
ipcMain.on('set-transparent', async () => {
// Get updated background color.
const window = await getWindow();
const buf = window.thumbnail.toPNG();
const result = await getColors(buf, { count: 1, type: 'image/png' });
colors.transparent = result[0].hex();
const { green, transparent } = colors;
console.log({ green, transparent });
process.exit(green === transparent ? 1 : 0);
});
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});

View file

@ -1,4 +0,0 @@
{
"name": "electron-test-background-color-transparent",
"main": "main.js"
}

View file

@ -1,9 +0,0 @@
const { ipcRenderer } = require('electron');
window.setTimeout(async (_) => {
document.body.style.background = 'transparent';
window.setTimeout(async (_) => {
ipcRenderer.send('set-transparent');
}, 2000);
}, 3000);