Skip to content

Commit 73ccf84

Browse files
committed
chore(e2e): initial setup for testing logged in Atlas experience in compass-web
1 parent d127c23 commit 73ccf84

File tree

15 files changed

+249
-36
lines changed

15 files changed

+249
-36
lines changed

.evergreen/buildvariants-and-tasks.in.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ buildvariants:
275275
<% } %>
276276
<% } %>
277277

278+
- name: test-web-sandbox-atlas-cloud
279+
display_name: Test Web Sandbox (w/ Atlas Cloud login)
280+
run_on: ubuntu2004-large
281+
tasks:
282+
- name: test-web-sandbox-atlas-cloud
283+
278284
- name: generate-vulnerability-report
279285
display_name: Vulnerability Report
280286
run_on: ubuntu2004-large
@@ -504,6 +510,21 @@ tasks:
504510
<% } %>
505511
<% } %>
506512

513+
- name: test-web-sandbox-atlas-cloud
514+
tags:
515+
- required-for-publish
516+
- run-on-pr
517+
- assigned_to_jira_team_compass_compass
518+
- foliage_check_task_only
519+
commands:
520+
- func: prepare
521+
- func: install
522+
- func: bootstrap
523+
- func: test-web-sandbox-atlas-cloud
524+
vars:
525+
compass_distribution: compass
526+
debug: 'compass-e2e-tests*,electron*,hadron*,mongo*'
527+
507528
- name: create_static_analysis_report
508529
tags: ['required-for-publish', 'run-on-pr']
509530
depends_on:

.evergreen/buildvariants-and-tasks.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ buildvariants:
257257
- name: test-web-sandbox-firefox-1
258258
- name: test-web-sandbox-firefox-2
259259
- name: test-web-sandbox-firefox-3
260+
- name: test-web-sandbox-atlas-cloud
261+
display_name: Test Web Sandbox (w/ Atlas Cloud login)
262+
run_on: ubuntu2004-large
263+
tasks:
264+
- name: test-web-sandbox-atlas-cloud
260265
- name: generate-vulnerability-report
261266
display_name: Vulnerability Report
262267
run_on: ubuntu2004-large
@@ -1715,6 +1720,20 @@ tasks:
17151720
e2e_test_groups: 3
17161721
e2e_test_group: 3
17171722
debug: compass-e2e-tests*,electron*,hadron*,mongo*
1723+
- name: test-web-sandbox-atlas-cloud
1724+
tags:
1725+
- required-for-publish
1726+
- run-on-pr
1727+
- assigned_to_jira_team_compass_compass
1728+
- foliage_check_task_only
1729+
commands:
1730+
- func: prepare
1731+
- func: install
1732+
- func: bootstrap
1733+
- func: test-web-sandbox-atlas-cloud
1734+
vars:
1735+
compass_distribution: compass
1736+
debug: compass-e2e-tests*,electron*,hadron*,mongo*
17181737
- name: create_static_analysis_report
17191738
tags:
17201739
- required-for-publish

.evergreen/functions.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ variables:
6262
E2E_TESTS_ATLAS_READANYDATABASE_STRING: ${e2e_tests_atlas_readanydatabase_string}
6363
E2E_TESTS_ATLAS_CUSTOMROLE_STRING: ${e2e_tests_atlas_customrole_string}
6464
E2E_TESTS_ATLAS_SPECIFICPERMISSION_STRING: ${e2e_tests_atlas_specificpermission_string}
65+
E2E_TESTS_COMPASS_WEB_ATLAS_DB_USERNAME: ${e2e_tests_compass_web_atlas_db_username}
66+
E2E_TESTS_COMPASS_WEB_ATLAS_USERNAME: ${e2e_tests_compass_web_atlas_username}
67+
E2E_TESTS_COMPASS_WEB_ATLAS_PASSWORD: ${e2e_tests_compass_web_atlas_password}
6568
MACOS_NOTARY_KEY: ${macos_notary_key}
6669
MACOS_NOTARY_SECRET: ${macos_notary_secret}
6770
MACOS_NOTARY_CLIENT_URL: 'https://macos-notary-1628249594.s3.amazonaws.com/releases/client/latest/darwin_amd64.zip'
@@ -673,6 +676,28 @@ functions:
673676
eval $(.evergreen/print-compass-env.sh)
674677
npm run --unsafe-perm --workspace compass-e2e-tests test-web
675678
679+
test-web-sandbox-atlas-cloud:
680+
- command: shell.exec
681+
# Fail the task if it's idle for 10 mins
682+
timeout_secs: 600
683+
params:
684+
working_dir: src
685+
shell: bash
686+
env:
687+
<<: *compass-env
688+
DEBUG: ${debug|}
689+
BROWSER_NAME: chrome
690+
MONGODB_VERSION: latest-enterprise
691+
MONGODB_RUNNER_VERSION: latest-enterprise
692+
script: |
693+
set -e
694+
# Load environment variables
695+
eval $(.evergreen/print-compass-env.sh)
696+
npm run --unsafe-perm \
697+
--workspace compass-e2e-tests test \
698+
-- \
699+
--test-compass-web-atlas-cloud
700+
676701
test-connectivity:
677702
- command: shell.exec
678703
# Fail the task if it's idle for 10 mins

