From ed6acd7914d75adb120c5f881459e3a47347003d Mon Sep 17 00:00:00 2001 From: Simon Zhu Date: Fri, 18 Oct 2024 12:07:12 -0400 Subject: [PATCH 1/7] enable test against atlas --- packages/compass-e2e-tests/helpers/compass.ts | 59 ++++++- packages/compass-e2e-tests/index.ts | 161 ++++++++++-------- .../tests/collection-rename.test.ts | 6 +- 3 files changed, 142 insertions(+), 84 deletions(-) diff --git a/packages/compass-e2e-tests/helpers/compass.ts b/packages/compass-e2e-tests/helpers/compass.ts index 531edc9420e..dc4b97812ab 100644 --- a/packages/compass-e2e-tests/helpers/compass.ts +++ b/packages/compass-e2e-tests/helpers/compass.ts @@ -46,6 +46,8 @@ let MONGODB_USE_ENTERPRISE = // should we test compass-web (true) or compass electron (false)? export const TEST_COMPASS_WEB = process.argv.includes('--test-compass-web'); +export const ATLAS_DOMAIN = process.env.ATLAS_DOMAIN; +export const ATLAS_GROUP_ID = process.env.ATLAS_GROUP_ID; // multiple connections is now the default export const TEST_MULTIPLE_CONNECTIONS = true; @@ -75,19 +77,22 @@ export const MONGODB_TEST_SERVER_PORT = Number( process.env.MONGODB_TEST_SERVER_PORT ?? 27091 ); -export const DEFAULT_CONNECTION_STRING_1 = `mongodb://127.0.0.1:${MONGODB_TEST_SERVER_PORT}/test`; +export const DEFAULT_CONNECTION_STRING_1 = + process.env.CONNECTION_STRING_1 || + `mongodb://127.0.0.1:${MONGODB_TEST_SERVER_PORT}/test`; // NOTE: in browser.setupDefaultConnections() we don't give the first connection an // explicit name, so it gets a calculated one based off the connection string -export const DEFAULT_CONNECTION_NAME_1 = connectionNameFromString( - DEFAULT_CONNECTION_STRING_1 -); +export const DEFAULT_CONNECTION_NAME_1 = + process.env.CONNECTION_NAME_1 || + connectionNameFromString(DEFAULT_CONNECTION_STRING_1); // for testing multiple connections -export const DEFAULT_CONNECTION_STRING_2 = `mongodb://127.0.0.1:${ - MONGODB_TEST_SERVER_PORT + 1 -}/test`; +export const DEFAULT_CONNECTION_STRING_2 = + process.env.CONNECTION_STRING_2 || + `mongodb://127.0.0.1:${MONGODB_TEST_SERVER_PORT + 1}/test`; // NOTE: in browser.setupDefaultConnections() the second connection gets given an explicit name -export const DEFAULT_CONNECTION_NAME_2 = 'connection-2'; +export const DEFAULT_CONNECTION_NAME_2 = + process.env.CONNECTION_NAME_2 || 'connection-2'; export function updateMongoDBServerInfo() { try { @@ -787,7 +792,43 @@ export async function startBrowser( ...webdriverOptions, ...wdioOptions, })) as CompassBrowser; - await browser.navigateTo('http://localhost:7777/'); + + if (ATLAS_DOMAIN) { + // Navigate to a 404 page to set cookies + await browser.navigateTo(`https://${ATLAS_DOMAIN}/404`); + + const cookiesFile = process.env.COOKIES_FILE; + if (!cookiesFile) { + throw new Error( + 'ATLAS_DOMAIN is set but COOKIES_FILE is not. Please set COOKIES_FILE to the path of the cookies file.' + ); + } + const cookies = JSON.parse(await fs.readFile(cookiesFile, 'utf8')); + + for (const cookie of cookies) { + if ( + cookie.name.includes('mmsa-') || + cookie.name.includes('mdb-sat') || + cookie.name.includes('mdb-srt') + ) { + await browser.setCookies({ + name: cookie.name, + value: cookie.value, + domain: cookie.domain, + path: cookie.path, + secure: cookie.secure, + httpOnly: cookie.httpOnly, + }); + } + } + + await browser.navigateTo( + `https://${ATLAS_DOMAIN}/v2/${ATLAS_GROUP_ID}#/explorer` + ); + } else { + await browser.navigateTo('http://localhost:7777/'); + } + const compass = new Compass(name, browser, { mode: 'web', writeCoverage: false, diff --git a/packages/compass-e2e-tests/index.ts b/packages/compass-e2e-tests/index.ts index 309767330a2..877106b4ff5 100644 --- a/packages/compass-e2e-tests/index.ts +++ b/packages/compass-e2e-tests/index.ts @@ -18,6 +18,7 @@ import { LOG_PATH, removeUserDataDir, updateMongoDBServerInfo, + ATLAS_DOMAIN, } from './helpers/compass'; import ResultLogger from './helpers/result-logger'; @@ -60,52 +61,54 @@ async function setup() { const disableStartStop = process.argv.includes('--disable-start-stop'); const shouldTestCompassWeb = process.argv.includes('--test-compass-web'); - // When working on the tests it is faster to just keep the server running. - if (!disableStartStop) { - debug('Starting MongoDB server'); - crossSpawn.sync('npm', ['run', 'start-servers'], { stdio: 'inherit' }); - - if (shouldTestCompassWeb) { - debug('Starting Compass Web'); - compassWeb = crossSpawn.spawn( - 'npm', - ['run', '--unsafe-perm', 'start-web'], - { - cwd: path.resolve(__dirname, '..', '..'), - env: { - ...process.env, - OPEN_BROWSER: 'false', // tell webpack dev server not to open the default browser - DISABLE_DEVSERVER_OVERLAY: 'true', - APP_ENV: 'webdriverio', - }, + if (!ATLAS_DOMAIN) { + // When working on the tests it is faster to just keep the server running. + if (!disableStartStop) { + debug('Starting MongoDB server'); + crossSpawn.sync('npm', ['run', 'start-servers'], { stdio: 'inherit' }); + + if (shouldTestCompassWeb) { + debug('Starting Compass Web'); + compassWeb = crossSpawn.spawn( + 'npm', + ['run', '--unsafe-perm', 'start-web'], + { + cwd: path.resolve(__dirname, '..', '..'), + env: { + ...process.env, + OPEN_BROWSER: 'false', // tell webpack dev server not to open the default browser + DISABLE_DEVSERVER_OVERLAY: 'true', + APP_ENV: 'webdriverio', + }, + } + ); + + compassWeb.stdout.pipe(process.stdout); + compassWeb.stderr.pipe(process.stderr); + + let serverReady = false; + const start = Date.now(); + while (!serverReady) { + if (Date.now() - start >= 120_000) { + throw new Error( + 'The compass-web sandbox is still not running after 120000ms' + ); + } + try { + const res = await fetch('http://localhost:7777'); + serverReady = res.ok; + debug('Web server ready: %s', serverReady); + } catch (err) { + debug('Failed to connect to dev server: %s', (err as any).message); + } + await wait(1000); } - ); - - compassWeb.stdout.pipe(process.stdout); - compassWeb.stderr.pipe(process.stderr); - - let serverReady = false; - const start = Date.now(); - while (!serverReady) { - if (Date.now() - start >= 120_000) { - throw new Error( - 'The compass-web sandbox is still not running after 120000ms' - ); - } - try { - const res = await fetch('http://localhost:7777'); - serverReady = res.ok; - debug('Web server ready: %s', serverReady); - } catch (err) { - debug('Failed to connect to dev server: %s', (err as any).message); - } - await wait(1000); + } else { + debug('Writing electron-versions.json'); + crossSpawn.sync('scripts/write-electron-versions.sh', [], { + stdio: 'inherit', + }); } - } else { - debug('Writing electron-versions.json'); - crossSpawn.sync('scripts/write-electron-versions.sh', [], { - stdio: 'inherit', - }); } } @@ -118,8 +121,10 @@ async function setup() { fs.mkdirSync(LOG_PATH, { recursive: true }); - debug('Getting mongodb server info'); - updateMongoDBServerInfo(); + if (!ATLAS_DOMAIN) { + debug('Getting mongodb server info'); + updateMongoDBServerInfo(); + } } function getResources() { @@ -139,34 +144,36 @@ function cleanup() { const disableStartStop = process.argv.includes('--disable-start-stop'); const shouldTestCompassWeb = process.argv.includes('--test-compass-web'); - if (!disableStartStop) { - if (shouldTestCompassWeb) { - debug('Stopping compass-web'); - try { - if (compassWeb.pid) { - debug(`killing compass-web [${compassWeb.pid}]`); - kill(compassWeb.pid, 'SIGINT'); - } else { - debug('no pid for compass-web'); + if (!ATLAS_DOMAIN) { + if (!disableStartStop) { + if (shouldTestCompassWeb) { + debug('Stopping compass-web'); + try { + if (compassWeb.pid) { + debug(`killing compass-web [${compassWeb.pid}]`); + kill(compassWeb.pid, 'SIGINT'); + } else { + debug('no pid for compass-web'); + } + } catch (e) { + debug('Failed to stop compass-web', e); } - } catch (e) { - debug('Failed to stop compass-web', e); } - } - debug('Stopping MongoDB server'); - try { - crossSpawn.sync('npm', ['run', 'stop-servers'], { - // If it's taking too long we might as well kill the process and move on, - // mongodb-runner is flaky sometimes and in ci `posttest-ci` script will - // take care of additional clean up anyway - timeout: 120_000, - stdio: 'inherit', - }); - } catch (e) { - debug('Failed to stop MongoDB Server', e); + debug('Stopping MongoDB server'); + try { + crossSpawn.sync('npm', ['run', 'stop-servers'], { + // If it's taking too long we might as well kill the process and move on, + // mongodb-runner is flaky sometimes and in ci `posttest-ci` script will + // take care of additional clean up anyway + timeout: 120_000, + stdio: 'inherit', + }); + } catch (e) { + debug('Failed to stop MongoDB Server', e); + } + debug('Done stopping'); } - debug('Done stopping'); } // Since the webdriverio update something is messing with the terminal's @@ -258,9 +265,10 @@ async function main() { const e2eTestGroupsAmount = parseInt(process.env.E2E_TEST_GROUPS || '1'); const e2eTestGroup = parseInt(process.env.E2E_TEST_GROUP || '1'); + const e2eTestFilter = process.env.E2E_TEST_FILTER || '*'; - const rawTests = ( - await glob('tests/**/*.{test,spec}.ts', { + let tests = ( + await glob(`tests/**/${e2eTestFilter}.{test,spec}.ts`, { cwd: __dirname, }) ).filter((value, index, array) => { @@ -271,7 +279,7 @@ async function main() { return index >= minGroupIndex && index <= maxGroupIndex; }); - console.info('Test files:', rawTests); + console.info('Test files:', tests); // The only test file that's interested in the first-run experience (at the // time of writing) is time-to-first-query.ts and that happens to be @@ -279,7 +287,12 @@ async function main() { // will also get the slow first run experience for no good reason unless it is // the time-to-first-query.ts test. // So yeah.. this is a bit of a micro optimisation. - const tests = [FIRST_TEST, ...rawTests.filter((t) => t !== FIRST_TEST)]; + for (let i = 0; i < tests.length; ++i) { + if (tests[i] === FIRST_TEST) { + [tests[i], tests[0]] = [tests[0], tests[i]]; + break; + } + } // Ensure the insert-data mocha hooks are run. tests.unshift(path.join('helpers', 'insert-data.ts')); diff --git a/packages/compass-e2e-tests/tests/collection-rename.test.ts b/packages/compass-e2e-tests/tests/collection-rename.test.ts index 6d48e84f91d..64648b271fd 100644 --- a/packages/compass-e2e-tests/tests/collection-rename.test.ts +++ b/packages/compass-e2e-tests/tests/collection-rename.test.ts @@ -6,6 +6,7 @@ import { screenshotIfFailed, TEST_COMPASS_WEB, DEFAULT_CONNECTION_NAME_1, + ATLAS_DOMAIN, } from '../helpers/compass'; import type { CompassBrowser } from '../helpers/compass-browser'; import { createDummyCollections } from '../helpers/insert-data'; @@ -84,7 +85,10 @@ describe('Collection Rename Modal', () => { before(async function () { compass = await init(this.test?.fullTitle()); browser = compass.browser; - await browser.setupDefaultConnections(); + // no need to setup connections if we are running against Atlas + if (!ATLAS_DOMAIN) { + await browser.setupDefaultConnections(); + } }); beforeEach(async function () { From 6c17604e8924a92f1f7b110100c9afc0ca6a1b47 Mon Sep 17 00:00:00 2001 From: Simon Zhu Date: Fri, 18 Oct 2024 16:11:16 -0400 Subject: [PATCH 2/7] use const --- packages/compass-e2e-tests/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compass-e2e-tests/index.ts b/packages/compass-e2e-tests/index.ts index 877106b4ff5..0ef22cdfdcc 100644 --- a/packages/compass-e2e-tests/index.ts +++ b/packages/compass-e2e-tests/index.ts @@ -267,7 +267,7 @@ async function main() { const e2eTestGroup = parseInt(process.env.E2E_TEST_GROUP || '1'); const e2eTestFilter = process.env.E2E_TEST_FILTER || '*'; - let tests = ( + const tests = ( await glob(`tests/**/${e2eTestFilter}.{test,spec}.ts`, { cwd: __dirname, }) From 9585f5043155bec8d7c0ff6d30e5f409d809556c Mon Sep 17 00:00:00 2001 From: Simon Zhu Date: Mon, 21 Oct 2024 10:15:05 -0400 Subject: [PATCH 3/7] update function --- packages/compass-e2e-tests/helpers/compass.ts | 3 ++- packages/compass-e2e-tests/index.ts | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/compass-e2e-tests/helpers/compass.ts b/packages/compass-e2e-tests/helpers/compass.ts index dc4b97812ab..b63796770af 100644 --- a/packages/compass-e2e-tests/helpers/compass.ts +++ b/packages/compass-e2e-tests/helpers/compass.ts @@ -111,7 +111,8 @@ export function updateMongoDBServerInfo() { 'server-info', '--', '--connectionString', - `mongodb://127.0.0.1:${String(MONGODB_TEST_SERVER_PORT)}`, + process.env.CONNECTION_STRING_1 || + `mongodb://127.0.0.1:${String(MONGODB_TEST_SERVER_PORT)}`, ], { encoding: 'utf-8' } ); diff --git a/packages/compass-e2e-tests/index.ts b/packages/compass-e2e-tests/index.ts index 0ef22cdfdcc..4480d04a0ad 100644 --- a/packages/compass-e2e-tests/index.ts +++ b/packages/compass-e2e-tests/index.ts @@ -121,10 +121,8 @@ async function setup() { fs.mkdirSync(LOG_PATH, { recursive: true }); - if (!ATLAS_DOMAIN) { - debug('Getting mongodb server info'); - updateMongoDBServerInfo(); - } + debug('Getting mongodb server info'); + updateMongoDBServerInfo(); } function getResources() { From a0b6199f045c3e55e10292d06d60ff020913a251 Mon Sep 17 00:00:00 2001 From: Simon Zhu Date: Mon, 21 Oct 2024 16:06:38 -0400 Subject: [PATCH 4/7] comments --- .../helpers/commands/connect-form.ts | 7 ++++ packages/compass-e2e-tests/helpers/compass.ts | 36 +++++++++++++------ packages/compass-e2e-tests/index.ts | 6 ++-- .../tests/collection-rename.test.ts | 6 +--- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/packages/compass-e2e-tests/helpers/commands/connect-form.ts b/packages/compass-e2e-tests/helpers/commands/connect-form.ts index 97575d39fce..a53158eb869 100644 --- a/packages/compass-e2e-tests/helpers/commands/connect-form.ts +++ b/packages/compass-e2e-tests/helpers/commands/connect-form.ts @@ -8,6 +8,7 @@ import { DEFAULT_CONNECTION_NAME_2, DEFAULT_CONNECTION_STRING_1, DEFAULT_CONNECTION_STRING_2, + TEST_ATLAS_CLOUD_EXTERNAL_URL, TEST_MULTIPLE_CONNECTIONS, } from '../compass'; import Debug from 'debug'; @@ -986,6 +987,12 @@ export async function setupDefaultConnections(browser: CompassBrowser) { whereas we do have some tests that try and use those. We can easily change this in future if needed, though. */ + + // no need to setup connections if we are running against Atlas + if (!TEST_ATLAS_CLOUD_EXTERNAL_URL) { + return; + } + for (const connectionName of [ DEFAULT_CONNECTION_NAME_1, DEFAULT_CONNECTION_NAME_2, diff --git a/packages/compass-e2e-tests/helpers/compass.ts b/packages/compass-e2e-tests/helpers/compass.ts index b63796770af..1ee6fe9f5d9 100644 --- a/packages/compass-e2e-tests/helpers/compass.ts +++ b/packages/compass-e2e-tests/helpers/compass.ts @@ -46,8 +46,10 @@ let MONGODB_USE_ENTERPRISE = // should we test compass-web (true) or compass electron (false)? export const TEST_COMPASS_WEB = process.argv.includes('--test-compass-web'); -export const ATLAS_DOMAIN = process.env.ATLAS_DOMAIN; -export const ATLAS_GROUP_ID = process.env.ATLAS_GROUP_ID; +export const TEST_ATLAS_CLOUD_EXTERNAL_URL = + process.env.TEST_ATLAS_CLOUD_EXTERNAL_URL; +export const TEST_ATLAS_CLOUD_EXTERNAL_GROUP_ID = + process.env.TEST_ATLAS_CLOUD_EXTERNAL_GROUP_ID; // multiple connections is now the default export const TEST_MULTIPLE_CONNECTIONS = true; @@ -78,21 +80,21 @@ export const MONGODB_TEST_SERVER_PORT = Number( ); export const DEFAULT_CONNECTION_STRING_1 = - process.env.CONNECTION_STRING_1 || + process.env.TEST_ATLAS_CLOUD_EXTERNAL_CONNECTION_STRING_1 || `mongodb://127.0.0.1:${MONGODB_TEST_SERVER_PORT}/test`; // NOTE: in browser.setupDefaultConnections() we don't give the first connection an // explicit name, so it gets a calculated one based off the connection string export const DEFAULT_CONNECTION_NAME_1 = - process.env.CONNECTION_NAME_1 || + process.env.TEST_ATLAS_CLOUD_EXTERNAL_CONNECTION_NAME_1 || connectionNameFromString(DEFAULT_CONNECTION_STRING_1); // for testing multiple connections export const DEFAULT_CONNECTION_STRING_2 = - process.env.CONNECTION_STRING_2 || + process.env.TEST_ATLAS_CLOUD_EXTERNAL_CONNECTION_STRING_2 || `mongodb://127.0.0.1:${MONGODB_TEST_SERVER_PORT + 1}/test`; // NOTE: in browser.setupDefaultConnections() the second connection gets given an explicit name export const DEFAULT_CONNECTION_NAME_2 = - process.env.CONNECTION_NAME_2 || 'connection-2'; + process.env.TEST_ATLAS_CLOUD_EXTERNAL_CONNECTION_NAME_2 || 'connection-2'; export function updateMongoDBServerInfo() { try { @@ -111,7 +113,7 @@ export function updateMongoDBServerInfo() { 'server-info', '--', '--connectionString', - process.env.CONNECTION_STRING_1 || + process.env.TEST_ATLAS_CLOUD_EXTERNAL_CONNECTION_STRING_1 || `mongodb://127.0.0.1:${String(MONGODB_TEST_SERVER_PORT)}`, ], { encoding: 'utf-8' } @@ -767,6 +769,16 @@ async function startCompassElectron( return compass; } +export type StoredAtlasCloudCookies = { + name: string; + value: string; + domain: string; + path: string; + secure: boolean; + httpOnly: boolean; + expirationDate: number; +}[]; + export async function startBrowser( name: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -794,9 +806,9 @@ export async function startBrowser( ...wdioOptions, })) as CompassBrowser; - if (ATLAS_DOMAIN) { + if (TEST_ATLAS_CLOUD_EXTERNAL_URL) { // Navigate to a 404 page to set cookies - await browser.navigateTo(`https://${ATLAS_DOMAIN}/404`); + await browser.navigateTo(`https://${TEST_ATLAS_CLOUD_EXTERNAL_URL}/404`); const cookiesFile = process.env.COOKIES_FILE; if (!cookiesFile) { @@ -804,7 +816,9 @@ export async function startBrowser( 'ATLAS_DOMAIN is set but COOKIES_FILE is not. Please set COOKIES_FILE to the path of the cookies file.' ); } - const cookies = JSON.parse(await fs.readFile(cookiesFile, 'utf8')); + const cookies: StoredAtlasCloudCookies = JSON.parse( + await fs.readFile(cookiesFile, 'utf8') + ); for (const cookie of cookies) { if ( @@ -824,7 +838,7 @@ export async function startBrowser( } await browser.navigateTo( - `https://${ATLAS_DOMAIN}/v2/${ATLAS_GROUP_ID}#/explorer` + `https://${TEST_ATLAS_CLOUD_EXTERNAL_URL}/v2/${TEST_ATLAS_CLOUD_EXTERNAL_GROUP_ID}#/explorer` ); } else { await browser.navigateTo('http://localhost:7777/'); diff --git a/packages/compass-e2e-tests/index.ts b/packages/compass-e2e-tests/index.ts index 4480d04a0ad..1350bb2c73b 100644 --- a/packages/compass-e2e-tests/index.ts +++ b/packages/compass-e2e-tests/index.ts @@ -18,7 +18,7 @@ import { LOG_PATH, removeUserDataDir, updateMongoDBServerInfo, - ATLAS_DOMAIN, + TEST_ATLAS_CLOUD_EXTERNAL_URL, } from './helpers/compass'; import ResultLogger from './helpers/result-logger'; @@ -61,7 +61,7 @@ async function setup() { const disableStartStop = process.argv.includes('--disable-start-stop'); const shouldTestCompassWeb = process.argv.includes('--test-compass-web'); - if (!ATLAS_DOMAIN) { + if (!TEST_ATLAS_CLOUD_EXTERNAL_URL) { // When working on the tests it is faster to just keep the server running. if (!disableStartStop) { debug('Starting MongoDB server'); @@ -142,7 +142,7 @@ function cleanup() { const disableStartStop = process.argv.includes('--disable-start-stop'); const shouldTestCompassWeb = process.argv.includes('--test-compass-web'); - if (!ATLAS_DOMAIN) { + if (!TEST_ATLAS_CLOUD_EXTERNAL_URL) { if (!disableStartStop) { if (shouldTestCompassWeb) { debug('Stopping compass-web'); diff --git a/packages/compass-e2e-tests/tests/collection-rename.test.ts b/packages/compass-e2e-tests/tests/collection-rename.test.ts index 64648b271fd..6d48e84f91d 100644 --- a/packages/compass-e2e-tests/tests/collection-rename.test.ts +++ b/packages/compass-e2e-tests/tests/collection-rename.test.ts @@ -6,7 +6,6 @@ import { screenshotIfFailed, TEST_COMPASS_WEB, DEFAULT_CONNECTION_NAME_1, - ATLAS_DOMAIN, } from '../helpers/compass'; import type { CompassBrowser } from '../helpers/compass-browser'; import { createDummyCollections } from '../helpers/insert-data'; @@ -85,10 +84,7 @@ describe('Collection Rename Modal', () => { before(async function () { compass = await init(this.test?.fullTitle()); browser = compass.browser; - // no need to setup connections if we are running against Atlas - if (!ATLAS_DOMAIN) { - await browser.setupDefaultConnections(); - } + await browser.setupDefaultConnections(); }); beforeEach(async function () { From 40b64472f51404c1064afb15f6d79a0a830aab94 Mon Sep 17 00:00:00 2001 From: Simon Zhu Date: Mon, 21 Oct 2024 16:46:06 -0400 Subject: [PATCH 5/7] fix if check --- packages/compass-e2e-tests/helpers/commands/connect-form.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compass-e2e-tests/helpers/commands/connect-form.ts b/packages/compass-e2e-tests/helpers/commands/connect-form.ts index a53158eb869..d6a11d99bbd 100644 --- a/packages/compass-e2e-tests/helpers/commands/connect-form.ts +++ b/packages/compass-e2e-tests/helpers/commands/connect-form.ts @@ -989,7 +989,7 @@ export async function setupDefaultConnections(browser: CompassBrowser) { */ // no need to setup connections if we are running against Atlas - if (!TEST_ATLAS_CLOUD_EXTERNAL_URL) { + if (TEST_ATLAS_CLOUD_EXTERNAL_URL) { return; } From 6eb7796b92bb6172a09767b8c28feff2dd6cad72 Mon Sep 17 00:00:00 2001 From: Simon Zhu Date: Tue, 22 Oct 2024 09:33:32 -0400 Subject: [PATCH 6/7] comments --- packages/compass-e2e-tests/helpers/compass.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/compass-e2e-tests/helpers/compass.ts b/packages/compass-e2e-tests/helpers/compass.ts index 1ee6fe9f5d9..eac7c8ee1c5 100644 --- a/packages/compass-e2e-tests/helpers/compass.ts +++ b/packages/compass-e2e-tests/helpers/compass.ts @@ -810,32 +810,34 @@ export async function startBrowser( // Navigate to a 404 page to set cookies await browser.navigateTo(`https://${TEST_ATLAS_CLOUD_EXTERNAL_URL}/404`); - const cookiesFile = process.env.COOKIES_FILE; + const cookiesFile = process.env.TEST_ATLAS_CLOUD_EXTERNAL_COOKIES_FILE; if (!cookiesFile) { throw new Error( - 'ATLAS_DOMAIN is set but COOKIES_FILE is not. Please set COOKIES_FILE to the path of the cookies file.' + 'TEST_ATLAS_CLOUD_EXTERNAL_URL is set but TEST_ATLAS_CLOUD_EXTERNAL_COOKIES_FILE is not. Please set TEST_ATLAS_CLOUD_EXTERNAL_COOKIES_FILE to the path of the cookies file.' ); } const cookies: StoredAtlasCloudCookies = JSON.parse( await fs.readFile(cookiesFile, 'utf8') ); - for (const cookie of cookies) { - if ( - cookie.name.includes('mmsa-') || - cookie.name.includes('mdb-sat') || - cookie.name.includes('mdb-srt') - ) { - await browser.setCookies({ + // These are the relevant cookies for auth: + // https://github.com/10gen/mms/blob/6d27992a6ab9ab31471c8bcdaa4e347aa39f4013/server/src/features/com/xgen/svc/cukes/helpers/Client.java#L122-L130 + await browser.setCookies( + cookies + .filter((cookie) => { + cookie.name.includes('mmsa-') || + cookie.name.includes('mdb-sat') || + cookie.name.includes('mdb-srt'); + }) + .map((cookie) => ({ name: cookie.name, value: cookie.value, domain: cookie.domain, path: cookie.path, secure: cookie.secure, httpOnly: cookie.httpOnly, - }); - } - } + })) + ); await browser.navigateTo( `https://${TEST_ATLAS_CLOUD_EXTERNAL_URL}/v2/${TEST_ATLAS_CLOUD_EXTERNAL_GROUP_ID}#/explorer` From 6b85cd5572986313e84a9a8147ccb196eb2f6029 Mon Sep 17 00:00:00 2001 From: Simon Zhu Date: Tue, 22 Oct 2024 09:48:21 -0400 Subject: [PATCH 7/7] comments --- packages/compass-e2e-tests/helpers/compass.ts | 3 +-- packages/compass-e2e-tests/index.ts | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/compass-e2e-tests/helpers/compass.ts b/packages/compass-e2e-tests/helpers/compass.ts index eac7c8ee1c5..3daccb6e094 100644 --- a/packages/compass-e2e-tests/helpers/compass.ts +++ b/packages/compass-e2e-tests/helpers/compass.ts @@ -113,8 +113,7 @@ export function updateMongoDBServerInfo() { 'server-info', '--', '--connectionString', - process.env.TEST_ATLAS_CLOUD_EXTERNAL_CONNECTION_STRING_1 || - `mongodb://127.0.0.1:${String(MONGODB_TEST_SERVER_PORT)}`, + DEFAULT_CONNECTION_STRING_1, ], { encoding: 'utf-8' } ); diff --git a/packages/compass-e2e-tests/index.ts b/packages/compass-e2e-tests/index.ts index 1350bb2c73b..0974b80e50c 100644 --- a/packages/compass-e2e-tests/index.ts +++ b/packages/compass-e2e-tests/index.ts @@ -285,12 +285,11 @@ async function main() { // will also get the slow first run experience for no good reason unless it is // the time-to-first-query.ts test. // So yeah.. this is a bit of a micro optimisation. - for (let i = 0; i < tests.length; ++i) { - if (tests[i] === FIRST_TEST) { - [tests[i], tests[0]] = [tests[0], tests[i]]; - break; - } - } + tests.sort((a, b) => { + if (a === FIRST_TEST) return -1; + else if (b === FIRST_TEST) return 1; + else return 0; + }); // Ensure the insert-data mocha hooks are run. tests.unshift(path.join('helpers', 'insert-data.ts'));