Skip to content

Commit c921216

Browse files
committed
Merge remote-tracking branch 'origin/main' into restructure-e2e-test-runner
This also includes re-applying changes from #6381 from scratch
2 parents 0d6af31 + b1bc75e commit c921216

File tree

20 files changed

+216
-170
lines changed

20 files changed

+216
-170
lines changed

.evergreen/functions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ functions:
664664
DEBUG: ${debug|}
665665
MONGODB_VERSION: ${mongodb_version|}
666666
MONGODB_RUNNER_VERSION: ${mongodb_version|}
667-
BROWSER_NAME: ${browser_name}
667+
COMPASS_WEB_BROWSER_NAME: ${browser_name}
668668
E2E_TEST_GROUPS: ${e2e_test_groups}
669669
E2E_TEST_GROUP: ${e2e_test_group}
670670
script: |

.evergreen/print-compass-env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
export MONGODB_DEFAULT_VERSION=6.0.x
5+
export MONGODB_DEFAULT_VERSION=7.0.x
66

77
if [[ $OSTYPE == "cygwin" ]]; then
88
export PLATFORM='win32'

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ admin-token-bot <[email protected]>
9292
Kræn Hansen <[email protected]>
9393
Kræn Hansen <[email protected]>
9494
Ruchitha Rajaghatta <[email protected]>
95+

THIRD-PARTY-NOTICES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The following third-party software is used by and included in **Mongodb Compass**.
2-
This document was automatically generated on Thu Oct 17 2024.
2+
This document was automatically generated on Tue Oct 22 2024.
33

44
## List of dependencies
55

docs/tracking-plan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Compass Tracking Plan
33

4-
Generated on Thu, Oct 17, 2024 at 03:33 PM
4+
Generated on Tue, Oct 22, 2024 at 04:10 PM
55

66
## Table of Contents
77

packages/atlas-service/src/main.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,7 @@ export class CompassAuthService {
376376

377377
await throwIfNotOk(res);
378378

379-
const userInfo = (await res.json()) as AtlasUserInfo;
380-
381-
// TODO: Remove hadcoded `enabledAIFeature: true` when Atlas returns the actual value.
382-
return { ...userInfo, enabledAIFeature: true };
379+
return (await res.json()) as AtlasUserInfo;
383380
})();
384381
return this.currentUser;
385382
}

packages/atlas-service/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type AtlasUserInfo = {
99
lastName: string;
1010
primaryEmail: string;
1111
login: string;
12-
} & { enabledAIFeature: boolean };
12+
};
1313

1414
export type IntrospectInfo = { active: boolean };
1515

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

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ import {
4141
TEST_COMPASS_DESKTOP_PACKAGED_APP,
4242
ELECTRON_PATH,
4343
COMPASS_WEB_BROWSER_NAME,
44-
COPMASS_WEB_BROWSER_VERSION,
44+
COMPASS_WEB_BROWSER_VERSION,
45+
TEST_ATLAS_CLOUD_EXTERNAL,
46+
TEST_ATLAS_CLOUD_EXTERNAL_COOKIES_FILE,
47+
TEST_ATLAS_CLOUD_EXTERNAL_URL,
48+
TEST_ATLAS_CLOUD_EXTERNAL_GROUP_ID,
49+
COMPASS_WEB_SANDBOX_URL,
4550
} from './test-runner-context';
4651

4752
const debug = Debug('compass-e2e-tests');
@@ -710,6 +715,16 @@ async function startCompassElectron(
710715
return compass;
711716
}
712717

