2024-10-03 02:10:44 +00:00
|
|
|
const { app, protocol } = require('electron');
|
|
|
|
|
2023-06-15 14:42:27 +00:00
|
|
|
const fs = require('node:fs');
|
|
|
|
const path = require('node:path');
|
|
|
|
const v8 = require('node:v8');
|
2019-03-10 22:38:44 +00:00
|
|
|
|
|
|
|
// We want to terminate on errors, not throw up a dialog
|
|
|
|
process.on('uncaughtException', (err) => {
|
|
|
|
console.error('Unhandled exception in main spec runner:', err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Tell ts-node which tsconfig to use
|
|
|
|
process.env.TS_NODE_PROJECT = path.resolve(__dirname, '../tsconfig.spec.json');
|
2019-07-16 20:43:00 +00:00
|
|
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
|
2019-03-10 22:38:44 +00:00
|
|
|
|
2023-07-19 14:54:08 +00:00
|
|
|
// Some Linux machines have broken hardware acceleration support.
|
|
|
|
if (process.env.ELECTRON_TEST_DISABLE_HARDWARE_ACCELERATION) {
|
|
|
|
app.disableHardwareAcceleration();
|
|
|
|
}
|
|
|
|
|
2019-03-10 22:38:44 +00:00
|
|
|
v8.setFlagsFromString('--expose_gc');
|
|
|
|
app.commandLine.appendSwitch('js-flags', '--expose_gc');
|
2022-02-21 09:27:45 +00:00
|
|
|
// Prevent the spec runner quitting when the first window closes
|
2019-03-10 22:38:44 +00:00
|
|
|
app.on('window-all-closed', () => null);
|
|
|
|
|
2019-10-11 20:55:50 +00:00
|
|
|
// Use fake device for Media Stream to replace actual camera and microphone.
|
|
|
|
app.commandLine.appendSwitch('use-fake-device-for-media-stream');
|
2021-09-21 06:47:54 +00:00
|
|
|
app.commandLine.appendSwitch('host-rules', 'MAP localhost2 127.0.0.1');
|
2023-04-05 14:06:14 +00:00
|
|
|
app.commandLine.appendSwitch('host-resolver-rules', [
|
|
|
|
'MAP ipv4.localhost2 10.0.0.1',
|
|
|
|
'MAP ipv6.localhost2 [::1]',
|
|
|
|
'MAP notfound.localhost2 ~NOTFOUND'
|
|
|
|
].join(', '));
|
2019-10-11 20:55:50 +00:00
|
|
|
|
2019-05-28 21:12:59 +00:00
|
|
|
global.standardScheme = 'app';
|
2019-08-30 00:45:41 +00:00
|
|
|
global.zoomScheme = 'zoom';
|
2021-03-23 15:16:53 +00:00
|
|
|
global.serviceWorkerScheme = 'sw';
|
2019-05-28 21:12:59 +00:00
|
|
|
protocol.registerSchemesAsPrivileged([
|
2020-06-08 16:49:36 +00:00
|
|
|
{ scheme: global.standardScheme, privileges: { standard: true, secure: true, stream: false } },
|
2019-08-30 00:45:41 +00:00
|
|
|
{ scheme: global.zoomScheme, privileges: { standard: true, secure: true } },
|
2021-03-23 15:16:53 +00:00
|
|
|
{ scheme: global.serviceWorkerScheme, privileges: { allowServiceWorkers: true, standard: true, secure: true } },
|
2024-04-22 20:40:01 +00:00
|
|
|
{ scheme: 'http-like', privileges: { standard: true, secure: true, corsEnabled: true, supportFetchAPI: true } },
|
2019-05-28 21:12:59 +00:00
|
|
|
{ scheme: 'cors-blob', privileges: { corsEnabled: true, supportFetchAPI: true } },
|
2019-06-27 21:20:29 +00:00
|
|
|
{ scheme: 'cors', privileges: { corsEnabled: true, supportFetchAPI: true } },
|
|
|
|
{ scheme: 'no-cors', privileges: { supportFetchAPI: true } },
|
2020-01-29 12:01:37 +00:00
|
|
|
{ scheme: 'no-fetch', privileges: { corsEnabled: true } },
|
2020-06-08 16:49:36 +00:00
|
|
|
{ scheme: 'stream', privileges: { standard: true, stream: true } },
|
2020-01-29 12:01:37 +00:00
|
|
|
{ scheme: 'foo', privileges: { standard: true } },
|
|
|
|
{ scheme: 'bar', privileges: { standard: true } }
|
2019-05-28 21:12:59 +00:00
|
|
|
]);
|
|
|
|
|
2020-05-27 22:21:02 +00:00
|
|
|
app.whenReady().then(async () => {
|
2019-03-10 22:38:44 +00:00
|
|
|
require('ts-node/register');
|
|
|
|
|
|
|
|
const argv = require('yargs')
|
|
|
|
.boolean('ci')
|
2019-11-07 00:15:55 +00:00
|
|
|
.array('files')
|
2019-03-10 22:38:44 +00:00
|
|
|
.string('g').alias('g', 'grep')
|
|
|
|
.boolean('i').alias('i', 'invert')
|
|
|
|
.argv;
|
|
|
|
|
|
|
|
const Mocha = require('mocha');
|
2023-02-03 01:40:30 +00:00
|
|
|
const mochaOptions = {
|
|
|
|
forbidOnly: process.env.CI
|
|
|
|
};
|
2023-02-08 06:44:53 +00:00
|
|
|
if (process.env.CI) {
|
|
|
|
mochaOptions.retries = 3;
|
|
|
|
}
|
2019-03-10 22:38:44 +00:00
|
|
|
if (process.env.MOCHA_REPORTER) {
|
|
|
|
mochaOptions.reporter = process.env.MOCHA_REPORTER;
|
|
|
|
}
|
|
|
|
if (process.env.MOCHA_MULTI_REPORTERS) {
|
|
|
|
mochaOptions.reporterOptions = {
|
|
|
|
reporterEnabled: process.env.MOCHA_MULTI_REPORTERS
|
|
|
|
};
|
|
|
|
}
|
2023-07-19 14:54:08 +00:00
|
|
|
// The MOCHA_GREP and MOCHA_INVERT are used in some vendor builds for sharding
|
|
|
|
// tests.
|
|
|
|
if (process.env.MOCHA_GREP) {
|
|
|
|
mochaOptions.grep = process.env.MOCHA_GREP;
|
|
|
|
}
|
|
|
|
if (process.env.MOCHA_INVERT) {
|
|
|
|
mochaOptions.invert = process.env.MOCHA_INVERT === 'true';
|
|
|
|
}
|
2019-03-10 22:38:44 +00:00
|
|
|
const mocha = new Mocha(mochaOptions);
|
|
|
|
|
2023-02-28 22:27:54 +00:00
|
|
|
// Add a root hook on mocha to skip any tests that are disabled
|
|
|
|
const disabledTests = new Set(
|
|
|
|
JSON.parse(
|
|
|
|
fs.readFileSync(path.join(__dirname, 'disabled-tests.json'), 'utf8')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
mocha.suite.beforeEach(function () {
|
2023-04-04 13:48:51 +00:00
|
|
|
// TODO(clavin): add support for disabling *suites* by title, not just tests
|
2023-02-28 22:27:54 +00:00
|
|
|
if (disabledTests.has(this.currentTest?.fullTitle())) {
|
|
|
|
this.skip();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-11 18:35:50 +00:00
|
|
|
// The cleanup method is registered this way rather than through an
|
|
|
|
// `afterEach` at the top level so that it can run before other `afterEach`
|
|
|
|
// methods.
|
|
|
|
//
|
|
|
|
// The order of events is:
|
|
|
|
// 1. test completes,
|
|
|
|
// 2. `defer()`-ed methods run, in reverse order,
|
|
|
|
// 3. regular `afterEach` hooks run.
|
2023-01-25 21:01:25 +00:00
|
|
|
const { runCleanupFunctions } = require('./lib/spec-helpers');
|
2020-06-11 18:35:50 +00:00
|
|
|
mocha.suite.on('suite', function attach (suite) {
|
|
|
|
suite.afterEach('cleanup', runCleanupFunctions);
|
|
|
|
suite.on('suite', attach);
|
|
|
|
});
|
|
|
|
|
2019-03-10 22:38:44 +00:00
|
|
|
if (!process.env.MOCHA_REPORTER) {
|
|
|
|
mocha.ui('bdd').reporter('tap');
|
|
|
|
}
|
2020-05-18 16:33:54 +00:00
|
|
|
const mochaTimeout = process.env.MOCHA_TIMEOUT || 30000;
|
|
|
|
mocha.timeout(mochaTimeout);
|
2019-03-10 22:38:44 +00:00
|
|
|
|
|
|
|
if (argv.grep) mocha.grep(argv.grep);
|
|
|
|
if (argv.invert) mocha.invert();
|
|
|
|
|
2023-05-08 08:14:59 +00:00
|
|
|
const baseElectronDir = path.resolve(__dirname, '..');
|
|
|
|
const validTestPaths = argv.files && argv.files.map(file =>
|
|
|
|
path.isAbsolute(file)
|
|
|
|
? path.relative(baseElectronDir, file)
|
|
|
|
: file);
|
2020-05-27 22:21:02 +00:00
|
|
|
const filter = (file) => {
|
|
|
|
if (!/-spec\.[tj]s$/.test(file)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-03-10 22:38:44 +00:00
|
|
|
|
2020-05-27 22:21:02 +00:00
|
|
|
// This allows you to run specific modules only:
|
|
|
|
// npm run test -match=menu
|
|
|
|
const moduleMatch = process.env.npm_config_match
|
|
|
|
? new RegExp(process.env.npm_config_match, 'g')
|
|
|
|
: null;
|
|
|
|
if (moduleMatch && !moduleMatch.test(file)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-08 08:14:59 +00:00
|
|
|
if (validTestPaths && !validTestPaths.includes(path.relative(baseElectronDir, file))) {
|
2020-05-27 22:21:02 +00:00
|
|
|
return false;
|
2019-03-10 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 22:21:02 +00:00
|
|
|
return true;
|
|
|
|
};
|
2019-11-07 00:15:55 +00:00
|
|
|
|
2022-08-16 19:23:13 +00:00
|
|
|
const { getFiles } = require('./get-files');
|
2024-06-21 14:31:10 +00:00
|
|
|
const testFiles = await getFiles(__dirname, filter);
|
2023-08-31 14:36:43 +00:00
|
|
|
for (const file of testFiles.sort()) {
|
2020-05-27 22:21:02 +00:00
|
|
|
mocha.addFile(file);
|
2023-08-31 14:36:43 +00:00
|
|
|
}
|
2020-05-27 22:21:02 +00:00
|
|
|
|
2023-05-08 08:14:59 +00:00
|
|
|
if (validTestPaths && validTestPaths.length > 0 && testFiles.length === 0) {
|
|
|
|
console.error('Test files were provided, but they did not match any searched files');
|
|
|
|
console.error('provided file paths (relative to electron/):', validTestPaths);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2020-05-27 22:21:02 +00:00
|
|
|
const cb = () => {
|
|
|
|
// Ensure the callback is called after runner is defined
|
|
|
|
process.nextTick(() => {
|
|
|
|
process.exit(runner.failures);
|
2019-11-07 00:15:55 +00:00
|
|
|
});
|
2020-05-27 22:21:02 +00:00
|
|
|
};
|
2019-11-07 00:15:55 +00:00
|
|
|
|
2020-05-27 22:21:02 +00:00
|
|
|
// Set up chai in the correct order
|
|
|
|
const chai = require('chai');
|
|
|
|
chai.use(require('chai-as-promised'));
|
|
|
|
chai.use(require('dirty-chai'));
|
2019-11-07 00:15:55 +00:00
|
|
|
|
2021-03-09 07:05:02 +00:00
|
|
|
// Show full object diff
|
|
|
|
// https://github.com/chaijs/chai/issues/469
|
|
|
|
chai.config.truncateThreshold = 0;
|
|
|
|
|
2020-05-27 22:21:02 +00:00
|
|
|
const runner = mocha.run(cb);
|
2020-07-29 03:36:35 +00:00
|
|
|
}).catch((err) => {
|
2022-08-16 19:23:13 +00:00
|
|
|
console.error('An error occurred while running the spec runner');
|
2020-07-29 03:36:35 +00:00
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
2019-03-10 22:38:44 +00:00
|
|
|
});
|