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