mirror of
https://github.com/electron/electron.git
synced 2026-10-28 11:44:46 +08:00
* test: make DNS-failure specs independent of the network's DNS and proxy Four specs check how a failed host name lookup is reported: net.fetch in the main process and in a utility process, a main-frame loadURL, and a subframe failure that must not reject the main frame's loadURL. They used made-up public names (i.do.not.exist, err.name.not.resolved) and relied on the machine's network to answer NXDOMAIN for them. In a downstream Windows CI, an HTTP proxy was briefly enabled on October 6, and every test job that ran with it failed these specs: the https requests failed with ERR_CONNECTION_CLOSED or ERR_CONNECTION_ABORTED instead of a lookup error, and the http subframe never reported a failed load, so that test timed out. A local proxy that accepts the tunnel and then closes it, and serves an error page for plain http, reproduces all four failures on Linux. Map notfound.localhost to ^NOTFOUND in the spec runner's host-resolver-rules and use it in these specs. Chromium fails that lookup with ERR_NAME_NOT_RESOLVED without sending a DNS query, and proxies bypass *.localhost by default, so the specs check the same error and subframe behavior on any network. This also re-enables the main-frame spec on Windows on Arm. It was skipped for #20008, where that platform's DNS returned ERR_NAME_RESOLUTION_FAILED; the mapped host never reaches DNS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Update spec/index.js Co-authored-by: David Babenko-Sanders <dsanders11@ucsbalum.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: David Babenko-Sanders <dsanders11@ucsbalum.com>
121 lines
5.2 KiB
JavaScript
121 lines
5.2 KiB
JavaScript
import { app, protocol } from 'electron';
|
|
|
|
import * as v8 from 'node:v8';
|
|
|
|
// This app is started by the vitest Electron pool (spec/vitest/electron-pool.ts),
|
|
// several instances at a time, each running one spec file after another in
|
|
// the main process. Everything up to app 'ready' configures the process the
|
|
// specs expect; spec/vitest/worker.ts then takes over.
|
|
const isVitestWorker = process.argv.includes('--vitest-worker');
|
|
if (isVitestWorker) {
|
|
// Workers run concurrently; give each its own profile directory so they do
|
|
// not fight over cookie/localStorage/cache databases. Keep the app name in
|
|
// the path, some specs check for it.
|
|
app.setPath('userData', `${app.getPath('userData')}-worker-${process.env.ELECTRON_SPEC_WORKER_ID || process.pid}`);
|
|
}
|
|
|
|
// Uncaught exceptions before the worker runtime is up are fatal; afterwards
|
|
// vitest reports them against the running test (and its listener keeps
|
|
// Electron's error dialog away).
|
|
let workerStarted = false;
|
|
process.on('uncaughtException', (err) => {
|
|
if (workerStarted) return;
|
|
console.error('Unhandled exception in the spec worker:', err);
|
|
process.exit(1);
|
|
});
|
|
|
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
|
|
|
|
// Some Linux machines have broken hardware acceleration support.
|
|
if (process.env.ELECTRON_TEST_DISABLE_HARDWARE_ACCELERATION) {
|
|
app.disableHardwareAcceleration();
|
|
}
|
|
|
|
// macos-x64 CI runner VMs have no Metal-capable GPU, and SwiftShader's Vulkan
|
|
// backend fails to initialize there too, so every GPU process launch fails
|
|
// until Chromium falls back to software compositing with GL disabled. Start in
|
|
// that end state directly to skip the failed launches. Mirrors `ciGpuArgs`
|
|
// (--disable-gpu) in spec/lib/spec-helpers.ts, which is only loaded once the
|
|
// app is ready (see below).
|
|
if (process.env.CI && process.platform === 'darwin' && process.arch === 'x64') {
|
|
app.disableHardwareAcceleration();
|
|
}
|
|
|
|
v8.setFlagsFromString('--expose_gc');
|
|
app.commandLine.appendSwitch('js-flags', '--expose_gc');
|
|
// Prevent the spec runner quitting when the first window closes
|
|
app.on('window-all-closed', () => null);
|
|
|
|
// Use fake device for Media Stream to replace actual camera and microphone.
|
|
app.commandLine.appendSwitch('use-fake-device-for-media-stream');
|
|
app.commandLine.appendSwitch(
|
|
'host-resolver-rules',
|
|
[
|
|
'MAP localhost2 127.0.0.1',
|
|
'MAP ipv4.localhost2 10.0.0.1',
|
|
'MAP ipv6.localhost2 [::1]',
|
|
'MAP notfound.localhost2 ^NOTFOUND',
|
|
// For specs that load a URL which must fail name resolution.
|
|
// Chromium fails this lookup with ERR_NAME_NOT_RESOLVED without a DNS query,
|
|
// and proxies bypass *.localhost by default (unlike localhost2),
|
|
// so the result does not depend on the network's DNS server or proxy.
|
|
'MAP notfound.localhost ^NOTFOUND'
|
|
].join(', ')
|
|
);
|
|
|
|
// Enable features required by tests.
|
|
app.commandLine.appendSwitch(
|
|
'enable-features',
|
|
[
|
|
// spec/api-web-frame-main.spec.ts
|
|
'DocumentPolicyIncludeJSCallStacksInCrashReports',
|
|
// spec/spellchecker.spec.ts - allows spellcheck without user gesture
|
|
// https://chromium-review.googlesource.com/c/chromium/src/+/7452579
|
|
'UnrestrictSpellingAndGrammarForTesting'
|
|
].join(',')
|
|
);
|
|
|
|
global.standardScheme = 'app';
|
|
global.zoomScheme = 'zoom';
|
|
global.serviceWorkerScheme = 'sw';
|
|
protocol.registerSchemesAsPrivileged([
|
|
{ scheme: global.standardScheme, privileges: { standard: true, secure: true, stream: false } },
|
|
{ scheme: global.zoomScheme, privileges: { standard: true, secure: true } },
|
|
{ scheme: global.serviceWorkerScheme, privileges: { allowServiceWorkers: true, standard: true, secure: true } },
|
|
{ scheme: 'http-like', privileges: { standard: true, secure: true, corsEnabled: true, supportFetchAPI: true } },
|
|
{ scheme: 'cors-blob', privileges: { corsEnabled: true, supportFetchAPI: true } },
|
|
{ scheme: 'cors', privileges: { corsEnabled: true, supportFetchAPI: true } },
|
|
{ scheme: 'no-cors', privileges: { supportFetchAPI: true } },
|
|
{ scheme: 'no-cors-file', privileges: { supportFetchAPI: true } },
|
|
{ scheme: 'no-cors-http', privileges: { supportFetchAPI: true } },
|
|
{ scheme: 'no-cors-standard', privileges: { standard: true, supportFetchAPI: true } },
|
|
{ scheme: 'no-fetch', privileges: { corsEnabled: true } },
|
|
{ scheme: 'stream', privileges: { standard: true, stream: true } },
|
|
{ scheme: 'foo', privileges: { standard: true } },
|
|
{ scheme: 'bar', privileges: { standard: true } }
|
|
]);
|
|
|
|
app
|
|
.whenReady()
|
|
.then(async () => {
|
|
if (!isVitestWorker) {
|
|
console.error(
|
|
'This is the Electron spec app; it is started by the test runner. Run `npm test` ' +
|
|
'(node script/spec-runner.js) from the repository root instead, optionally with ' +
|
|
'--files spec/some.spec.ts or -g <pattern>.'
|
|
);
|
|
return process.exit(1);
|
|
}
|
|
const { isTestingBindingAvailable } = await import('./lib/spec-helpers.ts');
|
|
if (process.env.ELECTRON_REQUIRE_TESTING_BINDINGS === '1' && !isTestingBindingAvailable()) {
|
|
throw new Error('Testing build expected, but testing bindings are unavailable');
|
|
}
|
|
workerStarted = true;
|
|
await import('./vitest/worker.ts');
|
|
})
|
|
.catch((err) => {
|
|
console.error('An error occurred while starting the spec worker');
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|