package-lock.json

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
"package-compass": "npm run package-compass --workspace=mongodb-compass --",
3333
"package-compass-debug": "npm run package-compass-debug --workspace=mongodb-compass --",
3434
"package-compass-nocompile": "npm run package-compass-nocompile --workspace=mongodb-compass --",
35-
"prestart": "npm run compile --workspace=@mongodb-js/webpack-config-compass",
36-
"prestart-web": "npm run prestart",
3735
"start": "npm run start --workspace=mongodb-compass",
3836
"start-web": "npm run start --workspace=@mongodb-js/compass-web",
3937
"test": "lerna run test --concurrency 1 --stream",

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
DEFAULT_CONNECTION_NAME_1,
33
DEFAULT_CONNECTION_NAME_2,
44
DEFAULT_CONNECTION_STRING_1,
5+
TEST_COMPASS_WEB_ATLAS_CLOUD,
56
TEST_MULTIPLE_CONNECTIONS,
67
connectionNameFromString,
78
} from '../compass';
@@ -53,6 +54,10 @@ export async function connectWithConnectionString(
5354
connectionString = DEFAULT_CONNECTION_STRING_1,
5455
options: ConnectOptions = {}
5556
): Promise<void> {
57+
if (TEST_COMPASS_WEB_ATLAS_CLOUD) {
58+
return connectByName(browser, connectionString);
59+
}
60+
5661
// Use this command when you need to add a new connection with a specific
5762
// connection string. Most test files should just be using
5863
// browser.connectToDefaults()

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ let MONGODB_USE_ENTERPRISE =
4545
(process.env.MONGODB_VERSION?.endsWith('-enterprise') && 'yes') ?? 'no';
4646

4747
// should we test compass-web (true) or compass electron (false)?
48-
export const TEST_COMPASS_WEB = process.argv.includes('--test-compass-web');
48+
export const TEST_COMPASS_WEB_ATLAS_CLOUD = process.argv.includes(
49+
'--test-compass-web-atlas-cloud'
50+
);
51+
export const TEST_COMPASS_WEB =
52+
process.argv.includes('--test-compass-web') || TEST_COMPASS_WEB_ATLAS_CLOUD;
4953
// multiple connections is now the default
5054
export const TEST_MULTIPLE_CONNECTIONS = true;
5155

packages/compass-e2e-tests/index.ts

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const wait = (ms: number) =>
3030

3131
const allowedArgs = [
3232
'--test-compass-web',
33+
'--test-compass-web-atlas-cloud',
3334
'--no-compile',
3435
'--no-native-modules',
3536
'--test-packaged-app',
@@ -47,60 +48,97 @@ for (const arg of process.argv) {
4748
}
4849
}
4950

51+
const disableStartStop = process.argv.includes('--disable-start-stop');
52+
const shouldTestCompassWebAtlasCloud = process.argv.includes(
53+
'--test-compass-web-atlas-cloud'
54+
);
55+
const shouldTestCompassWeb =
56+
process.argv.includes('--test-compass-web') || shouldTestCompassWebAtlasCloud;
57+
5058
// We can't import mongodb here yet because native modules will be recompiled
5159
let metricsClient: MongoClient;
5260

5361
const FIRST_TEST = 'tests/time-to-first-query.test.ts';
5462

55-
let compassWeb: ChildProcessWithoutNullStreams;
63+
let compassWeb: ChildProcessWithoutNullStreams | undefined;
5664

5765
async function setup() {
5866
debug('X DISPLAY', process.env.DISPLAY);
5967

60-
const disableStartStop = process.argv.includes('--disable-start-stop');
61-
const shouldTestCompassWeb = process.argv.includes('--test-compass-web');
62-
6368
// When working on the tests it is faster to just keep the server running.
6469
if (!disableStartStop) {
6570
debug('Starting MongoDB server');
6671
crossSpawn.sync('npm', ['run', 'start-servers'], { stdio: 'inherit' });
6772

6873
if (shouldTestCompassWeb) {
69-
debug('Starting Compass Web');
70-
compassWeb = crossSpawn.spawn(
71-
'npm',
72-
['run', '--unsafe-perm', 'start-web'],
73-
{
74-
cwd: path.resolve(__dirname, '..', '..'),
75-
env: {
76-
...process.env,
77-
OPEN_BROWSER: 'false', // tell webpack dev server not to open the default browser
78-
DISABLE_DEVSERVER_OVERLAY: 'true',
79-
APP_ENV: 'webdriverio',
80-
},
81-
}
82-
);
74+
debug('Starting Compass Web', { shouldTestCompassWebAtlasCloud });
75+
76+
const spawnCommand: [string, string[]] = shouldTestCompassWebAtlasCloud
77+
? [
78+
'npx',
79+
[
80+
'ts-node',
81+
path.resolve(
82+
__dirname,
83+
'scripts',
84+
'start-compass-web-with-atlas-auth.ts'
85+
),
86+
],
87+
]
88+
: [
89+
'npm',
90+
[
91+
'run',
92+
'--workspace',
93+
'@mongodb-js/compass-web',
94+
'--unsafe-perm',
95+
'start',
96+
],
97+
];
98+
99+
compassWeb = crossSpawn.spawn(...spawnCommand, {
100+
env: {
101+
...process.env,
102+
OPEN_BROWSER: 'false', // tell webpack dev server not to open the default browser
103+
DISABLE_DEVSERVER_OVERLAY: 'true',
104+
APP_ENV: 'webdriverio',
105+
},
106+
});
83107

84108
compassWeb.stdout.pipe(process.stdout);
85109
compassWeb.stderr.pipe(process.stderr);
86110

87111
let serverReady = false;
88112
const start = Date.now();
113+
const timeout = shouldTestCompassWebAtlasCloud ? 240_000 : 120_000;
89114
while (!serverReady) {
90-
if (Date.now() - start >= 120_000) {
115+
if (Date.now() - start >= timeout) {
91116
throw new Error(
92117
'The compass-web sandbox is still not running after 120000ms'
93118
);
94119
}
95120
try {
96121
const res = await fetch('http://localhost:7777');
97122
serverReady = res.ok;
123+
if (shouldTestCompassWebAtlasCloud) {
124+
// TODO: we probably want to have just one endpoint for the sandbox
125+
// healthcheck sort of stuff
126+
const authRes = await fetch('http://localhost:7777/projectId');
127+
serverReady = authRes.ok;
128+
}
98129
debug('Web server ready: %s', serverReady);
99130
} catch (err) {
100131
debug('Failed to connect to dev server: %s', (err as any).message);
101132
}
102133
await wait(1000);
103134
}
135+
if (shouldTestCompassWebAtlasCloud) {
136+
// Now wait for the cert to be issued
137+
// TODO: same as above, probably better to have just one nedpoint we can
138+
// ping to wait for everything to be ready
139+
debug('Waitiing for x509 cert to propagate to Atlas clusters...');
140+
await fetch('http://localhost:7777/x509');
141+
}
104142
} else {
105143
debug('Writing electron-versions.json');
106144
crossSpawn.sync('scripts/write-electron-versions.sh', [], {
@@ -136,11 +174,8 @@ function getResources() {
136174
function cleanup() {
137175
removeUserDataDir();
138176

139-
const disableStartStop = process.argv.includes('--disable-start-stop');
140-
const shouldTestCompassWeb = process.argv.includes('--test-compass-web');
141-
142177
if (!disableStartStop) {
143-
if (shouldTestCompassWeb) {
178+
if (compassWeb) {
144179
debug('Stopping compass-web');
145180
try {
146181
if (compassWeb.pid) {
@@ -199,8 +234,6 @@ function cleanup() {
199234
async function main() {
200235
await setup();
201236

202-
const shouldTestCompassWeb = process.argv.includes('--test-compass-web');
203-
204237
if (!shouldTestCompassWeb) {
205238
if (!process.env.CHROME_VERSION) {
206239
// written during setup() if disableStartStop is false

packages/compass-e2e-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"debug": "^4.3.4",
5454
"depcheck": "^1.4.1",
5555
"electron": "^30.5.1",
56+
"electron-to-chromium": "^1.5.28",
5657
"eslint": "^7.25.0",
5758
"fast-glob": "^3.2.7",
5859
"glob": "^10.2.5",

0 commit comments

Comments
 (0)