test: use node helpers for events.once and setTimeout promise (#37374)

This commit is contained in:
Jeremy Rose 2023-02-23 15:53:53 -08:00 committed by GitHub
parent 46c8b9c728
commit a3e3efe4c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 932 additions and 927 deletions

View file

@ -5,8 +5,9 @@ import * as path from 'path';
import * as fs from 'fs';
import * as http from 'http';
import { closeWindow } from './lib/window-helpers';
import { emittedOnce } from './lib/events-helpers';
import { ifit, ifdescribe, delay, listen } from './lib/spec-helpers';
import { ifit, ifdescribe, listen } from './lib/spec-helpers';
import { once } from 'events';
import { setTimeout } from 'timers/promises';
const features = process._linkedBinding('electron_common_features');
const v8Util = process._linkedBinding('electron_common_v8_util');
@ -17,7 +18,7 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', function ()
let w: BrowserWindow;
async function rightClick () {
const contextMenuPromise = emittedOnce(w.webContents, 'context-menu');
const contextMenuPromise = once(w.webContents, 'context-menu');
w.webContents.sendInputEvent({
type: 'mouseDown',
button: 'right',
@ -35,7 +36,7 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', function ()
const timeout = (process.env.IS_ASAN ? 180 : 10) * 1000;
let contextMenuParams = await rightClick();
while (!fn(contextMenuParams) && (Date.now() - now < timeout)) {
await delay(100);
await setTimeout(100);
contextMenuParams = await rightClick();
}
return contextMenuParams;
@ -107,7 +108,7 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', function ()
ifit(shouldRun)('should detect incorrectly spelled words as incorrect after disabling all languages and re-enabling', async () => {
w.webContents.session.setSpellCheckerLanguages([]);
await delay(500);
await setTimeout(500);
w.webContents.session.setSpellCheckerLanguages(['en-US']);
await w.webContents.executeJavaScript('document.body.querySelector("textarea").value = "typograpy"');
await w.webContents.executeJavaScript('document.body.querySelector("textarea").focus()');
@ -147,13 +148,13 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', function ()
// spellCheckerEnabled is sent to renderer asynchronously and there is
// no event notifying when it is finished, so wait a little while to
// ensure the setting has been changed in renderer.
await delay(500);
await setTimeout(500);
expect(await callWebFrameFn('isWordMisspelled("typograpy")')).to.equal(false);
w.webContents.session.spellCheckerEnabled = true;
v8Util.runUntilIdle();
expect(w.webContents.session.spellCheckerEnabled).to.be.true();
await delay(500);
await setTimeout(500);
expect(await callWebFrameFn('isWordMisspelled("typograpy")')).to.equal(true);
});
});