Skip to content

Commit

Permalink
chore(e2e): restructure e2e test helpers to better separate shared st…
Browse files Browse the repository at this point in the history
…ate 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
  • Loading branch information
gribnoysup authored Oct 23, 2024
1 parent c72a1df commit ce0d66f
Show file tree
Hide file tree
Showing 21 changed files with 737 additions and 967 deletions.
2 changes: 1 addition & 1 deletion .evergreen/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ functions:
DEBUG: ${debug|}
MONGODB_VERSION: ${mongodb_version|}
MONGODB_RUNNER_VERSION: ${mongodb_version|}
BROWSER_NAME: ${browser_name}
COMPASS_WEB_BROWSER_NAME: ${browser_name}
E2E_TEST_GROUPS: ${e2e_test_groups}
E2E_TEST_GROUP: ${e2e_test_group}
script: |
Expand Down
49 changes: 47 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
"package-compass": "npm run package-compass --workspace=mongodb-compass --",
"package-compass-debug": "npm run package-compass-debug --workspace=mongodb-compass --",
"package-compass-nocompile": "npm run package-compass-nocompile --workspace=mongodb-compass --",
"prestart": "npm run compile --workspace=@mongodb-js/webpack-config-compass",
"prestart-web": "npm run prestart",
"start": "npm run start --workspace=mongodb-compass",
"start-web": "npm run start --workspace=@mongodb-js/compass-web",
"test": "lerna run test --concurrency 1 --stream",
Expand Down
7 changes: 5 additions & 2 deletions packages/compass-e2e-tests/.depcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ ignores:
- '@mongodb-js/prettier-config-compass'
- '@mongodb-js/tsconfig-compass'
- '@wdio/types'
- 'mongodb-compass'
- 'ps-list'
- 'mongodb-runner'
# Avoiding recursive deps on monorepo workspaces
- 'mongodb-compass'
- '@mongodb-js/mocha-config-compass'
- 'compass-e2e-tests'
- '@mongodb-js/compass-web'
# TODO(COMPASS-8312): depcheck doesn't count this dependency because it's a
# types only import and the depcheck parser is resolving the @types/<name>
# package as a dep instead
Expand Down
2 changes: 0 additions & 2 deletions packages/compass-e2e-tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
.log
fixtures/*.csv
fixtures/*.json
write-electron-versions.js
electron-versions.json
4 changes: 0 additions & 4 deletions packages/compass-e2e-tests/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@
fixtures
.nyc_output
coverage

# Generated files
electron-versions.json
write-electron-versions.js
78 changes: 16 additions & 62 deletions packages/compass-e2e-tests/helpers/commands/connect-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@ import { expect } from 'chai';
import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';
import type { ConnectFormState } from '../connect-form-state';
import {
DEFAULT_CONNECTION_NAME_1,
DEFAULT_CONNECTION_NAME_2,
DEFAULT_CONNECTION_STRING_1,
DEFAULT_CONNECTION_STRING_2,
TEST_ATLAS_CLOUD_EXTERNAL_URL,
TEST_MULTIPLE_CONNECTIONS,
} from '../compass';
import { TEST_MULTIPLE_CONNECTIONS } from '../compass';
import Debug from 'debug';
import { DEFAULT_CONNECTIONS } from '../test-runner-context';
import { getConnectionTitle } from '@mongodb-js/connection-info';
const debug = Debug('compass-e2e-tests');

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

export async function saveConnection(
browser: CompassBrowser,
state: ConnectFormState,

// TODO(COMPASS-8023): Just remove these once the single connection code is removed
favouriteName: string,
color: string
state: ConnectFormState
): Promise<void> {
await browser.setConnectFormState(state);
if (TEST_MULTIPLE_CONNECTIONS) {
await browser.clickVisible(Selectors.ConnectionModalSaveButton);
await browser
.$(Selectors.ConnectionModal)
.waitForDisplayed({ reverse: true });
} else {
await browser.clickVisible(Selectors.ConnectionEditFavouriteButton);
await browser.$(Selectors.FavoriteModal).waitForDisplayed();
await browser.setValueVisible(Selectors.FavoriteNameInput, favouriteName);
await browser.clickVisible(
`${Selectors.FavoriteColorSelector} [data-testid="color-pick-${color}"]`
);
await browser.$(Selectors.FavoriteSaveButton).waitForEnabled();
await browser.clickVisible(Selectors.FavoriteSaveButton);
await browser.$(Selectors.FavoriteModal).waitForExist({ reverse: true });
}
await browser.clickVisible(Selectors.ConnectionModalSaveButton);
await browser
.$(Selectors.ConnectionModal)
.waitForDisplayed({ reverse: true });
}

export async function setupDefaultConnections(browser: CompassBrowser) {
Expand All @@ -987,45 +966,20 @@ 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,
]) {
for (const connectionInfo of DEFAULT_CONNECTIONS) {
const connectionName = getConnectionTitle(connectionInfo);
if (await browser.removeConnection(connectionName)) {
debug('Removing existing connection so we do not create a duplicate', {
connectionName,
});
}
}

await browser.saveConnection(
{
connectionString: DEFAULT_CONNECTION_STRING_1,
// NOTE: no connectionName, we're going with the auto-generated one. Also no
// connectionColor. Passing a name and colour for single connection world,
// though, because that's the only way to create a favourite.
},
DEFAULT_CONNECTION_NAME_1,
'color1'
);

// no need for a second connection in single connection mode
if (TEST_MULTIPLE_CONNECTIONS) {
await browser.saveConnection(
{
connectionString: DEFAULT_CONNECTION_STRING_2,
// NOTE: filling in a name so that this one does _not_ have the auto-generated one
connectionName: DEFAULT_CONNECTION_NAME_2,
connectionColor: 'Iris',
},
DEFAULT_CONNECTION_NAME_2,
'color8'
);
for (const connectionInfo of DEFAULT_CONNECTIONS) {
await browser.saveConnection({
connectionString: connectionInfo.connectionOptions.connectionString,
connectionName: connectionInfo.favorite?.name,
connectionColor: connectionInfo.favorite?.color,
});
}
}
4 changes: 2 additions & 2 deletions packages/compass-e2e-tests/helpers/commands/screenshot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import type { CompassBrowser } from '../compass-browser';
import { SCREENSHOTS_PATH } from '../compass';
import { LOG_SCREENSHOTS_PATH } from '../test-runner-context';

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

const fullPath = path.join(SCREENSHOTS_PATH, filename);
const fullPath = path.join(LOG_SCREENSHOTS_PATH, filename);
try {
await withTimeout(10000, browser.saveScreenshot(fullPath));
} catch (err: any) {
Expand Down
Loading

0 comments on commit ce0d66f

Please sign in to comment.