test: use delay() helper (#24321)
This commit is contained in:
parent
8eb198bab4
commit
1c49e4e376
9 changed files with 24 additions and 36 deletions
|
@ -9,7 +9,7 @@ import { AddressInfo } from 'net';
|
|||
import { app, BrowserWindow, BrowserView, ipcMain, OnBeforeSendHeadersListenerDetails, protocol, screen, webContents, session, WebContents } from 'electron/main';
|
||||
|
||||
import { emittedOnce, emittedUntil } from './events-helpers';
|
||||
import { ifit, ifdescribe } from './spec-helpers';
|
||||
import { ifit, ifdescribe, delay } from './spec-helpers';
|
||||
import { closeWindow, closeAllWindows } from './window-helpers';
|
||||
|
||||
const features = process._linkedBinding('electron_common_features');
|
||||
|
@ -3145,7 +3145,7 @@ describe('BrowserWindow module', () => {
|
|||
await w.webContents.executeJavaScript('document.body.webkitRequestFullscreen()', true);
|
||||
await emittedOnce(w, 'enter-full-screen');
|
||||
// Wait a tick for the full-screen state to 'stick'
|
||||
await new Promise(resolve => setTimeout(resolve));
|
||||
await delay();
|
||||
w.setFullScreen(false);
|
||||
await emittedOnce(w, 'leave-html-full-screen');
|
||||
});
|
||||
|
@ -3786,7 +3786,6 @@ describe('BrowserWindow module', () => {
|
|||
});
|
||||
|
||||
// fullscreen events are dispatched eagerly and twiddling things too fast can confuse poor Electron
|
||||
const tick = () => new Promise(resolve => setTimeout(resolve));
|
||||
|
||||
ifdescribe(process.platform === 'darwin')('kiosk state', () => {
|
||||
it('with properties', () => {
|
||||
|
@ -3798,7 +3797,7 @@ describe('BrowserWindow module', () => {
|
|||
it('can be changed ', (done) => {
|
||||
const w = new BrowserWindow();
|
||||
w.once('enter-full-screen', async () => {
|
||||
await tick();
|
||||
await delay();
|
||||
w.kiosk = false;
|
||||
expect(w.kiosk).to.be.false();
|
||||
});
|
||||
|
@ -3819,7 +3818,7 @@ describe('BrowserWindow module', () => {
|
|||
it('can be changed ', (done) => {
|
||||
const w = new BrowserWindow();
|
||||
w.once('enter-full-screen', async () => {
|
||||
await tick();
|
||||
await delay();
|
||||
w.setKiosk(false);
|
||||
expect(w.isKiosk()).to.be.false('isKiosk');
|
||||
});
|
||||
|
@ -3837,7 +3836,7 @@ describe('BrowserWindow module', () => {
|
|||
const w = new BrowserWindow({ resizable: false });
|
||||
w.once('enter-full-screen', async () => {
|
||||
expect(w.resizable).to.be.true('resizable');
|
||||
await tick();
|
||||
await delay();
|
||||
w.setFullScreen(false);
|
||||
});
|
||||
w.once('leave-full-screen', () => {
|
||||
|
@ -3853,7 +3852,7 @@ describe('BrowserWindow module', () => {
|
|||
const w = new BrowserWindow();
|
||||
w.once('enter-full-screen', async () => {
|
||||
expect(w.isFullScreen()).to.be.true('isFullScreen');
|
||||
await tick();
|
||||
await delay();
|
||||
w.setFullScreen(false);
|
||||
});
|
||||
w.once('leave-full-screen', () => {
|
||||
|
@ -3887,9 +3886,9 @@ describe('BrowserWindow module', () => {
|
|||
const w = new BrowserWindow();
|
||||
w.once('enter-full-screen', async () => {
|
||||
expect(w.isFullScreen()).to.be.true('isFullScreen');
|
||||
await tick();
|
||||
await delay();
|
||||
w.setKiosk(true);
|
||||
await tick();
|
||||
await delay();
|
||||
w.setKiosk(false);
|
||||
expect(w.isFullScreen()).to.be.true('isFullScreen');
|
||||
w.setFullScreen(false);
|
||||
|
|
|
@ -2,13 +2,7 @@ import { expect } from 'chai';
|
|||
import { app, contentTracing, TraceConfig, TraceCategoriesAndOptions } from 'electron/main';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { ifdescribe } from './spec-helpers';
|
||||
|
||||
const timeout = async (milliseconds: number) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, milliseconds);
|
||||
});
|
||||
};
|
||||
import { ifdescribe, delay } from './spec-helpers';
|
||||
|
||||
// FIXME: The tests are skipped on arm/arm64.
|
||||
ifdescribe(!(process.platform === 'linux' && ['arm', 'arm64'].includes(process.arch)))('contentTracing', () => {
|
||||
|
@ -16,7 +10,7 @@ ifdescribe(!(process.platform === 'linux' && ['arm', 'arm64'].includes(process.a
|
|||
await app.whenReady();
|
||||
|
||||
await contentTracing.startRecording(options);
|
||||
await timeout(recordTimeInMilliseconds);
|
||||
await delay(recordTimeInMilliseconds);
|
||||
const resultFilePath = await contentTracing.stopRecording(outputFilePath);
|
||||
|
||||
return resultFilePath;
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as childProcess from 'child_process';
|
|||
import * as http from 'http';
|
||||
import * as Busboy from 'busboy';
|
||||
import * as path from 'path';
|
||||
import { ifdescribe, ifit, defer, startRemoteControlApp } from './spec-helpers';
|
||||
import { ifdescribe, ifit, defer, startRemoteControlApp, delay } from './spec-helpers';
|
||||
import { app } from 'electron/main';
|
||||
import { crashReporter } from 'electron/common';
|
||||
import { AddressInfo } from 'net';
|
||||
|
@ -281,7 +281,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_
|
|||
waitForCrash().then(() => expect.fail('expected not to receive a dump'));
|
||||
await runCrashApp('renderer', port, ['--no-upload']);
|
||||
// wait a sec in case the crash reporter is about to upload a crash
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
await delay(1000);
|
||||
expect(getCrashes()).to.have.length(0);
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// python-dbusmock.
|
||||
import { expect } from 'chai';
|
||||
import * as dbus from 'dbus-native';
|
||||
import { ifdescribe } from './spec-helpers';
|
||||
import { ifdescribe, delay } from './spec-helpers';
|
||||
import { promisify } from 'util';
|
||||
|
||||
describe('powerMonitor', () => {
|
||||
|
@ -60,7 +60,7 @@ describe('powerMonitor', () => {
|
|||
while (retriesRemaining-- > 0) {
|
||||
calls = await getCalls();
|
||||
if (calls.length > 0) break;
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
await delay(1000);
|
||||
}
|
||||
expect(calls).to.be.an('array').that.has.lengthOf(1);
|
||||
expect(calls[0].slice(1)).to.deep.equal([
|
||||
|
|
|
@ -11,6 +11,7 @@ import { EventEmitter } from 'events';
|
|||
import { closeWindow } from './window-helpers';
|
||||
import { emittedOnce } from './events-helpers';
|
||||
import { WebmGenerator } from './video-helpers';
|
||||
import { delay } from './spec-helpers';
|
||||
|
||||
const fixturesPath = path.resolve(__dirname, '..', 'spec', 'fixtures');
|
||||
|
||||
|
@ -33,12 +34,6 @@ const postData = {
|
|||
type: 'string'
|
||||
};
|
||||
|
||||
function delay (ms: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
function getStream (chunkSize = text.length, data: Buffer | string = text) {
|
||||
const body = new stream.PassThrough();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import { BrowserWindow, ipcMain, webContents, session, WebContents, app } from '
|
|||
import { clipboard } from 'electron/common';
|
||||
import { emittedOnce } from './events-helpers';
|
||||
import { closeAllWindows } from './window-helpers';
|
||||
import { ifdescribe, ifit } from './spec-helpers';
|
||||
import { ifdescribe, ifit, delay } from './spec-helpers';
|
||||
|
||||
const pdfjs = require('pdfjs-dist');
|
||||
const fixturesPath = path.resolve(__dirname, '..', 'spec', 'fixtures');
|
||||
|
@ -406,7 +406,7 @@ describe('webContents module', () => {
|
|||
expect(() => { webContents.getFocusedWebContents(); }).to.not.throw();
|
||||
|
||||
// Work around https://github.com/electron/electron/issues/19985
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
await delay();
|
||||
|
||||
const devToolsClosed = emittedOnce(w.webContents, 'devtools-closed');
|
||||
w.webContents.closeDevTools();
|
||||
|
@ -490,7 +490,7 @@ describe('webContents module', () => {
|
|||
emittedOnce(w.webContents, 'devtools-opened'),
|
||||
emittedOnce(w.webContents, 'devtools-focused')
|
||||
]);
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
await delay();
|
||||
expect(w.isFocused()).to.be.false();
|
||||
});
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import * as url from 'url';
|
|||
import * as ChildProcess from 'child_process';
|
||||
import { EventEmitter } from 'events';
|
||||
import { promisify } from 'util';
|
||||
import { ifit, ifdescribe } from './spec-helpers';
|
||||
import { ifit, ifdescribe, delay } from './spec-helpers';
|
||||
import { AddressInfo } from 'net';
|
||||
import { PipeTransport } from './pipe-transport';
|
||||
|
||||
|
@ -1374,7 +1374,7 @@ describe('iframe using HTML fullscreen API while window is OS-fullscreened', ()
|
|||
"document.querySelector('iframe').contentWindow.postMessage('exitFullscreen', '*')"
|
||||
);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
await delay(500);
|
||||
|
||||
const width = await w.webContents.executeJavaScript(
|
||||
"document.querySelector('iframe').offsetWidth"
|
||||
|
|
|
@ -6,7 +6,7 @@ import * as v8 from 'v8';
|
|||
export const ifit = (condition: boolean) => (condition ? it : it.skip);
|
||||
export const ifdescribe = (condition: boolean) => (condition ? describe : describe.skip);
|
||||
|
||||
export const delay = (time: number) => new Promise(resolve => setTimeout(resolve, time));
|
||||
export const delay = (time: number = 0) => new Promise(resolve => setTimeout(resolve, time));
|
||||
|
||||
type CleanupFunction = (() => void) | (() => Promise<void>)
|
||||
const cleanupFunctions: CleanupFunction[] = [];
|
||||
|
|
|
@ -4,7 +4,7 @@ import { expect } from 'chai';
|
|||
import * as path from 'path';
|
||||
import { closeWindow } from './window-helpers';
|
||||
import { emittedOnce } from './events-helpers';
|
||||
import { ifit, ifdescribe } from './spec-helpers';
|
||||
import { ifit, ifdescribe, delay } from './spec-helpers';
|
||||
|
||||
const features = process._linkedBinding('electron_common_features');
|
||||
|
||||
|
@ -33,7 +33,7 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', () => {
|
|||
await w.webContents.executeJavaScript('document.body.querySelector("textarea").focus()');
|
||||
const contextMenuPromise = emittedOnce(w.webContents, 'context-menu');
|
||||
// Wait for spellchecker to load
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
await delay(500);
|
||||
w.webContents.sendInputEvent({
|
||||
type: 'mouseDown',
|
||||
button: 'right',
|
||||
|
@ -50,7 +50,7 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', () => {
|
|||
await w.webContents.executeJavaScript('document.body.querySelector("textarea").focus()');
|
||||
const contextMenuPromise = emittedOnce(w.webContents, 'context-menu');
|
||||
// Wait for spellchecker to load
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
await delay(500);
|
||||
w.webContents.sendInputEvent({
|
||||
type: 'mouseDown',
|
||||
button: 'right',
|
||||
|
|
Loading…
Reference in a new issue