electron/script/spec-runner.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

265 lines
8 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
const childProcess = require('child_process');
const crypto = require('crypto');
const fs = require('fs-extra');
const { hashElement } = require('folder-hash');
const path = require('path');
const unknownFlags = [];
require('colors');
const pass = '✓'.green;
const fail = '✗'.red;
2019-03-13 22:09:28 +00:00
const args = require('minimist')(process.argv, {
string: ['runners', 'target'],
boolean: ['buildNativeTests'],
unknown: arg => unknownFlags.push(arg)
2019-03-13 22:09:28 +00:00
});
const unknownArgs = [];
for (const flag of unknownFlags) {
unknownArgs.push(flag);
const onlyFlag = flag.replace(/^-+/, '');
if (args[onlyFlag]) {
unknownArgs.push(args[onlyFlag]);
}
}
const utils = require('./lib/utils');
const { YARN_VERSION } = require('./yarn');
const BASE = path.resolve(__dirname, '../..');
const NPX_CMD = process.platform === 'win32' ? 'npx.cmd' : 'npx';
const runners = new Map([
['main', { description: 'Main process specs', run: runMainProcessElectronTests }],
['native', { description: 'Native specs', run: runNativeElectronTests }]
]);
const specHashPath = path.resolve(__dirname, '../spec/.hash');
2019-03-15 00:22:42 +00:00
let runnersToRun = null;
if (args.runners !== undefined) {
runnersToRun = args.runners.split(',').filter(value => value);
if (!runnersToRun.every(r => [...runners.keys()].includes(r))) {
console.log(`${fail} ${runnersToRun} must be a subset of [${[...runners.keys()].join(' | ')}]`);
process.exit(1);
}
2019-03-15 00:22:42 +00:00
console.log('Only running:', runnersToRun);
} else {
console.log(`Triggering runners: ${[...runners.keys()].join(', ')}`);
}
async function main () {
const [lastSpecHash, lastSpecInstallHash] = loadLastSpecHash();
const [currentSpecHash, currentSpecInstallHash] = await getSpecHash();
const somethingChanged = (currentSpecHash !== lastSpecHash) ||
(lastSpecInstallHash !== currentSpecInstallHash);
if (somethingChanged) {
await installSpecModules(path.resolve(__dirname, '..', 'spec'));
await getSpecHash().then(saveSpecHash);
}
if (!fs.existsSync(path.resolve(__dirname, '../electron.d.ts'))) {
console.log('Generating electron.d.ts as it is missing');
generateTypeDefinitions();
}
await runElectronTests();
}
function generateTypeDefinitions () {
const { status } = childProcess.spawnSync('npm', ['run', 'create-typescript-definitions'], {
cwd: path.resolve(__dirname, '..'),
stdio: 'inherit',
shell: true
});
if (status !== 0) {
throw new Error(`Electron typescript definition generation failed with exit code: ${status}.`);
}
}
function loadLastSpecHash () {
return fs.existsSync(specHashPath)
? fs.readFileSync(specHashPath, 'utf8').split('\n')
: [null, null];
}
function saveSpecHash ([newSpecHash, newSpecInstallHash]) {
fs.writeFileSync(specHashPath, `${newSpecHash}\n${newSpecInstallHash}`);
}
async function runElectronTests () {
const errors = [];
const testResultsDir = process.env.ELECTRON_TEST_RESULTS_DIR;
for (const [runnerId, { description, run }] of runners) {
if (runnersToRun && !runnersToRun.includes(runnerId)) {
console.info('\nSkipping:', description);
continue;
}
try {
console.info('\nRunning:', description);
if (testResultsDir) {
process.env.MOCHA_FILE = path.join(testResultsDir, `test-results-${runnerId}.xml`);
}
await run();
} catch (err) {
errors.push([runnerId, err]);
}
}
if (errors.length !== 0) {
for (const err of errors) {
console.error('\n\nRunner Failed:', err[0]);
console.error(err[1]);
}
console.log(`${fail} Electron test runners have failed`);
process.exit(1);
}
}
async function runTestUsingElectron (specDir, testName) {
let exe = path.resolve(BASE, utils.getElectronExec());
const runnerArgs = [`electron/${specDir}`, ...unknownArgs.slice(2)];
if (process.platform === 'linux') {
2019-03-13 22:09:28 +00:00
runnerArgs.unshift(path.resolve(__dirname, 'dbus_mock.py'), exe);
exe = 'python3';
}
const { status, signal } = childProcess.spawnSync(exe, runnerArgs, {
cwd: path.resolve(__dirname, '../..'),
stdio: 'inherit'
});
if (status !== 0) {
if (status) {
const textStatus = process.platform === 'win32' ? `0x${status.toString(16)}` : status.toString();
console.log(`${fail} Electron tests failed with code ${textStatus}.`);
} else {
console.log(`${fail} Electron tests failed with kill signal ${signal}.`);
}
process.exit(1);
}
console.log(`${pass} Electron ${testName} process tests passed.`);
}
const specFilter = (file) => {
if (!/-spec\.[tj]s$/.test(file)) {
return false;
} else {
return true;
}
};
async function runNativeElectronTests () {
let testTargets = require('./native-test-targets.json');
const outDir = `out/${utils.getOutDir()}`;
// If native tests are being run, only one arg would be relevant
if (args.target && !testTargets.includes(args.target)) {
console.log(`${fail} ${args.target} must be a subset of [${[testTargets].join(', ')}]`);
process.exit(1);
}
// Optionally build all native test targets
if (args.buildNativeTests) {
for (const target of testTargets) {
const build = childProcess.spawnSync('ninja', ['-C', outDir, target], {
cwd: path.resolve(__dirname, '../..'),
stdio: 'inherit'
});
// Exit if test target failed to build
if (build.status !== 0) {
console.log(`${fail} ${target} failed to build.`);
process.exit(1);
}
}
}
// If a specific target was passed, only build and run that target
if (args.target) testTargets = [args.target];
// Run test targets
const failures = [];
for (const target of testTargets) {
console.info('\nRunning native test for target:', target);
const testRun = childProcess.spawnSync(`./${outDir}/${target}`, {
cwd: path.resolve(__dirname, '../..'),
stdio: 'inherit'
});
// Collect failures and log at end
if (testRun.status !== 0) failures.push({ target });
}
// Exit if any failures
if (failures.length > 0) {
console.log(`${fail} Electron native tests failed for the following targets: `, failures);
process.exit(1);
}
console.log(`${pass} Electron native tests passed.`);
}
async function runMainProcessElectronTests () {
await runTestUsingElectron('spec', 'main');
}
async function installSpecModules (dir) {
chore: bump chromium to 103.0.5046.0 (main) (#33906) * chore: bump chromium in DEPS to 103.0.5020.0 * chore: bump chromium in DEPS to 103.0.5022.0 * chore: bump chromium in DEPS to 103.0.5024.0 * chore: update patches * 3587410: [Printing] Remove JobEventDetails Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3587410 * chore: bump chromium in DEPS to 103.0.5026.0 * chore: update patches * 3577218: WebUI: Delete webui_resources.grd and related GN targets. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3577218 * chore: bump chromium in DEPS to 103.0.5028.0 * chore: update patches * 3579297: Convert UpdatePrintSettings() to use non-deprecated base::Value APIs. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3579297 * 3560622: serial: Add SerialPort.forget() method Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3560622 * 3581708: Restore original display when moving from tab-fullscreen to browser-fullscreen. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3581708 * chore: fix authorization flags lint error * 3583363: Remove net wrappers around base/strings/escape.h Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3583363 * fixup! 3560622: serial: Add SerialPort.forget() method Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3560622 * 3587589: Reland "Propagate the MIME type from DownloadTargetDeterminer to DownloadItem" Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3587589 * 3584006: Remove IsRenderViewLive from content public Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3584006 * 3596174: [api] Remove APIs for resurrecting finalizers Ref: https://chromium-review.googlesource.com/c/v8/v8/+/3596174 * 3368244: Hook SnapshotForContentAnalysis renderer API to scan system prints Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3368244 * chore: bump chromium in DEPS to 103.0.5030.0 * chore: update patches * chore: bump chromium in DEPS to 103.0.5032.0 * chore: bump chromium in DEPS to 103.0.5034.0 * chore: bump chromium in DEPS to 103.0.5036.0 * chore: update patches * 3586363: Introduce PrintRenderFrame.PrintWithParams() for batch printing to PDF Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3586363 * 3593199: Remove content::PermissionType references and replace them with blink::PermissionType Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3593199 * 3368244: Hook SnapshotForContentAnalysis renderer API to scan system prints Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3368244 * chore: lint * chore: bump chromium in DEPS to 103.0.5038.0 * chore: update patches * fixup! 3560622: serial: Add SerialPort.forget() method * 3606495: mac screen capture: add metric Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3606495 * chore: bump chromium in DEPS to 103.0.5040.0 * chore: update patches * 3590840: Add IPs to DnsOverHttpsServerConfig https://chromium-review.googlesource.com/c/chromium/src/+/3590840 * stub functions for ElectronSerialDelegate and SerialChooserController to fix link * 3566412: [base] Remove base/android dependency on post_task.h and officially remove post_task.h! Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3566412 * 3347944: [content] No longer hand-off whole MainFunctionParams to BrowserMainParts Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3347944 * fixup! 3566412: [base] Remove base/android dependency on post_task.h and off… e3ea3e1 …icially remove post_task.h! * chore: update process_singleton patches for content::GetIOThreadTaskRunner({}) Ref: 2015655: [BrowserThread] Migrate co/pub/br and co/br/scheduler to the new API | https://chromium-review.googlesource.com/c/chromium/src/+/2015655 * chore: migrate base::DeleteSoon to content::GetUIThreadTaskRunner({})->DeleteSoon Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3566412 * chore: remove duplicate functions for RevokePortPermissionWebInitiated & GetPortInfo * chore: migrate Linux/Windows methods off of post_task.h Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3566412 * 64908: Stop building legacy SwiftShader GL in Chromium https://swiftshader-review.googlesource.com/c/SwiftShader/+/64908 * 3573245: Added Themed versions of RoundedRectBackground and RoundedRectBorder. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3573245 * chore: bump chromium in DEPS to 103.0.5042.0 * chore: update patches * 3571804: [api] Advance API deprecation for V8 version v10.2 https://chromium-review.googlesource.com/c/v8/v8/+/3571804 * fixup! 3571804: [api] Advance API deprecation for V8 version v10.2 * build: fix run-clang-format extension matching * lint * fix windows build * how is clang-format still not working for me * chore: update patches * 3623985: Replace ad-hoc SetPublicFirstPartySets calls with method in ContentBrowserClient. https://chromium-review.googlesource.com/c/chromium/src/+/3623985 * no need to implement WillProvidePublicFirstPartySets; the default is false * 3601036: [QT] Introduce ui/views/linux_ui/linux_ui_factory.* https://chromium-review.googlesource.com/c/chromium/src/+/3601036 * 3583363: Remove net wrappers around base/strings/escape.h https://chromium-review.googlesource.com/c/chromium/src/+/3583363 * lint * chore: bump chromium in DEPS to 103.0.5044.0 * fix conflicts * chore: update patches * upgrade nan * pin version of nan in tests * replace my hacky deprecated override fix with the fix from upstream * revert runtime dcheck in v8 * pin nan version at root too * refactor: tell gyp to use c++17 when building with our node * Revert "refactor: tell gyp to use c++17 when building with our node" This reverts commit 41a03a5799a8f40f31555d73d20ea865acfcd192. * Undo the reversion of 41a03a5799a8f40f31555d73d20ea865acfcd192. This reverts commit 54440abc598153bd7e259be4a908f0ecc0b33348. * disable sequential/test-cpu-prof-kill for now * also sequential/test-diagnostic-dir-cpu-prof Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: Jeremy Rose <japthorp@slack-corp.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: Charles Kerr <charles@charleskerr.com>
2022-05-17 16:48:40 +00:00
// v8 headers use c++17 so override the gyp default of -std=c++14,
// but don't clobber any other CXXFLAGS that were passed into spec-runner.js
const CXXFLAGS = ['-std=c++17', process.env.CXXFLAGS].filter(x => !!x).join(' ');
const nodeDir = path.resolve(BASE, `out/${utils.getOutDir({ shouldLog: true })}/gen/node_headers`);
const env = {
...process.env,
chore: bump chromium to 103.0.5046.0 (main) (#33906) * chore: bump chromium in DEPS to 103.0.5020.0 * chore: bump chromium in DEPS to 103.0.5022.0 * chore: bump chromium in DEPS to 103.0.5024.0 * chore: update patches * 3587410: [Printing] Remove JobEventDetails Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3587410 * chore: bump chromium in DEPS to 103.0.5026.0 * chore: update patches * 3577218: WebUI: Delete webui_resources.grd and related GN targets. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3577218 * chore: bump chromium in DEPS to 103.0.5028.0 * chore: update patches * 3579297: Convert UpdatePrintSettings() to use non-deprecated base::Value APIs. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3579297 * 3560622: serial: Add SerialPort.forget() method Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3560622 * 3581708: Restore original display when moving from tab-fullscreen to browser-fullscreen. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3581708 * chore: fix authorization flags lint error * 3583363: Remove net wrappers around base/strings/escape.h Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3583363 * fixup! 3560622: serial: Add SerialPort.forget() method Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3560622 * 3587589: Reland "Propagate the MIME type from DownloadTargetDeterminer to DownloadItem" Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3587589 * 3584006: Remove IsRenderViewLive from content public Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3584006 * 3596174: [api] Remove APIs for resurrecting finalizers Ref: https://chromium-review.googlesource.com/c/v8/v8/+/3596174 * 3368244: Hook SnapshotForContentAnalysis renderer API to scan system prints Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3368244 * chore: bump chromium in DEPS to 103.0.5030.0 * chore: update patches * chore: bump chromium in DEPS to 103.0.5032.0 * chore: bump chromium in DEPS to 103.0.5034.0 * chore: bump chromium in DEPS to 103.0.5036.0 * chore: update patches * 3586363: Introduce PrintRenderFrame.PrintWithParams() for batch printing to PDF Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3586363 * 3593199: Remove content::PermissionType references and replace them with blink::PermissionType Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3593199 * 3368244: Hook SnapshotForContentAnalysis renderer API to scan system prints Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3368244 * chore: lint * chore: bump chromium in DEPS to 103.0.5038.0 * chore: update patches * fixup! 3560622: serial: Add SerialPort.forget() method * 3606495: mac screen capture: add metric Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3606495 * chore: bump chromium in DEPS to 103.0.5040.0 * chore: update patches * 3590840: Add IPs to DnsOverHttpsServerConfig https://chromium-review.googlesource.com/c/chromium/src/+/3590840 * stub functions for ElectronSerialDelegate and SerialChooserController to fix link * 3566412: [base] Remove base/android dependency on post_task.h and officially remove post_task.h! Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3566412 * 3347944: [content] No longer hand-off whole MainFunctionParams to BrowserMainParts Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3347944 * fixup! 3566412: [base] Remove base/android dependency on post_task.h and off… e3ea3e1 …icially remove post_task.h! * chore: update process_singleton patches for content::GetIOThreadTaskRunner({}) Ref: 2015655: [BrowserThread] Migrate co/pub/br and co/br/scheduler to the new API | https://chromium-review.googlesource.com/c/chromium/src/+/2015655 * chore: migrate base::DeleteSoon to content::GetUIThreadTaskRunner({})->DeleteSoon Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3566412 * chore: remove duplicate functions for RevokePortPermissionWebInitiated & GetPortInfo * chore: migrate Linux/Windows methods off of post_task.h Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3566412 * 64908: Stop building legacy SwiftShader GL in Chromium https://swiftshader-review.googlesource.com/c/SwiftShader/+/64908 * 3573245: Added Themed versions of RoundedRectBackground and RoundedRectBorder. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3573245 * chore: bump chromium in DEPS to 103.0.5042.0 * chore: update patches * 3571804: [api] Advance API deprecation for V8 version v10.2 https://chromium-review.googlesource.com/c/v8/v8/+/3571804 * fixup! 3571804: [api] Advance API deprecation for V8 version v10.2 * build: fix run-clang-format extension matching * lint * fix windows build * how is clang-format still not working for me * chore: update patches * 3623985: Replace ad-hoc SetPublicFirstPartySets calls with method in ContentBrowserClient. https://chromium-review.googlesource.com/c/chromium/src/+/3623985 * no need to implement WillProvidePublicFirstPartySets; the default is false * 3601036: [QT] Introduce ui/views/linux_ui/linux_ui_factory.* https://chromium-review.googlesource.com/c/chromium/src/+/3601036 * 3583363: Remove net wrappers around base/strings/escape.h https://chromium-review.googlesource.com/c/chromium/src/+/3583363 * lint * chore: bump chromium in DEPS to 103.0.5044.0 * fix conflicts * chore: update patches * upgrade nan * pin version of nan in tests * replace my hacky deprecated override fix with the fix from upstream * revert runtime dcheck in v8 * pin nan version at root too * refactor: tell gyp to use c++17 when building with our node * Revert "refactor: tell gyp to use c++17 when building with our node" This reverts commit 41a03a5799a8f40f31555d73d20ea865acfcd192. * Undo the reversion of 41a03a5799a8f40f31555d73d20ea865acfcd192. This reverts commit 54440abc598153bd7e259be4a908f0ecc0b33348. * disable sequential/test-cpu-prof-kill for now * also sequential/test-diagnostic-dir-cpu-prof Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: Jeremy Rose <japthorp@slack-corp.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: Charles Kerr <charles@charleskerr.com>
2022-05-17 16:48:40 +00:00
CXXFLAGS,
npm_config_nodedir: nodeDir,
npm_config_msvs_version: '2019',
npm_config_yes: 'true'
};
if (fs.existsSync(path.resolve(dir, 'node_modules'))) {
await fs.remove(path.resolve(dir, 'node_modules'));
}
const { status } = childProcess.spawnSync(NPX_CMD, [`yarn@${YARN_VERSION}`, 'install', '--frozen-lockfile'], {
env,
cwd: dir,
stdio: 'inherit'
});
if (status !== 0 && !process.env.IGNORE_YARN_INSTALL_ERROR) {
console.log(`${fail} Failed to yarn install in '${dir}'`);
process.exit(1);
}
}
function getSpecHash () {
return Promise.all([
(async () => {
const hasher = crypto.createHash('SHA256');
hasher.update(fs.readFileSync(path.resolve(__dirname, '../spec/package.json')));
hasher.update(fs.readFileSync(path.resolve(__dirname, '../spec/yarn.lock')));
hasher.update(fs.readFileSync(path.resolve(__dirname, '../script/spec-runner.js')));
return hasher.digest('hex');
})(),
(async () => {
const specNodeModulesPath = path.resolve(__dirname, '../spec/node_modules');
if (!fs.existsSync(specNodeModulesPath)) {
return null;
}
const { hash } = await hashElement(specNodeModulesPath, {
folders: {
exclude: ['.bin']
}
});
return hash;
})()
]);
}
main().catch((error) => {
console.error('An error occurred inside the spec runner:', error);
process.exit(1);
});