Skip to content

Commit ed6acd7

Browse files
committed
enable test against atlas
1 parent 0a92de6 commit ed6acd7

File tree

3 files changed

+142
-84
lines changed

3 files changed

+142
-84
lines changed

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

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ let MONGODB_USE_ENTERPRISE =
4646

4747
// should we test compass-web (true) or compass electron (false)?
4848
export const TEST_COMPASS_WEB = process.argv.includes('--test-compass-web');
49+
export const ATLAS_DOMAIN = process.env.ATLAS_DOMAIN;
50+
export const ATLAS_GROUP_ID = process.env.ATLAS_GROUP_ID;
4951
// multiple connections is now the default
5052
export const TEST_MULTIPLE_CONNECTIONS = true;
5153

@@ -75,19 +77,22 @@ export const MONGODB_TEST_SERVER_PORT = Number(
7577
process.env.MONGODB_TEST_SERVER_PORT ?? 27091
7678
);
7779

78-
export const DEFAULT_CONNECTION_STRING_1 = `mongodb://127.0.0.1:${MONGODB_TEST_SERVER_PORT}/test`;
80+
export const DEFAULT_CONNECTION_STRING_1 =
81+
process.env.CONNECTION_STRING_1 ||
82+
`mongodb://127.0.0.1:${MONGODB_TEST_SERVER_PORT}/test`;
7983
// NOTE: in browser.setupDefaultConnections() we don't give the first connection an
8084
// explicit name, so it gets a calculated one based off the connection string
81-
export const DEFAULT_CONNECTION_NAME_1 = connectionNameFromString(
82-
DEFAULT_CONNECTION_STRING_1
83-
);
85+
export const DEFAULT_CONNECTION_NAME_1 =
86+
process.env.CONNECTION_NAME_1 ||
87+
connectionNameFromString(DEFAULT_CONNECTION_STRING_1);
8488

8589
// for testing multiple connections
86-
export const DEFAULT_CONNECTION_STRING_2 = `mongodb://127.0.0.1:${
87-
MONGODB_TEST_SERVER_PORT + 1
88-
}/test`;
90+
export const DEFAULT_CONNECTION_STRING_2 =
91+
process.env.CONNECTION_STRING_2 ||
92+
`mongodb://127.0.0.1:${MONGODB_TEST_SERVER_PORT + 1}/test`;
8993
// NOTE: in browser.setupDefaultConnections() the second connection gets given an explicit name
90-
export const DEFAULT_CONNECTION_NAME_2 = 'connection-2';
94+
export const DEFAULT_CONNECTION_NAME_2 =
95+
process.env.CONNECTION_NAME_2 || 'connection-2';
9196

