Skip to content

Commit 43931d6

Browse files
committed
chore(e2e): separate chrome flags and compass flags
1 parent 32f7aa4 commit 43931d6

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

packages/compass-e2e-tests/helpers/chrome-startup-flags.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copied from https://github.com/webdriverio/webdriverio/blob/1825c633aead82bc650dff1f403ac30cff7c7cb3/packages/devtools/src/constants.ts
22
// These are the default flags that webdriverio uses to start Chrome driver.
33
// NOTE: this has since been removed along with the devtools automation protocol https://github.com/webdriverio/webdriverio/commit/28e64e439ffc36a95f24aeda9f1d21111429dfa3#diff-6ea151d6c0687197931735239f397b7f5f0140a588c5b2b82ff584bbe73be069
4-
const DEFAULT_WEBDRIVER_FLAGS = [
4+
export const DEFAULT_WEBDRIVER_FLAGS = [
55
// suppresses Save Password prompt window
66
'--enable-automation',
77
// do not block popups
@@ -45,7 +45,7 @@ const DEFAULT_WEBDRIVER_FLAGS = [
4545
];
4646

4747
// These flags are used to start Chrome driver based on the CI requirements.
48-
const CI_FLAGS = [
48+
export const CI_FLAGS = [
4949
// Chromecast feature that is enabled by default in some chrome versions
5050
// and breaks the app on Ubuntu
5151
'--media-router=0',
@@ -55,21 +55,24 @@ const CI_FLAGS = [
5555
// Seeing gpu init related errors on at least RHEL, especially when starting
5656
// the CLI
5757
'--disable-gpu',
58+
'--num-raster-threads=0',
59+
// Seems like disabling gpu is not always enough to prevent chromium from
60+
// spawning it anyway, activating in process gpu seems to help with that
61+
//
62+
// See https://github.com/electron/electron/issues/28164 and
63+
// https://www.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome/
64+
'--in-process-gpu',
5865
];
5966

60-
// These flags are used to start Chrome driver based on the Compass requirements.
61-
const COMPASS_FLAGS = [
67+
// The shared set of flags that are used to start Chrome when running Compass
68+
// desktop and web tests in CLI or GUI mode.
69+
export const CHROME_STARTUP_FLAGS = [...DEFAULT_WEBDRIVER_FLAGS, ...CI_FLAGS];
70+
71+
// These flags are used to start Chrome based on the Compass requirements.
72+
export const COMPASS_FLAGS = [
6273
// Allow options such as --user-data-dir to pass through the command line
6374
// flag validation code.
6475
'--ignore-additional-command-line-flags',
6576
// Use the Atlas dev server for generative ai and atlas requests (cloud-dev).
6677
'--atlasServiceBackendPreset=atlas-dev',
6778
];
68-
69-
// The shared set of flags that are used to start Chrome driver when running Compass
70-
// tests in CLI or GUI mode.
71-
export const CHROME_STARTUP_FLAGS = [
72-
...DEFAULT_WEBDRIVER_FLAGS,
73-
...CI_FLAGS,
74-
...COMPASS_FLAGS,
75-
];

packages/compass-e2e-tests/helpers/compass-web-sandbox.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from './test-runner-paths';
1212
import type { ConnectionInfo } from '@mongodb-js/connection-info';
1313
import ConnectionString from 'mongodb-connection-string-url';
14+
import { CHROME_STARTUP_FLAGS } from './chrome-startup-flags';
1415

1516
const debug = Debug('compass-e2e-tests:compass-web-sandbox');
1617

@@ -31,7 +32,16 @@ const wait = (ms: number) => {
3132
export function spawnCompassWebSandbox() {
3233
const proc = crossSpawn.spawn(
3334
'npm',
34-
['run', '--unsafe-perm', 'start', '--workspace', '@mongodb-js/compass-web'],
35+
[
36+
'run',
37+
'--unsafe-perm',
38+
'--workspace',
39+
'@mongodb-js/compass-web',
40+
'start',
41+
'--',
42+
'--no-sandbox',
43+
'--in-process-gpu',
44+
],
3545
{ env: process.env }
3646
);
3747
proc.stdout.pipe(process.stdout);
@@ -56,7 +66,7 @@ export async function waitForCompassWebSandboxToBeReady(
5666
}
5767
// No point in trying to fetch sandbox URL right away, give the spawn script
5868
// some time to run
59-
await wait(2000);
69+
await wait(5000);
6070
try {
6171
const res = await fetch(sandboxUrl);
6272
serverReady = res.ok;
@@ -90,6 +100,7 @@ export async function spawnCompassWebSandboxAndSignInToAtlas(
90100
'goog:chromeOptions': {
91101
binary: ELECTRON_PATH,
92102
args: [
103+
...CHROME_STARTUP_FLAGS,
93104
`--user-data-dir=${COMPASS_WEB_WDIO_USER_DATA_PATH}`,
94105
`--app=${COMPASS_WEB_SANDBOX_RUNNER_PATH}`,
95106
],

packages/compass-e2e-tests/helpers/compass.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type { CompassBrowser } from './compass-browser';
2020
import type { LogEntry } from './telemetry';
2121
import Debug from 'debug';
2222
import semver from 'semver';
23-
import { CHROME_STARTUP_FLAGS } from './chrome-startup-flags';
23+
import { CHROME_STARTUP_FLAGS, COMPASS_FLAGS } from './chrome-startup-flags';
2424
import {
2525
DEFAULT_CONNECTION_STRINGS,
2626
DEFAULT_CONNECTION_NAMES,
@@ -494,6 +494,7 @@ export async function runCompassOnce(args: string[], timeout = 30_000) {
494494
// When running binary without webdriver, we need to pass the same flags
495495
// as we pass when running with webdriverio to have similar behaviour.
496496
...CHROME_STARTUP_FLAGS,
497+
...COMPASS_FLAGS,
497498
`--user-data-dir=${String(defaultUserDataDir)}`,
498499
...args,
499500
],
@@ -598,6 +599,8 @@ async function startCompassElectron(
598599
const { needsCloseWelcomeModal, webdriverOptions, wdioOptions, chromeArgs } =
599600
await processCommonOpts(opts);
600601

602+
chromeArgs.push(...COMPASS_FLAGS);
603+
601604
if (!testPackagedApp) {
602605
// https://www.electronjs.org/docs/latest/tutorial/automated-testing#with-webdriverio
603606
chromeArgs.push(`--app=${COMPASS_DESKTOP_PATH}`);
@@ -761,14 +764,16 @@ export async function startBrowser(
761764
assertTestingWeb(context);
762765

763766
runCounter++;
764-
const { webdriverOptions, wdioOptions } = await processCommonOpts();
767+
const { webdriverOptions, wdioOptions, chromeArgs } =
768+
await processCommonOpts();
765769

766770
const browserCapabilities: Record<string, Record<string, unknown>> = {
767771
chrome: {
768772
'goog:chromeOptions': {
769773
prefs: {
770774
'download.default_directory': downloadPath,
771775
},
776+
args: chromeArgs,
772777
},
773778
},
774779
firefox: {

0 commit comments

Comments
 (0)