Skip to content

Commit b8a21db

Browse files
authored
test: migrate to helpers & disabled tests list (electron#37513)
* test: migrate to helpers & disabled tests list * can't disable a test suite * correct condition * address review comments
1 parent 58f3c0e commit b8a21db

20 files changed

+95
-117
lines changed

spec/api-app-spec.ts

+27-54
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,7 @@ describe('app module', () => {
188188
expect(code).to.equal(123, 'exit code should be 123, if you see this please tag @MarshallOfSound');
189189
});
190190

191-
it('exits gracefully', async function () {
192-
if (!['darwin', 'linux'].includes(process.platform)) {
193-
this.skip();
194-
return;
195-
}
196-
191+
ifit(['darwin', 'linux'].includes(process.platform))('exits gracefully', async function () {
197192
const electronPath = process.execPath;
198193
const appPath = path.join(fixturesPath, 'api', 'singleton');
199194
appProcess = cp.spawn(electronPath, [appPath]);
@@ -409,13 +404,7 @@ describe('app module', () => {
409404
});
410405
});
411406

412-
describe('app.setUserActivity(type, userInfo)', () => {
413-
before(function () {
414-
if (process.platform !== 'darwin') {
415-
this.skip();
416-
}
417-
});
418-
407+
ifdescribe(process.platform === 'darwin')('app.setUserActivity(type, userInfo)', () => {
419408
it('sets the current activity', () => {
420409
app.setUserActivity('com.electron.testActivity', { testData: '123' });
421410
expect(app.getCurrentActivityType()).to.equal('com.electron.testActivity');
@@ -737,9 +726,7 @@ describe('app module', () => {
737726
expect(app.getLoginItemSettings().openAtLogin).to.equal(false);
738727
});
739728

740-
it('correctly sets and unsets the LoginItem as hidden', function () {
741-
if (process.platform !== 'darwin') this.skip();
742-
729+
ifit(process.platform === 'darwin')('correctly sets and unsets the LoginItem as hidden', function () {
743730
expect(app.getLoginItemSettings().openAtLogin).to.equal(false);
744731
expect(app.getLoginItemSettings().openAsHidden).to.equal(false);
745732

@@ -1099,13 +1086,10 @@ describe('app module', () => {
10991086
});
11001087
});
11011088

1102-
describe('select-client-certificate event', () => {
1089+
ifdescribe(process.platform !== 'linux')('select-client-certificate event', () => {
11031090
let w: BrowserWindow;
11041091

11051092
before(function () {
1106-
if (process.platform === 'linux') {
1107-
this.skip();
1108-
}
11091093
session.fromPartition('empty-certificate').setCertificateVerifyProc((req, cb) => { cb(0); });
11101094
});
11111095

@@ -1134,7 +1118,7 @@ describe('app module', () => {
11341118
});
11351119
});
11361120

1137-
describe('setAsDefaultProtocolClient(protocol, path, args)', () => {
1121+
ifdescribe(process.platform === 'win32')('setAsDefaultProtocolClient(protocol, path, args)', () => {
11381122
const protocol = 'electron-test';
11391123
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe');
11401124
const processStartArgs = [
@@ -1146,16 +1130,12 @@ describe('app module', () => {
11461130
let classesKey: any;
11471131

11481132
before(function () {
1149-
if (process.platform !== 'win32') {
1150-
this.skip();
1151-
} else {
1152-
Winreg = require('winreg');
1133+
Winreg = require('winreg');
11531134

1154-
classesKey = new Winreg({
1155-
hive: Winreg.HKCU,
1156-
key: '\\Software\\Classes\\'
1157-
});
1158-
}
1135+
classesKey = new Winreg({
1136+
hive: Winreg.HKCU,
1137+
key: '\\Software\\Classes\\'
1138+
});
11591139
});
11601140

11611141
after(function (done) {
@@ -1240,14 +1220,11 @@ describe('app module', () => {
12401220
});
12411221

12421222
describe('getApplicationNameForProtocol()', () => {
1243-
it('returns application names for common protocols', function () {
1223+
// TODO: Linux CI doesn't have registered http & https handlers
1224+
ifit(!(process.env.CI && process.platform === 'linux'))('returns application names for common protocols', function () {
12441225
// We can't expect particular app names here, but these protocols should
12451226
// at least have _something_ registered. Except on our Linux CI
12461227
// environment apparently.
1247-
if (process.platform === 'linux') {
1248-
this.skip();
1249-
}
1250-
12511228
const protocols = [
12521229
'http://',
12531230
'https://'
@@ -1492,28 +1469,25 @@ describe('app module', () => {
14921469
});
14931470
});
14941471

1495-
describe('sandbox options', () => {
1472+
ifdescribe(!(process.platform === 'linux' && (process.arch === 'arm64' || process.arch === 'arm')))('sandbox options', () => {
1473+
// Our ARM tests are run on VSTS rather than CircleCI, and the Docker
1474+
// setup on VSTS disallows syscalls that Chrome requires for setting up
1475+
// sandboxing.
1476+
// See:
1477+
// - https://docs.docker.com/engine/security/seccomp/#significant-syscalls-blocked-by-the-default-profile
1478+
// - https://chromium.googlesource.com/chromium/src/+/70.0.3538.124/sandbox/linux/services/credentials.cc#292
1479+
// - https://github.com/docker/docker-ce/blob/ba7dfc59ccfe97c79ee0d1379894b35417b40bca/components/engine/profiles/seccomp/seccomp_default.go#L497
1480+
// - https://blog.jessfraz.com/post/how-to-use-new-docker-seccomp-profiles/
1481+
//
1482+
// Adding `--cap-add SYS_ADMIN` or `--security-opt seccomp=unconfined`
1483+
// to the Docker invocation allows the syscalls that Chrome needs, but
1484+
// are probably more permissive than we'd like.
1485+
14961486
let appProcess: cp.ChildProcess = null as any;
14971487
let server: net.Server = null as any;
14981488
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-mixed-sandbox' : '/tmp/electron-mixed-sandbox';
14991489

15001490
beforeEach(function (done) {
1501-
if (process.platform === 'linux' && (process.arch === 'arm64' || process.arch === 'arm')) {
1502-
// Our ARM tests are run on VSTS rather than CircleCI, and the Docker
1503-
// setup on VSTS disallows syscalls that Chrome requires for setting up
1504-
// sandboxing.
1505-
// See:
1506-
// - https://docs.docker.com/engine/security/seccomp/#significant-syscalls-blocked-by-the-default-profile
1507-
// - https://chromium.googlesource.com/chromium/src/+/70.0.3538.124/sandbox/linux/services/credentials.cc#292
1508-
// - https://github.com/docker/docker-ce/blob/ba7dfc59ccfe97c79ee0d1379894b35417b40bca/components/engine/profiles/seccomp/seccomp_default.go#L497
1509-
// - https://blog.jessfraz.com/post/how-to-use-new-docker-seccomp-profiles/
1510-
//
1511-
// Adding `--cap-add SYS_ADMIN` or `--security-opt seccomp=unconfined`
1512-
// to the Docker invocation allows the syscalls that Chrome needs, but
1513-
// are probably more permissive than we'd like.
1514-
this.skip();
1515-
return;
1516-
}
15171491
fs.unlink(socketPath, () => {
15181492
server = net.createServer();
15191493
server.listen(socketPath);
@@ -1613,8 +1587,7 @@ describe('app module', () => {
16131587
});
16141588
});
16151589

1616-
const dockDescribe = process.platform === 'darwin' ? describe : describe.skip;
1617-
dockDescribe('dock APIs', () => {
1590+
ifdescribe(process.platform === 'darwin')('dock APIs', () => {
16181591
after(async () => {
16191592
await app.dock.show();
16201593
});

spec/api-autoupdater-darwin-spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ifdescribe(process.platform === 'darwin' && !(process.env.CI && process.arch ===
2929
if (process.env.CI && !process.env.CIRCLE_PR_NUMBER) {
3030
throw new Error('No valid signing identity available to run autoUpdater specs');
3131
}
32+
3233
this.skip();
3334
} else {
3435
identity = result.stdout.toString().trim();

spec/api-browser-window-spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ describe('BrowserWindow module', () => {
359359
w.loadURL('about:blank');
360360
await readyToShow;
361361
});
362-
// TODO(deepak1556): The error code now seems to be `ERR_FAILED`, verify what
362+
// DISABLED-FIXME(deepak1556): The error code now seems to be `ERR_FAILED`, verify what
363363
// changed and adjust the test.
364-
it.skip('should emit did-fail-load event for files that do not exist', async () => {
364+
it('should emit did-fail-load event for files that do not exist', async () => {
365365
const didFailLoad = once(w.webContents, 'did-fail-load');
366366
w.loadURL('file://a.txt');
367367
const [, code, desc,, isMainFrame] = await didFailLoad;
@@ -4083,9 +4083,9 @@ describe('BrowserWindow module', () => {
40834083
}
40844084
});
40854085

4086-
// FIXME(MarshallOfSound): This test fails locally 100% of the time, on CI it started failing
4086+
// DISABLED-FIXME(MarshallOfSound): This test fails locally 100% of the time, on CI it started failing
40874087
// when we introduced the compositor recycling patch. Should figure out how to fix this
4088-
it.skip('visibilityState remains visible if backgroundThrottling is disabled', async () => {
4088+
it('visibilityState remains visible if backgroundThrottling is disabled', async () => {
40894089
const w = new BrowserWindow({
40904090
show: false,
40914091
width: 100,

spec/api-media-handler-spec.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ ifdescribe(features.isDesktopCapturerEnabled())('setDisplayMediaRequestHandler',
2323
server.close();
2424
});
2525

26-
// NOTE(nornagon): this test fails on our macOS CircleCI runners with the
26+
// FIXME(nornagon): this test fails on our macOS CircleCI runners with the
2727
// error message:
2828
// [ERROR:video_capture_device_client.cc(659)] error@ OnStart@content/browser/media/capture/desktop_capture_device_mac.cc:98, CGDisplayStreamCreate failed, OS message: Value too large to be stored in data type (84)
2929
// This is possibly related to the OS/VM setup that CircleCI uses for macOS.
3030
// Our arm64 runners are in @jkleinsc's office, and are real machines, so the
3131
// test works there.
3232
ifit(!(process.platform === 'darwin' && process.arch === 'x64'))('works when calling getDisplayMedia', async function () {
33-
if ((await desktopCapturer.getSources({ types: ['screen'] })).length === 0) { return this.skip(); }
33+
if ((await desktopCapturer.getSources({ types: ['screen'] })).length === 0) {
34+
return this.skip();
35+
}
3436
const ses = session.fromPartition('' + Math.random());
3537
let requestHandlerCalled = false;
3638
let mediaRequest: any = null;

spec/api-menu-item-spec.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BrowserWindow, app, Menu, MenuItem, MenuItemConstructorOptions } from 'electron/main';
22
import { expect } from 'chai';
3+
import { ifdescribe } from './lib/spec-helpers';
34
import { closeAllWindows } from './lib/window-helpers';
45
import { roleList, execute } from '../lib/browser/api/menu-item-roles';
56

@@ -280,13 +281,7 @@ describe('MenuItems', () => {
280281
});
281282
});
282283

283-
describe('MenuItem appMenu', () => {
284-
before(function () {
285-
if (process.platform !== 'darwin') {
286-
this.skip();
287-
}
288-
});
289-
284+
ifdescribe(process.platform === 'darwin')('MenuItem appMenu', () => {
290285
it('includes a default submenu layout when submenu is empty', () => {
291286
const item = new MenuItem({ role: 'appMenu' });
292287

spec/api-menu-spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,8 @@ describe('Menu module', function () {
891891
expect(Menu.getApplicationMenu()).to.not.be.null('application menu');
892892
});
893893

894-
// TODO(nornagon): this causes the focus handling tests to fail
895-
it.skip('unsets a menu with null', () => {
894+
// DISABLED-FIXME(nornagon): this causes the focus handling tests to fail
895+
it('unsets a menu with null', () => {
896896
Menu.setApplicationMenu(null);
897897
expect(Menu.getApplicationMenu()).to.be.null('application menu');
898898
});

spec/api-process-spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ describe('process module', () => {
204204
});
205205

206206
describe('process.takeHeapSnapshot()', () => {
207-
// TODO(nornagon): this seems to take a really long time when run in the
207+
// DISABLED-FIXME(nornagon): this seems to take a really long time when run in the
208208
// main process, for unknown reasons.
209-
it.skip('returns true on success', () => {
209+
it('returns true on success', () => {
210210
const filePath = path.join(app.getPath('temp'), 'test.heapsnapshot');
211211
defer(() => {
212212
try {

spec/api-protocol-spec.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ describe('protocol module', () => {
282282
ipcMain.once('loaded-iframe-custom-protocol', () => done());
283283
});
284284

285-
it.skip('throws an error when custom headers are invalid', (done) => {
285+
// DISABLED-FIXME
286+
it('throws an error when custom headers are invalid', (done) => {
286287
registerFileProtocol(protocolName, (request, callback) => {
287288
expect(() => callback({
288289
path: filePath,
@@ -879,7 +880,8 @@ describe('protocol module', () => {
879880
await requestReceived;
880881
});
881882

882-
it.skip('can access files through the FileSystem API', (done) => {
883+
// DISABLED-FIXME
884+
it('can access files through the FileSystem API', (done) => {
883885
const filePath = path.join(fixturesPath, 'pages', 'filesystem.html');
884886
protocol.registerFileProtocol(standardScheme, (request, callback) => callback({ path: filePath }));
885887
w.loadURL(origin);
@@ -928,8 +930,8 @@ describe('protocol module', () => {
928930
});
929931
});
930932

931-
// FIXME: Figure out why this test is failing
932-
it.skip('disallows CORS and fetch requests when only supportFetchAPI is specified', async () => {
933+
// DISABLED-FIXME: Figure out why this test is failing
934+
it('disallows CORS and fetch requests when only supportFetchAPI is specified', async () => {
933935
await allowsCORSRequests('no-cors', ['failed xhr', 'failed fetch'], /has been blocked by CORS policy/, () => {
934936
const { ipcRenderer } = require('electron');
935937
Promise.all([

spec/api-screen-spec.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from 'chai';
22
import { screen } from 'electron/main';
3+
import { ifit } from './lib/spec-helpers';
34

45
describe('screen module', () => {
56
describe('methods reassignment', () => {
@@ -28,8 +29,7 @@ describe('screen module', () => {
2829
expect(display).to.be.an('object');
2930
});
3031

31-
it('has the correct non-object properties', function () {
32-
if (process.platform === 'linux') this.skip();
32+
ifit(process.platform !== 'linux')('has the correct non-object properties', function () {
3333
const display = screen.getPrimaryDisplay();
3434

3535
expect(display).to.have.property('scaleFactor').that.is.a('number');
@@ -46,8 +46,7 @@ describe('screen module', () => {
4646
expect(display).to.have.property('displayFrequency').that.is.a('number');
4747
});
4848

49-
it('has a size object property', function () {
50-
if (process.platform === 'linux') this.skip();
49+
ifit(process.platform !== 'linux')('has a size object property', function () {
5150
const display = screen.getPrimaryDisplay();
5251

5352
expect(display).to.have.property('size').that.is.an('object');
@@ -56,8 +55,7 @@ describe('screen module', () => {
5655
expect(size).to.have.property('height').that.is.greaterThan(0);
5756
});
5857

59-
it('has a workAreaSize object property', function () {
60-
if (process.platform === 'linux') this.skip();
58+
ifit(process.platform !== 'linux')('has a workAreaSize object property', function () {
6159
const display = screen.getPrimaryDisplay();
6260

6361
expect(display).to.have.property('workAreaSize').that.is.an('object');
@@ -66,8 +64,7 @@ describe('screen module', () => {
6664
expect(workAreaSize).to.have.property('height').that.is.greaterThan(0);
6765
});
6866

69-
it('has a bounds object property', function () {
70-
if (process.platform === 'linux') this.skip();
67+
ifit(process.platform !== 'linux')('has a bounds object property', function () {
7168
const display = screen.getPrimaryDisplay();
7269

7370
expect(display).to.have.property('bounds').that.is.an('object');

spec/api-session-spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ describe('session module', () => {
172172
expect(list.some(cookie => cookie.name === name && cookie.value === value)).to.equal(false);
173173
});
174174

175-
it.skip('should set cookie for standard scheme', async () => {
175+
// DISABLED-FIXME
176+
it('should set cookie for standard scheme', async () => {
176177
const { cookies } = session.defaultSession;
177178
const domain = 'fake-host';
178179
const url = `${standardScheme}://${domain}`;

spec/api-web-contents-spec.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as fs from 'fs';
55
import * as http from 'http';
66
import { BrowserWindow, ipcMain, webContents, session, app, BrowserView } from 'electron/main';
77
import { closeAllWindows } from './lib/window-helpers';
8-
import { ifdescribe, defer, waitUntil, listen } from './lib/spec-helpers';
8+
import { ifdescribe, defer, waitUntil, listen, ifit } from './lib/spec-helpers';
99
import { once } from 'events';
1010
import { setTimeout } from 'timers/promises';
1111

@@ -372,10 +372,9 @@ describe('webContents module', () => {
372372
.and.have.property('code', 'ERR_FILE_NOT_FOUND');
373373
});
374374

375-
// Temporarily disable on WOA until
375+
// FIXME: Temporarily disable on WOA until
376376
// https://github.com/electron/electron/issues/20008 is resolved
377-
const testFn = (process.platform === 'win32' && process.arch === 'arm64' ? it.skip : it);
378-
testFn('rejects when loading fails due to DNS not resolved', async () => {
377+
ifit(!(process.platform === 'win32' && process.arch === 'arm64'))('rejects when loading fails due to DNS not resolved', async () => {
379378
await expect(w.loadURL('https://err.name.not.resolved')).to.eventually.be.rejected()
380379
.and.have.property('code', 'ERR_NAME_NOT_RESOLVED');
381380
});
@@ -489,8 +488,8 @@ describe('webContents module', () => {
489488
describe('getFocusedWebContents() API', () => {
490489
afterEach(closeAllWindows);
491490

492-
const testFn = (process.platform === 'win32' && process.arch === 'arm64' ? it.skip : it);
493-
testFn('returns the focused web contents', async () => {
491+
// FIXME
492+
ifit(!(process.platform === 'win32' && process.arch === 'arm64'))('returns the focused web contents', async () => {
494493
const w = new BrowserWindow({ show: true });
495494
await w.loadFile(path.join(__dirname, 'fixtures', 'blank.html'));
496495
expect(webContents.getFocusedWebContents().id).to.equal(w.webContents.id);

spec/api-web-frame-main-spec.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,8 @@ describe('webFrameMain module', () => {
185185
});
186186

187187
describe('WebFrame.visibilityState', () => {
188-
// TODO(MarshallOfSound): Fix flaky test
189-
// @flaky-test
190-
it.skip('should match window state', async () => {
188+
// DISABLED-FIXME(MarshallOfSound): Fix flaky test
189+
it('should match window state', async () => {
191190
const w = new BrowserWindow({ show: true });
192191
await w.loadURL('about:blank');
193192
const webFrame = w.webContents.mainFrame;

spec/asar-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1410,8 +1410,8 @@ describe('asar package', function () {
14101410
expect(process.noAsar).to.be.false();
14111411
});
14121412
});
1413-
/*
14141413

1414+
/*
14151415
describe('process.env.ELECTRON_NO_ASAR', function () {
14161416
before(function () {
14171417
if (!features.isRunAsNodeEnabled()) {

0 commit comments

Comments
 (0)