9297
export function updateMongoDBServerInfo() {
9398
try {
@@ -787,7 +792,43 @@ export async function startBrowser(
787792
...webdriverOptions,
788793
...wdioOptions,
789794
})) as CompassBrowser;
790-
await browser.navigateTo('http://localhost:7777/');
795+
796+
if (ATLAS_DOMAIN) {
797+
// Navigate to a 404 page to set cookies
798+
await browser.navigateTo(`https://${ATLAS_DOMAIN}/404`);
799+
800+
const cookiesFile = process.env.COOKIES_FILE;
801+
if (!cookiesFile) {
802+
throw new Error(
803+
'ATLAS_DOMAIN is set but COOKIES_FILE is not. Please set COOKIES_FILE to the path of the cookies file.'
804+
);
805+
}
806+
const cookies = JSON.parse(await fs.readFile(cookiesFile, 'utf8'));
807+
808+
for (const cookie of cookies) {
809+
if (
810+
cookie.name.includes('mmsa-') ||
811+
cookie.name.includes('mdb-sat') ||
812+
cookie.name.includes('mdb-srt')
813+
) {
814+
await browser.setCookies({
815+
name: cookie.name,
816+
value: cookie.value,
817+
domain: cookie.domain,
818+
path: cookie.path,
819+
secure: cookie.secure,
820+
httpOnly: cookie.httpOnly,
821+
});
822+
}
823+
}
824+
825+
await browser.navigateTo(
826+
`https://${ATLAS_DOMAIN}/v2/${ATLAS_GROUP_ID}#/explorer`
827+
);
828+
} else {
829+
await browser.navigateTo('http://localhost:7777/');
830+
}
831+
791832
const compass = new Compass(name, browser, {
792833
mode: 'web',
793834
writeCoverage: false,

packages/compass-e2e-tests/index.ts

Lines changed: 87 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
LOG_PATH,
1919
removeUserDataDir,
2020
updateMongoDBServerInfo,
21+
ATLAS_DOMAIN,
2122
} from './helpers/compass';
2223
import ResultLogger from './helpers/result-logger';
2324

@@ -60,52 +61,54 @@ async function setup() {
6061
const disableStartStop = process.argv.includes('--disable-start-stop');
6162
const shouldTestCompassWeb = process.argv.includes('--test-compass-web');
6263

63-
// When working on the tests it is faster to just keep the server running.
64-
if (!disableStartStop) {
65-
debug('Starting MongoDB server');
66-
crossSpawn.sync('npm', ['run', 'start-servers'], { stdio: 'inherit' });
67-
68-
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-
},
64+
if (!ATLAS_DOMAIN) {
65+
// When working on the tests it is faster to just keep the server running.
66+
if (!disableStartStop) {
67+
debug('Starting MongoDB server');
68+
crossSpawn.sync('npm', ['run', 'start-servers'], { stdio: 'inherit' });
69+
70+
if (shouldTestCompassWeb) {
71+
debug('Starting Compass Web');
72+
compassWeb = crossSpawn.spawn(
73+
'npm',
74+
['run', '--unsafe-perm', 'start-web'],
75+
{
76+
cwd: path.resolve(__dirname, '..', '..'),
77+
env: {
78+
...process.env,
79+
OPEN_BROWSER: 'false', // tell webpack dev server not to open the default browser
80+
DISABLE_DEVSERVER_OVERLAY: 'true',
81+
APP_ENV: 'webdriverio',
82+
},
83+
}
84+
);
85+
86+
compassWeb.stdout.pipe(process.stdout);
87+
compassWeb.stderr.pipe(process.stderr);
88+
89+
let serverReady = false;
90+
const start = Date.now();
91+
while (!serverReady) {
92+
if (Date.now() - start >= 120_000) {
93+
throw new Error(
94+
'The compass-web sandbox is still not running after 120000ms'
95+
);
96+
}
97+
try {
98+
const res = await fetch('http://localhost:7777');
99+
serverReady = res.ok;
100+
debug('Web server ready: %s', serverReady);
101+
} catch (err) {
102+
debug('Failed to connect to dev server: %s', (err as any).message);
103+
}
104+
await wait(1000);
81105
}
82-
);
83-
84-
compassWeb.stdout.pipe(process.stdout);
85-
compassWeb.stderr.pipe(process.stderr);
86-
87-
let serverReady = false;
88-
const start = Date.now();
89-
while (!serverReady) {
90-
if (Date.now() - start >= 120_000) {
91-
throw new Error(
92-
'The compass-web sandbox is still not running after 120000ms'
93-
);
94-
}
95-
try {
96-
const res = await fetch('http://localhost:7777');
97-
serverReady = res.ok;
98-
debug('Web server ready: %s', serverReady);
99-
} catch (err) {
100-
debug('Failed to connect to dev server: %s', (err as any).message);
101-
}
102-
await wait(1000);
106+
} else {
107+
debug('Writing electron-versions.json');
108+
crossSpawn.sync('scripts/write-electron-versions.sh', [], {
109+
stdio: 'inherit',
110+
});
103111
}
104-
} else {
105-
debug('Writing electron-versions.json');
106-
crossSpawn.sync('scripts/write-electron-versions.sh', [], {
107-
stdio: 'inherit',
108-
});
109112
}
110113
}
111114

@@ -118,8 +121,10 @@ async function setup() {
118121

119122
fs.mkdirSync(LOG_PATH, { recursive: true });
120123

121-
debug('Getting mongodb server info');
122-
updateMongoDBServerInfo();
124+
if (!ATLAS_DOMAIN) {
125+
debug('Getting mongodb server info');
126+
updateMongoDBServerInfo();
127+
}
123128
}
124129

125130
function getResources() {
@@ -139,34 +144,36 @@ function cleanup() {
139144
const disableStartStop = process.argv.includes('--disable-start-stop');
140145
const shouldTestCompassWeb = process.argv.includes('--test-compass-web');
141146

142-
if (!disableStartStop) {
143-
if (shouldTestCompassWeb) {
144-
debug('Stopping compass-web');
145-
try {
146-
if (compassWeb.pid) {
147-
debug(`killing compass-web [${compassWeb.pid}]`);
148-
kill(compassWeb.pid, 'SIGINT');
149-
} else {
150-
debug('no pid for compass-web');
147+
if (!ATLAS_DOMAIN) {
148+
if (!disableStartStop) {
149+
if (shouldTestCompassWeb) {
150+
debug('Stopping compass-web');
151+
try {
152+
if (compassWeb.pid) {
153+
debug(`killing compass-web [${compassWeb.pid}]`);
154+
kill(compassWeb.pid, 'SIGINT');
155+
} else {
156+
debug('no pid for compass-web');
157+
}
158+
} catch (e) {
159+
debug('Failed to stop compass-web', e);
151160
}
152-
} catch (e) {
153-
debug('Failed to stop compass-web', e);
154161
}
155-
}
156162

157-
debug('Stopping MongoDB server');
158-
try {
159-
crossSpawn.sync('npm', ['run', 'stop-servers'], {
160-
// If it's taking too long we might as well kill the process and move on,
161-
// mongodb-runner is flaky sometimes and in ci `posttest-ci` script will
162-
// take care of additional clean up anyway
163-
timeout: 120_000,
164-
stdio: 'inherit',
165-
});
166-
} catch (e) {
167-
debug('Failed to stop MongoDB Server', e);
163+
debug('Stopping MongoDB server');
164+
try {
165+
crossSpawn.sync('npm', ['run', 'stop-servers'], {
166+
// If it's taking too long we might as well kill the process and move on,
167+
// mongodb-runner is flaky sometimes and in ci `posttest-ci` script will
168+
// take care of additional clean up anyway
169+
timeout: 120_000,
170+
stdio: 'inherit',
171+
});
172+
} catch (e) {
173+
debug('Failed to stop MongoDB Server', e);
174+
}
175+
debug('Done stopping');
168176
}
169-
debug('Done stopping');
170177
}
171178

172179
// Since the webdriverio update something is messing with the terminal's
@@ -258,9 +265,10 @@ async function main() {
258265

259266
const e2eTestGroupsAmount = parseInt(process.env.E2E_TEST_GROUPS || '1');
260267
const e2eTestGroup = parseInt(process.env.E2E_TEST_GROUP || '1');
268+
const e2eTestFilter = process.env.E2E_TEST_FILTER || '*';
261269

262-
const rawTests = (
263-
await glob('tests/**/*.{test,spec}.ts', {
270+
let tests = (
271+
await glob(`tests/**/${e2eTestFilter}.{test,spec}.ts`, {
264272
cwd: __dirname,
265273
})
266274
).filter((value, index, array) => {
@@ -271,15 +279,20 @@ async function main() {
271279
return index >= minGroupIndex && index <= maxGroupIndex;
272280
});
273281

274-
console.info('Test files:', rawTests);
282+
console.info('Test files:', tests);
275283

276284
// The only test file that's interested in the first-run experience (at the
277285
// time of writing) is time-to-first-query.ts and that happens to be
278286
// alphabetically right at the end. Which is fine, but the first test to run
279287
// will also get the slow first run experience for no good reason unless it is
280288
// the time-to-first-query.ts test.
281289
// So yeah.. this is a bit of a micro optimisation.
282-
const tests = [FIRST_TEST, ...rawTests.filter((t) => t !== FIRST_TEST)];
290+
for (let i = 0; i < tests.length; ++i) {
291+
if (tests[i] === FIRST_TEST) {
292+
[tests[i], tests[0]] = [tests[0], tests[i]];
293+
break;
294+
}
295+
}
283296

284297
// Ensure the insert-data mocha hooks are run.
285298
tests.unshift(path.join('helpers', 'insert-data.ts'));

packages/compass-e2e-tests/tests/collection-rename.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
screenshotIfFailed,
77
TEST_COMPASS_WEB,
88
DEFAULT_CONNECTION_NAME_1,
9+
ATLAS_DOMAIN,
910
} from '../helpers/compass';
1011
import type { CompassBrowser } from '../helpers/compass-browser';
1112
import { createDummyCollections } from '../helpers/insert-data';
@@ -84,7 +85,10 @@ describe('Collection Rename Modal', () => {
8485
before(async function () {
8586
compass = await init(this.test?.fullTitle());
8687
browser = compass.browser;
87-
await browser.setupDefaultConnections();
88+
// no need to setup connections if we are running against Atlas
89+
if (!ATLAS_DOMAIN) {
90+
await browser.setupDefaultConnections();
91+
}
8892
});
8993

9094
beforeEach(async function () {

0 commit comments

Comments
 (0)