Skip to content

Commit ce0d66f

Browse files
authored
chore(e2e): restructure e2e test helpers to better separate shared state and setup / teardown functions COMPASS-8361 (#6383)
* chore(e2e): restructure e2e test helpers to better separate shared state and setup / teardown functions * chore: fix depcheck and var name * chore: remove TEST_PACKAGED_APP env var usage * chore: replset for test servers and better cleanup * chore: eslint fixes * chore(e2e): use DEFAULT_CONNECTIONS in connect form helpers * chore: ts fix * chore: update to non-esm version * chore: fix glob * chore: remove unused imports * chore: more glob adjustments * chore: uncomment retries * chore: fix env var name
1 parent c72a1df commit ce0d66f

21 files changed

+737
-967
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: |

package-lock.json

Lines changed: 47 additions & 2 deletions
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/.depcheckrc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ ignores:
22
- '@mongodb-js/prettier-config-compass'
33
- '@mongodb-js/tsconfig-compass'
44
- '@wdio/types'
5-
- 'mongodb-compass'
65
- 'ps-list'
7-
- 'mongodb-runner'
6+
# Avoiding recursive deps on monorepo workspaces
7+
- 'mongodb-compass'
8+
- '@mongodb-js/mocha-config-compass'
9+
- 'compass-e2e-tests'
10+
- '@mongodb-js/compass-web'
811
# TODO(COMPASS-8312): depcheck doesn't count this dependency because it's a
912
# types only import and the depcheck parser is resolving the @types/<name>
1013
# package as a dep instead

packages/compass-e2e-tests/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@
22
.log
33
fixtures/*.csv
44
fixtures/*.json
5-
write-electron-versions.js
6-
electron-versions.json

packages/compass-e2e-tests/.prettierignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@
33
fixtures
44
.nyc_output
55
coverage
6-
7-
# Generated files
8-
electron-versions.json
9-
write-electron-versions.js

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

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +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_ATLAS_CLOUD_EXTERNAL_URL,
12-
TEST_MULTIPLE_CONNECTIONS,
13-
} from '../compass';
6+
import { TEST_MULTIPLE_CONNECTIONS } from '../compass';
147
import Debug from 'debug';
8+
import { DEFAULT_CONNECTIONS } from '../test-runner-context';
9+
import { getConnectionTitle } from '@mongodb-js/connection-info';
1510
const debug = Debug('compass-e2e-tests');
1611

1712
export async function resetConnectForm(browser: CompassBrowser): Promise<void> {
@@ -939,29 +934,13 @@ export async function setConnectFormState(
939934

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

967946
export async function setupDefaultConnections(browser: CompassBrowser) {
@@ -987,45 +966,20 @@ export async function setupDefaultConnections(browser: CompassBrowser) {
987966
whereas we do have some tests that try and use those. We can easily change
988967
this in future if needed, though.
989968
*/
990-
991-
// no need to setup connections if we are running against Atlas
992-
if (TEST_ATLAS_CLOUD_EXTERNAL_URL) {
993-
return;
994-
}
995-
996-
for (const connectionName of [
997-
DEFAULT_CONNECTION_NAME_1,
998-
DEFAULT_CONNECTION_NAME_2,
999-
]) {
969+
for (const connectionInfo of DEFAULT_CONNECTIONS) {
970+
const connectionName = getConnectionTitle(connectionInfo);
1000971
if (await browser.removeConnection(connectionName)) {
1001972
debug('Removing existing connection so we do not create a duplicate', {
1002973
connectionName,
1003974
});
1004975
}
1005976
}
1006977

1007-
await browser.saveConnection(
1008-
{
1009-
connectionString: DEFAULT_CONNECTION_STRING_1,
1010-
// NOTE: no connectionName, we're going with the auto-generated one. Also no
1011-
// connectionColor. Passing a name and colour for single connection world,
1012-
// though, because that's the only way to create a favourite.
1013-
},
1014-
DEFAULT_CONNECTION_NAME_1,
1015-
'color1'
1016-
);
1017-
1018-
// no need for a second connection in single connection mode
1019-
if (TEST_MULTIPLE_CONNECTIONS) {
1020-
await browser.saveConnection(
1021-
{
1022-
connectionString: DEFAULT_CONNECTION_STRING_2,
1023-
// NOTE: filling in a name so that this one does _not_ have the auto-generated one
1024-
connectionName: DEFAULT_CONNECTION_NAME_2,
1025-
connectionColor: 'Iris',
1026-
},
1027-
DEFAULT_CONNECTION_NAME_2,
1028-
'color8'
1029-
);
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+
});
1030984
}
1031985
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22
import type { CompassBrowser } from '../compass-browser';
3-
import { SCREENSHOTS_PATH } from '../compass';
3+
import { LOG_SCREENSHOTS_PATH } from '../test-runner-context';
44

55
const withTimeout = (millis: number, promise: Promise<any>) => {
66
let timeoutPid: NodeJS.Timeout;
@@ -26,7 +26,7 @@ export async function screenshot(
2626
// are still in progress or not.
2727
await browser.pause(1000);
2828

29-
const fullPath = path.join(SCREENSHOTS_PATH, filename);
29+
const fullPath = path.join(LOG_SCREENSHOTS_PATH, filename);
3030
try {
3131
await withTimeout(10000, browser.saveScreenshot(fullPath));
3232
} catch (err: any) {

0 commit comments

Comments
 (0)