Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: attempt to fix flaky nativeTheme spec #29035

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions spec-main/api-native-theme-spec.ts
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { nativeTheme, systemPreferences, BrowserWindow } from 'electron/main';
import { nativeTheme, systemPreferences, BrowserWindow, ipcMain } from 'electron/main';
import * as os from 'os';
import * as path from 'path';
import * as semver from 'semver';
Expand Down Expand Up @@ -75,14 +75,24 @@ describe('nativeTheme module', () => {
};

it('should override the result of prefers-color-scheme CSS media query', async () => {
const w = new BrowserWindow({ show: false });
const w = new BrowserWindow({ show: false, webPreferences: { contextIsolation: false, nodeIntegration: true } });
await w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
await w.webContents.executeJavaScript(`
window.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', () => require('electron').ipcRenderer.send('theme-change'))
`);
const originalSystemIsDark = await getPrefersColorSchemeIsDark(w);
let changePromise: Promise<any[]> = emittedOnce(ipcMain, 'theme-change');
nativeTheme.themeSource = 'dark';
if (!originalSystemIsDark) await changePromise;
expect(await getPrefersColorSchemeIsDark(w)).to.equal(true);
changePromise = emittedOnce(ipcMain, 'theme-change');
nativeTheme.themeSource = 'light';
await changePromise;
expect(await getPrefersColorSchemeIsDark(w)).to.equal(false);
changePromise = emittedOnce(ipcMain, 'theme-change');
nativeTheme.themeSource = 'system';
if (originalSystemIsDark) await changePromise;
expect(await getPrefersColorSchemeIsDark(w)).to.equal(originalSystemIsDark);
w.close();
});
Expand Down