Skip to content

Commit 926e3c5

Browse files
committed
chore(e2e): use DEFAULT_CONNECTIONS in connect form helpers
1 parent 1a0cd75 commit 926e3c5

File tree

7 files changed

+104
-99
lines changed

7 files changed

+104
-99
lines changed

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ import { expect } from 'chai';
33
import type { CompassBrowser } from '../compass-browser';
44
import * as Selectors from '../selectors';
55
import type { ConnectFormState } from '../connect-form-state';
6-
import {
7-
DEFAULT_CONNECTION_NAME_1,
8-
DEFAULT_CONNECTION_NAME_2,
9-
DEFAULT_CONNECTION_STRING_1,
10-
DEFAULT_CONNECTION_STRING_2,
11-
TEST_MULTIPLE_CONNECTIONS,
12-
} from '../compass';
6+
import { TEST_MULTIPLE_CONNECTIONS } from '../compass';
137
import Debug from 'debug';
8+
import { DEFAULT_CONNECTIONS } from '../test-runner-context';
9+
import { getConnectionTitle } from '@mongodb-js/connection-info';
1410
const debug = Debug('compass-e2e-tests');
1511

1612
export async function resetConnectForm(browser: CompassBrowser): Promise<void> {
@@ -938,29 +934,13 @@ export async function setConnectFormState(
938934

939935
export async function saveConnection(
940936
browser: CompassBrowser,
941-
state: ConnectFormState,
942-
943-
// TODO(COMPASS-8023): Just remove these once the single connection code is removed
944-
favouriteName: string,
945-
color: string
937+
state: ConnectFormState
946938
): Promise<void> {
947939
await browser.setConnectFormState(state);
948-
if (TEST_MULTIPLE_CONNECTIONS) {
949-
await browser.clickVisible(Selectors.ConnectionModalSaveButton);
950-
await browser
951-
.$(Selectors.ConnectionModal)
952-
.waitForDisplayed({ reverse: true });
953-
} else {
954-
await browser.clickVisible(Selectors.ConnectionEditFavouriteButton);
955-
await browser.$(Selectors.FavoriteModal).waitForDisplayed();
956-
await browser.setValueVisible(Selectors.FavoriteNameInput, favouriteName);
957-
await browser.clickVisible(
958-
`${Selectors.FavoriteColorSelector} [data-testid="color-pick-${color}"]`
959-
);
960-
await browser.$(Selectors.FavoriteSaveButton).waitForEnabled();
961-
await browser.clickVisible(Selectors.FavoriteSaveButton);
962-
await browser.$(Selectors.FavoriteModal).waitForExist({ reverse: true });
963-
}
940+
await browser.clickVisible(Selectors.ConnectionModalSaveButton);
941+
await browser
942+
.$(Selectors.ConnectionModal)
943+
.waitForDisplayed({ reverse: true });
964944
}
965945

966946
export async function setupDefaultConnections(browser: CompassBrowser) {
@@ -986,39 +966,20 @@ export async function setupDefaultConnections(browser: CompassBrowser) {
986966
whereas we do have some tests that try and use those. We can easily change
987967
this in future if needed, though.
988968
*/
989-
for (const connectionName of [
990-
DEFAULT_CONNECTION_NAME_1,
991-
DEFAULT_CONNECTION_NAME_2,
992-
]) {
969+
for (const connectionInfo of DEFAULT_CONNECTIONS) {
970+
const connectionName = getConnectionTitle(connectionInfo);
993971
if (await browser.removeConnection(connectionName)) {
994972
debug('Removing existing connection so we do not create a duplicate', {
995973
connectionName,
996974
});
997975
}
998976
}
999977

1000-
await browser.saveConnection(
1001-
{
1002-
connectionString: DEFAULT_CONNECTION_STRING_1,
1003-
// NOTE: no connectionName, we're going with the auto-generated one. Also no
1004-
// connectionColor. Passing a name and colour for single connection world,
1005-
// though, because that's the only way to create a favourite.
1006-
},
1007-
DEFAULT_CONNECTION_NAME_1,
1008-
'color1'
1009-
);
1010-
1011-
// no need for a second connection in single connection mode
1012-
if (TEST_MULTIPLE_CONNECTIONS) {
1013-
await browser.saveConnection(
1014-
{
1015-
connectionString: DEFAULT_CONNECTION_STRING_2,
1016-
// NOTE: filling in a name so that this one does _not_ have the auto-generated one
1017-
connectionName: DEFAULT_CONNECTION_NAME_2,
1018-
connectionColor: 'Iris',
1019-
},
1020-
DEFAULT_CONNECTION_NAME_2,
1021-
'color8'
1022-
);
978+
for (const connectionInfo of DEFAULT_CONNECTIONS) {
979+
await browser.saveConnection({
980+
connectionString: connectionInfo.connectionOptions.connectionString,
981+
connectionName: connectionInfo.favorite?.name,
982+
connectionColor: connectionInfo.favorite?.color,
983+
});
1023984
}
1024985
}

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import {
4040
WEBDRIVER_DEFAULT_WAITFOR_INTERVAL,
4141
TEST_COMPASS_DESKTOP_PACKAGED_APP,
4242
ELECTRON_PATH,
43+
COMPASS_WEB_BROWSER_NAME,
44+
COPMASS_WEB_BROWSER_VERSION,
4345
} from './test-runner-context';
4446

4547
const debug = Debug('compass-e2e-tests');
@@ -70,12 +72,6 @@ export function skipForWeb(
7072
}
7173
}
7274

73-
function getBrowserName() {
74-
return process.env.BROWSER_NAME ?? 'chrome';
75-
}
76-
77-
export const BROWSER_NAME = getBrowserName();
78-
7975
export const MONGODB_TEST_SERVER_PORT = Number(
8076
process.env.MONGODB_TEST_SERVER_PORT ?? 27091
8177
);
@@ -724,18 +720,10 @@ export async function startBrowser(
724720

725721
const options: RemoteOptions = {
726722
capabilities: {
727-
browserName: BROWSER_NAME, // 'chrome' or 'firefox'
728-
// https://webdriver.io/docs/driverbinaries/
729-
// If you leave out browserVersion it will try and find the browser binary
730-
// on your system. If you specify it it will download that version. The
731-
// main limitation then is that 'latest' is the only 'semantic' version
732-
// that is supported for Firefox.
733-
// https://github.com/puppeteer/puppeteer/blob/ab5d4ac60200d1cea5bcd4910f9ccb323128e79a/packages/browsers/src/browser-data/browser-data.ts#L66
734-
// Alternatively we can download it ourselves and specify the path to the
735-
// binary or we can even start and stop chromedriver/geckodriver manually.
736-
// NOTE: The version of chromedriver or geckodriver in play might also be
737-
// relevant.
738-
browserVersion: 'latest',
723+
browserName: COMPASS_WEB_BROWSER_NAME,
724+
...(COPMASS_WEB_BROWSER_VERSION && {
725+
browserVersion: COPMASS_WEB_BROWSER_VERSION,
726+
}),
739727
},
740728
...webdriverOptions,
741729
...wdioOptions,

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

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import {
22
getConnectionTitle,
33
type ConnectionInfo,
44
} from '@mongodb-js/connection-info';
5-
import ConnectionString from 'mongodb-connection-string-url';
65
import path from 'path';
76
import electronPath from 'electron';
87
import electronPackageJson from 'electron/package.json';
98
// @ts-expect-error no types for this package
109
import { electronToChromium } from 'electron-to-chromium';
10+
import type { MongoClusterOptions } from 'mongodb-runner';
1111

1212
if (typeof electronPath !== 'string') {
1313
throw new Error(
14-
'Running e2e tests in an unsupported runtime: `electron` is not a string'
14+
'Running e2e tests in an unsupported runtime: `electronPath` is not a string'
1515
);
1616
}
1717

@@ -43,12 +43,42 @@ export const SKIP_NATIVE_MODULE_REBUILD =
4343
export const DISABLE_START_STOP = process.argv.includes('--disable-start-stop');
4444
export const MOCHA_BAIL = process.argv.includes('--bail');
4545

46-
export const DEFAULT_CONNECTIONS: ConnectionInfo[] = [
46+
export const COMPASS_WEB_BROWSER_NAME = process.env.BROWSER_NAME ?? 'chrome';
47+
// https://webdriver.io/docs/driverbinaries/
48+
//
49+
// If you leave out browserVersion it will try and find the browser binary on
50+
// your system. If you specify it it will download that version. The main
51+
// limitation then is that 'latest' is the only 'semantic' version that is
52+
// supported for Firefox.
53+
// https://github.com/puppeteer/puppeteer/blob/ab5d4ac60200d1cea5bcd4910f9ccb323128e79a/packages/browsers/src/browser-data/browser-data.ts#L66
54+
//
55+
// Alternatively we can download it ourselves and specify the path to the binary
56+
// or we can even start and stop chromedriver/geckodriver manually.
57+
//
58+
// NOTE: The version of chromedriver or geckodriver in play might also be
59+
// relevant.
60+
export const COPMASS_WEB_BROWSER_VERSION =
61+
process.env.BROWSER_VERSION === 'unset'
62+
? undefined
63+
: process.env.BROWSER_VERSION ?? 'latest';
64+
65+
const MONGODB_TESTSERVER_VERSION =
66+
process.env.MONGODB_VERSION ?? process.env.MONGODB_RUNNER_VERSION;
67+
68+
export const DEFAULT_CONNECTIONS: (ConnectionInfo & {
69+
testServer?: Partial<MongoClusterOptions>;
70+
})[] = [
4771
{
4872
id: 'test-connection-1',
4973
connectionOptions: {
5074
connectionString: 'mongodb://127.0.0.1:27091/test',
5175
},
76+
testServer: {
77+
version: MONGODB_TESTSERVER_VERSION,
78+
topology: 'replset',
79+
secondaries: 0,
80+
args: ['--port', '27091'],
81+
},
5282
},
5383
{
5484
id: 'test-connection-2',
@@ -57,6 +87,13 @@ export const DEFAULT_CONNECTIONS: ConnectionInfo[] = [
5787
},
5888
favorite: {
5989
name: 'connection-2',
90+
color: 'Iris',
91+
},
92+
testServer: {
93+
version: MONGODB_TESTSERVER_VERSION,
94+
topology: 'replset',
95+
secondaries: 0,
96+
args: ['--port', '27092'],
6097
},
6198
},
6299
];
@@ -69,11 +106,6 @@ export const DEFAULT_CONNECTION_NAMES = DEFAULT_CONNECTIONS.map((info) => {
69106
return getConnectionTitle(info);
70107
});
71108

72-
export const DEFAULT_CONNECTION_PORTS = DEFAULT_CONNECTIONS.map((info) => {
73-
const str = new ConnectionString(info.connectionOptions.connectionString);
74-
return Number(str.hosts[0].split(':')[1]);
75-
});
76-
77109
export const DEFAULT_CONNECTIONS_SERVER_INFO: {
78110
version: string;
79111
enterprise: boolean;

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import gunzip from './gunzip';
22
import path from 'path';
33
import fs from 'fs';
44
import {
5-
DEFAULT_CONNECTION_PORTS,
5+
DEFAULT_CONNECTIONS,
66
DEFAULT_CONNECTIONS_SERVER_INFO,
77
DISABLE_START_STOP,
88
E2E_WORKSPACE_PATH,
@@ -26,6 +26,7 @@ import {
2626
rebuildNativeModules,
2727
removeUserDataDir,
2828
} from './compass';
29+
import { getConnectionTitle } from '@mongodb-js/connection-info';
2930

3031
export const globalFixturesAbortController = new AbortController();
3132

@@ -75,21 +76,22 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {
7576
debug('X DISPLAY', process.env.DISPLAY);
7677

7778
if (!DISABLE_START_STOP) {
78-
debug('Starting MongoDB servers');
79-
80-
for (const port of DEFAULT_CONNECTION_PORTS) {
81-
const server = await startTestServer({
82-
topology: 'replset',
83-
secondaries: 0,
84-
args: ['--port', String(port)],
85-
version:
86-
process.env.MONGODB_VERSION ?? process.env.MONGODB_RUNNER_VERSION,
87-
});
88-
servers.push(server);
89-
cleanupFns.push(() => {
90-
debug('Stopping server at port %s', port);
91-
return server.close();
92-
});
79+
for (const connectionInfo of DEFAULT_CONNECTIONS) {
80+
if (connectionInfo.testServer) {
81+
debug(
82+
'Starting MongoDB server for connection %s',
83+
getConnectionTitle(connectionInfo)
84+
);
85+
const server = await startTestServer(connectionInfo.testServer);
86+
servers.push(server);
87+
cleanupFns.push(() => {
88+
debug(
89+
'Stopping server for connection %s',
90+
getConnectionTitle(connectionInfo)
91+
);
92+
return server.close();
93+
});
94+
}
9395
throwIfAborted();
9496
}
9597

packages/compass-e2e-tests/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async function main() {
8080
return index >= minGroupIndex && index <= maxGroupIndex;
8181
});
8282

83-
console.info('Test files:', rawTests);
83+
debug('Test files:', rawTests);
8484

8585
// The only test file that's interested in the first-run experience (at the
8686
// time of writing) is time-to-first-query.ts and that happens to be
@@ -107,7 +107,7 @@ async function main() {
107107
mocha.rootHooks(mochaRootHooks);
108108

109109
// print the test order for debugging purposes and so we can tweak the groups later
110-
console.log('test order', tests);
110+
debug('Test order:', tests);
111111

112112
tests.forEach((testPath: string) => {
113113
mocha.addFile(path.join(__dirname, testPath));

packages/compass-e2e-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"tree-kill": "^1.2.2",
7373
"ts-node": "^10.9.1",
7474
"webdriverio": "^8.40.0",
75+
"why-is-node-running": "^3.2.0",
7576
"xvfb-maybe": "^0.2.1"
7677
}
7778
}

0 commit comments

Comments
 (0)