718+
export type StoredAtlasCloudCookies = {
719+
name: string;
720+
value: string;
721+
domain: string;
722+
path: string;
723+
secure: boolean;
724+
httpOnly: boolean;
725+
expirationDate: number;
726+
}[];
727+
713728
export async function startBrowser(
714729
name: string,
715730
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -721,19 +736,66 @@ export async function startBrowser(
721736
const options: RemoteOptions = {
722737
capabilities: {
723738
browserName: COMPASS_WEB_BROWSER_NAME,
724-
...(COPMASS_WEB_BROWSER_VERSION && {
725-
browserVersion: COPMASS_WEB_BROWSER_VERSION,
739+
...(COMPASS_WEB_BROWSER_VERSION && {
740+
browserVersion: COMPASS_WEB_BROWSER_VERSION,
726741
}),
727742
},
728743
...webdriverOptions,
729744
...wdioOptions,
730745
};
731746

732-
debug('Starting compass via webdriverio with the following configuration:');
747+
debug('Starting browser via webdriverio with the following configuration:');
733748
debug(JSON.stringify(options, null, 2));
734749

735750
const browser: CompassBrowser = (await remote(options)) as CompassBrowser;
736-
await browser.navigateTo('http://localhost:7777/');
751+
752+
if (TEST_ATLAS_CLOUD_EXTERNAL) {
753+
// To be able to use `setCookies` method, we need to first open any page on
754+
// the same domain as the cookies we are going to set
755+
// https://webdriver.io/docs/api/browser/setCookies/
756+
await browser.navigateTo(`${TEST_ATLAS_CLOUD_EXTERNAL_URL!}/404`);
757+
758+
type StoredAtlasCloudCookies = {
759+
name: string;
760+
value: string;
761+
domain: string;
762+
path: string;
763+
secure: boolean;
764+
httpOnly: boolean;
765+
expirationDate: number;
766+
}[];
767+
768+
const cookies: StoredAtlasCloudCookies = JSON.parse(
769+
await fs.readFile(TEST_ATLAS_CLOUD_EXTERNAL_COOKIES_FILE!, 'utf8')
770+
);
771+
772+
await browser.setCookies(
773+
cookies
774+
.filter((cookie) => {
775+
// These are the relevant cookies for auth:
776+
// https://github.com/10gen/mms/blob/6d27992a6ab9ab31471c8bcdaa4e347aa39f4013/server/src/features/com/xgen/svc/cukes/helpers/Client.java#L122-L130
777+
return (
778+
cookie.name.includes('mmsa-') ||
779+
cookie.name.includes('mdb-sat') ||
780+
cookie.name.includes('mdb-srt')
781+
);
782+
})
783+
.map((cookie) => ({
784+
name: cookie.name,
785+
value: cookie.value,
786+
domain: cookie.domain,
787+
path: cookie.path,
788+
secure: cookie.secure,
789+
httpOnly: cookie.httpOnly,
790+
}))
791+
);
792+
793+
await browser.navigateTo(
794+
`${TEST_ATLAS_CLOUD_EXTERNAL_URL!}/v2/${TEST_ATLAS_CLOUD_EXTERNAL_GROUP_ID!}#/explorer`
795+
);
796+
} else {
797+
await browser.navigateTo(COMPASS_WEB_SANDBOX_URL);
798+
}
737799

738800
const compass = new Compass(name, browser, {
739801
mode: 'web',

packages/compass-e2e-tests/helpers/test-runner-context.ts

Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,46 @@ export const ALLOWED_RUNNER_ARGS = [
2525
'--bail',
2626
];
2727

28-
export const TEST_COMPASS_WEB = process.argv.includes('--test-compass-web');
28+
/**
29+
* Variables used by a special use-case of running e2e tests against a
30+
* cloud(-dev).mongodb.com URL. If you're changing anything related to these,
31+
* make sure that the tests in mms are also updated to account for that
32+
*/
33+
export const TEST_ATLAS_CLOUD_EXTERNAL_URL =
34+
process.env.TEST_ATLAS_CLOUD_EXTERNAL_URL;
35+
export const TEST_ATLAS_CLOUD_EXTERNAL_COOKIES_FILE =
36+
process.env.TEST_ATLAS_CLOUD_EXTERNAL_COOKIES_FILE;
37+
export const TEST_ATLAS_CLOUD_EXTERNAL_GROUP_ID =
38+
process.env.TEST_ATLAS_CLOUD_EXTERNAL_GROUP_ID;
39+
const TEST_ATLAS_CLOUD_EXTERNAL_DEFAULT_CONNECTIONS: ConnectionInfo[] | null =
40+
JSON.parse(process.env.TEST_ATLAS_CLOUD_DEFAULT_CONNECTIONS ?? 'null');
41+
42+
const ALL_ATLAS_CLOUD_EXTERNAL_VARS = [
43+
TEST_ATLAS_CLOUD_EXTERNAL_URL,
44+
TEST_ATLAS_CLOUD_EXTERNAL_COOKIES_FILE,
45+
TEST_ATLAS_CLOUD_EXTERNAL_GROUP_ID,
46+
TEST_ATLAS_CLOUD_EXTERNAL_DEFAULT_CONNECTIONS,
47+
];
48+
49+
export const TEST_ATLAS_CLOUD_EXTERNAL = ALL_ATLAS_CLOUD_EXTERNAL_VARS.some(
50+
(val) => {
51+
return !!val;
52+
}
53+
);
54+
55+
if (
56+
TEST_ATLAS_CLOUD_EXTERNAL &&
57+
ALL_ATLAS_CLOUD_EXTERNAL_VARS.some((val) => {
58+
return !val;
59+
})
60+
) {
61+
throw new Error(
62+
'Trying to test Atlas Cloud external URL but some required variables are missing'
63+
);
64+
}
65+
66+
export const TEST_COMPASS_WEB =
67+
process.argv.includes('--test-compass-web') || TEST_ATLAS_CLOUD_EXTERNAL;
2968
export const TEST_COMPASS_DESKTOP = !TEST_COMPASS_WEB;
3069
export const TEST_COMPASS_DESKTOP_PACKAGED_APP = process.argv.includes(
3170
'--test-packaged-app'
@@ -57,46 +96,50 @@ export const COMPASS_WEB_BROWSER_NAME = process.env.BROWSER_NAME ?? 'chrome';
5796
//
5897
// NOTE: The version of chromedriver or geckodriver in play might also be
5998
// relevant.
60-
export const COPMASS_WEB_BROWSER_VERSION =
99+
export const COMPASS_WEB_BROWSER_VERSION =
61100
process.env.BROWSER_VERSION === 'unset'
62101
? undefined
63102
: process.env.BROWSER_VERSION ?? 'latest';
103+
export const COMPASS_WEB_SANDBOX_URL = 'http://localhost:7777';
64104

65105
const MONGODB_TESTSERVER_VERSION =
66106
process.env.MONGODB_VERSION ?? process.env.MONGODB_RUNNER_VERSION;
67107

68108
export const DEFAULT_CONNECTIONS: (ConnectionInfo & {
69109
testServer?: Partial<MongoClusterOptions>;
70-
})[] = [
71-
{
72-
id: 'test-connection-1',
73-
connectionOptions: {
74-
connectionString: 'mongodb://127.0.0.1:27091/test',
75-
},
76-
testServer: {
77-
version: MONGODB_TESTSERVER_VERSION,
78-
topology: 'replset',
79-
secondaries: 0,
80-
args: ['--port', '27091'],
81-
},
82-
},
83-
{
84-
id: 'test-connection-2',
85-
connectionOptions: {
86-
connectionString: 'mongodb://127.0.0.1:27092/test',
87-
},
88-
favorite: {
89-
name: 'connection-2',
90-
color: 'Iris',
91-
},
92-
testServer: {
93-
version: MONGODB_TESTSERVER_VERSION,
94-
topology: 'replset',
95-
secondaries: 0,
96-
args: ['--port', '27092'],
97-
},
98-
},
99-
];
110+
})[] =
111+
TEST_ATLAS_CLOUD_EXTERNAL && TEST_ATLAS_CLOUD_EXTERNAL_DEFAULT_CONNECTIONS
112+
? TEST_ATLAS_CLOUD_EXTERNAL_DEFAULT_CONNECTIONS
113+
: [
114+
{
115+
id: 'test-connection-1',
116+
connectionOptions: {
117+
connectionString: 'mongodb://127.0.0.1:27091/test',
118+
},
119+
testServer: {
120+
version: MONGODB_TESTSERVER_VERSION,
121+
topology: 'replset',
122+
secondaries: 0,
123+
args: ['--port', '27091'],
124+
},
125+
},
126+
{
127+
id: 'test-connection-2',
128+
connectionOptions: {
129+
connectionString: 'mongodb://127.0.0.1:27092/test',
130+
},
131+
favorite: {
132+
name: 'connection-2',
133+
color: 'Iris',
134+
},
135+
testServer: {
136+
version: MONGODB_TESTSERVER_VERSION,
137+
topology: 'replset',
138+
secondaries: 0,
139+
args: ['--port', '27092'],
140+
},
141+
},
142+
];
100143

101144
export const DEFAULT_CONNECTION_STRINGS = DEFAULT_CONNECTIONS.map((info) => {
102145
return info.connectionOptions.connectionString;

packages/compass-e2e-tests/helpers/test-runner-global-fixtures.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import gunzip from './gunzip';
22
import fs from 'fs';
33
import {
4+
COMPASS_WEB_SANDBOX_URL,
45
DEFAULT_CONNECTIONS,
56
DEFAULT_CONNECTIONS_SERVER_INFO,
67
DISABLE_START_STOP,
78
E2E_WORKSPACE_PATH,
89
LOG_PATH,
910
SKIP_COMPASS_DESKTOP_COMPILE,
1011
SKIP_NATIVE_MODULE_REBUILD,
12+
TEST_ATLAS_CLOUD_EXTERNAL,
1113
TEST_COMPASS_DESKTOP,
1214
TEST_COMPASS_DESKTOP_PACKAGED_APP,
1315
TEST_COMPASS_WEB,
1416
} from './test-runner-context';
1517
import Debug from 'debug';
16-
import type { MongoCluster } from '@mongodb-js/compass-test-server';
1718
import { startTestServer } from '@mongodb-js/compass-test-server';
1819
import crossSpawn from 'cross-spawn';
1920
import kill from 'tree-kill';
@@ -46,8 +47,6 @@ const wait = (ms: number) =>
4647

4748
const cleanupFns: (() => Promise<void> | void)[] = [];
4849

49-
const servers: MongoCluster[] = [];
50-
5150
/**
5251
* Main hook that does all the main pre-setup before running tests:
5352
* - Unpacks the fixtures
@@ -85,7 +84,6 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {
8584
getConnectionTitle(connectionInfo)
8685
);
8786
const server = await startTestServer(connectionInfo.testServer);
88-
servers.push(server);
8987
cleanupFns.push(() => {
9088
debug(
9189
'Stopping server for connection %s',
@@ -97,8 +95,8 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {
9795
throwIfAborted();
9896
}
9997

100-
if (TEST_COMPASS_WEB) {
101-
debug('Starting Compass Web');
98+
if (TEST_COMPASS_WEB && !TEST_ATLAS_CLOUD_EXTERNAL) {
99+
debug('Starting Compass Web server ...');
102100
const compassWeb = spawnCompassWeb();
103101
cleanupFns.push(() => {
104102
if (compassWeb.pid) {
@@ -196,7 +194,7 @@ async function waitForCompassWebToBeReady() {
196194
);
197195
}
198196
try {
199-
const res = await fetch('http://localhost:7777');
197+
const res = await fetch(COMPASS_WEB_SANDBOX_URL);
200198
serverReady = res.ok;
201199
debug('Web server ready:', serverReady);
202200
} catch (err) {
@@ -208,22 +206,19 @@ async function waitForCompassWebToBeReady() {
208206

209207
async function updateMongoDBServerInfo() {
210208
try {
211-
const [info1, info2] = await Promise.all(
212-
servers.map(async (server) => {
213-
let client: MongoClient | undefined;
214-
try {
215-
client = new MongoClient(server.connectionString);
216-
const info = await client.db('admin').command({ buildInfo: 1 });
217-
return {
218-
version: info.version,
219-
enterprise: isEnterprise(info),
220-
};
221-
} finally {
222-
void client?.close(true);
223-
}
224-
})
225-
);
226-
DEFAULT_CONNECTIONS_SERVER_INFO.push(info1, info2);
209+
for (const { connectionOptions } of DEFAULT_CONNECTIONS) {
210+
let client: MongoClient | undefined;
211+
try {
212+
client = new MongoClient(connectionOptions.connectionString);
213+
const info = await client.db('admin').command({ buildInfo: 1 });
214+
DEFAULT_CONNECTIONS_SERVER_INFO.push({
215+
version: info.version,
216+
enterprise: isEnterprise(info),
217+
});
218+
} finally {
219+
void client?.close(true);
220+
}
221+
}
227222
} catch (err) {
228223
debug('Failed to get MongoDB server info:', err);
229224
}

0 commit comments

Comments
 (0)