Skip to content

Commit 6b001f7

Browse files
authored
chore(e2e): provide clearer names for runtime assertion methods (#7891)
* chore(e2e): provide clearer names for runtime assertion methods * chore(e2e): a better name and clearer comment
1 parent fb6038b commit 6b001f7

File tree

9 files changed

+49
-31
lines changed

9 files changed

+49
-31
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { ConnectFormState } from '../connect-form-state';
66
import Debug from 'debug';
77
import {
88
DEFAULT_CONNECTIONS,
9-
isTestingAtlasCloud,
9+
isTestingWebAtlasCloud,
1010
} from '../test-runner-context';
1111
import { getConnectionTitle } from '@mongodb-js/connection-info';
1212
const debug = Debug('compass-e2e-tests');
@@ -935,7 +935,7 @@ let screenshotCounter = 0;
935935
export async function setupDefaultConnections(browser: CompassBrowser) {
936936
// When running tests against Atlas Cloud, connections can't be added or
937937
// removed from the UI manually, so we skip setup for default connections
938-
if (isTestingAtlasCloud()) {
938+
if (isTestingWebAtlasCloud()) {
939939
return;
940940
}
941941

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Debug from 'debug';
66
import {
77
getDefaultConnectionNames,
88
getDefaultConnectionStrings,
9-
isTestingAtlasCloud,
9+
isTestingWebAtlasCloud,
1010
} from '../test-runner-context';
1111

1212
const debug = Debug('compass-e2e-tests');
@@ -52,7 +52,7 @@ export async function connectWithConnectionString(
5252
// When testing Atlas Cloud, we can't really create a new connection, so just
5353
// assume a connection name was passed (with a fallback to a default one) and
5454
// try to use it
55-
if (isTestingAtlasCloud()) {
55+
if (isTestingWebAtlasCloud()) {
5656
await browser.connectByName(
5757
connectionStringOrName ?? getDefaultConnectionNames(0)
5858
);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
isTestingDesktop,
2828
context,
2929
assertTestingWeb,
30-
isTestingAtlasCloud,
30+
isTestingWebAtlasCloud,
3131
getCloudUrlsFromContext,
3232
} from './test-runner-context';
3333
import {
@@ -807,7 +807,7 @@ export async function startBrowser(
807807
const { webdriverOptions, wdioOptions } = await processCommonOpts();
808808

809809
const browserName = context.browserName as 'chrome' | 'firefox';
810-
const redirectExtension = isTestingAtlasCloud(context)
810+
const redirectExtension = isTestingWebAtlasCloud(context)
811811
? await (async () => {
812812
return getExtension(
813813
COMPASS_WEB_ENTRYPOINT_HOST,
@@ -821,7 +821,7 @@ export async function startBrowser(
821821
prefs: {
822822
'download.default_directory': downloadPath,
823823
},
824-
args: isTestingAtlasCloud(context)
824+
args: isTestingWebAtlasCloud(context)
825825
? [
826826
// We're going to be hitting localhost from remote domain, LNA needs
827827
// to be disabled
@@ -842,7 +842,7 @@ export async function startBrowser(
842842
// Hide the download (progress) panel
843843
'browser.download.alwaysOpenPanel': false,
844844

845-
...(isTestingAtlasCloud(context) && {
845+
...(isTestingWebAtlasCloud(context) && {
846846
// Need to disable LNA (see above)
847847
'network.lna.skip-domains': '*.mongodb.com',
848848
}),
@@ -873,7 +873,7 @@ export async function startBrowser(
873873
needsCloseWelcomeModal: false,
874874
});
875875

876-
if (isTestingAtlasCloud(context)) {
876+
if (isTestingWebAtlasCloud(context)) {
877877
// In firefox extension needs to be loaded via special Gecko command and
878878
// should be provided as a base64 string with compressed extension
879879
if (browserName === 'firefox') {
@@ -1123,7 +1123,7 @@ export async function init(
11231123

11241124
const { browser } = compass;
11251125

1126-
if (isTestingAtlasCloud(context)) {
1126+
if (isTestingWebAtlasCloud(context)) {
11271127
await browser.signInToAtlas(
11281128
context.atlasCloudUsername,
11291129
context.atlasCloudPassword
@@ -1141,7 +1141,7 @@ export async function init(
11411141
if (isTestingWeb(context)) {
11421142
await opts.onBeforeNavigate?.(browser);
11431143

1144-
if (isTestingAtlasCloud(context)) {
1144+
if (isTestingWebAtlasCloud(context)) {
11451145
const urls = getCloudUrlsFromContext();
11461146
await browser.navigateTo(
11471147
`${urls.cloudUrl}/v2/${context.atlasCloudProjectId}#/explorer`

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,16 @@ if (context.browserVersion === undefined) {
276276
context.browserName === 'firefox' ? 'latest' : 'stable';
277277
}
278278

279+
/**
280+
* Returns true if the tests are running against Compass desktop
281+
*/
279282
export function isTestingDesktop(ctx = context): ctx is DesktopParsedArgs {
280283
return testEnv === 'desktop';
281284
}
282285

286+
/**
287+
* Returns if tests are running against Compass desktop. Throws otherwise
288+
*/
283289
export function assertTestingDesktop(
284290
ctx = context
285291
): asserts ctx is DesktopParsedArgs {
@@ -290,10 +296,16 @@ export function assertTestingDesktop(
290296
}
291297
}
292298

299+
/**
300+
* Returns true if tests are running against compass-web in either local sandbox or integrated in Atlas Cloud
301+
*/
293302
export function isTestingWeb(ctx = context): ctx is WebParsedArgs {
294303
return testEnv === 'web';
295304
}
296305

306+
/**
307+
* Returns if tests are running against compass-web in either local sandbox or integrated in Atlas Cloud. Throws otherwise
308+
*/
297309
export function assertTestingWeb(ctx = context): asserts ctx is WebParsedArgs {
298310
if (!isTestingWeb(ctx)) {
299311
throw new Error(
@@ -302,16 +314,22 @@ export function assertTestingWeb(ctx = context): asserts ctx is WebParsedArgs {
302314
}
303315
}
304316

305-
export function isTestingAtlasCloud(
317+
/**
318+
* Returns true if tests are running against compass-web in cloud-<env>.mongodb.com
319+
*/
320+
export function isTestingWebAtlasCloud(
306321
ctx = context
307322
): ctx is AtlasCloudParsedArgs {
308323
return isTestingWeb(ctx) && !!ctx.testAtlasCloud;
309324
}
310325

311-
export function assertTestingAtlasCloud(
326+
/**
327+
* Returns if tests are running against compass-web in cloud-<env>.mongodb.com. Throws otherwise
328+
*/
329+
export function assertTestingWebAtlasCloud(
312330
ctx = context
313331
): asserts ctx is WebParsedArgs & AtlasCloudParsedArgs {
314-
if (!isTestingAtlasCloud(ctx)) {
332+
if (!isTestingWebAtlasCloud(ctx)) {
315333
throw new Error(`Expected tested runtime to be web w/ Atlas Cloud account`);
316334
}
317335
}
@@ -342,7 +360,7 @@ type TestConnectionInfo = ConnectionInfo & {
342360
testServer?: Partial<MongoClusterOptions>;
343361
};
344362

345-
export const DEFAULT_CONNECTIONS: TestConnectionInfo[] = isTestingAtlasCloud(
363+
export const DEFAULT_CONNECTIONS: TestConnectionInfo[] = isTestingWebAtlasCloud(
346364
context
347365
)
348366
? []
@@ -437,7 +455,7 @@ const CLOUD_URLS = {
437455
} as const;
438456

439457
export function getCloudUrlsFromContext(ctx = context) {
440-
assertTestingAtlasCloud(ctx);
458+
assertTestingWebAtlasCloud(ctx);
441459
return CLOUD_URLS[context.atlasCloudEnvironment as keyof typeof CLOUD_URLS];
442460
}
443461

@@ -459,7 +477,7 @@ export const ATLAS_CLOUD_TEST_UTILS: {
459477
: 'null'
460478
);
461479

462-
if (isTestingAtlasCloud() && !ATLAS_CLOUD_TEST_UTILS) {
480+
if (isTestingWebAtlasCloud() && !ATLAS_CLOUD_TEST_UTILS) {
463481
throw new Error(
464482
'Trying to test Atlas Cloud environment, but test utils config is not provided. Make sure that ATLAS_CLOUD_TEST_UTILS env variable is available'
465483
);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import gunzip from './gunzip';
22
import fs from 'fs';
33
import {
4-
assertTestingAtlasCloud,
4+
assertTestingWebAtlasCloud,
55
ATLAS_CLOUD_TEST_UTILS,
66
context,
77
DEFAULT_CONNECTIONS,
88
DEFAULT_CONNECTIONS_SERVER_INFO,
99
getCloudUrlsFromContext,
10-
isTestingAtlasCloud,
10+
isTestingWebAtlasCloud,
1111
isTestingDesktop,
1212
isTestingWeb,
1313
RUN_ID,
@@ -81,7 +81,7 @@ export function allowServerWarnings(...filters: WarningFilter[]): () => void {
8181
}
8282

8383
async function createAtlasCloudResources() {
84-
assertTestingAtlasCloud(context);
84+
assertTestingWebAtlasCloud(context);
8585

8686
debug('Creating Atlas Cloud resources...');
8787

@@ -305,7 +305,7 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {
305305
throwIfAborted();
306306
}
307307

308-
if (isTestingAtlasCloud(context)) {
308+
if (isTestingWebAtlasCloud(context)) {
309309
// Both tasks can take a decent amount of time and are not overlapping
310310
// with each other, so we can run them in parallel
311311
await Promise.all([

packages/compass-e2e-tests/tests/atlas-cloud/collection-ai-query.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import {
1010
import type { Compass } from '../../helpers/compass';
1111
import * as Selectors from '../../helpers/selectors';
1212
import { createNumbersCollection } from '../../helpers/mongo-clients';
13-
import { isTestingAtlasCloud } from '../../helpers/test-runner-context';
13+
import { isTestingWebAtlasCloud } from '../../helpers/test-runner-context';
1414
import { switchPipelineMode } from '../../helpers/commands/switch-pipeline-mode';
1515

1616
describe('Collection ai query (with real Cloud backend)', function () {
1717
let compass: Compass;
1818
let browser: CompassBrowser;
1919

2020
before(function () {
21-
if (!isTestingAtlasCloud()) {
21+
if (!isTestingWebAtlasCloud()) {
2222
this.skip();
2323
}
2424
});

packages/compass-e2e-tests/tests/atlas-cloud/error-states.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import type { Compass } from '../../helpers/compass';
22
import { cleanup, init, screenshotIfFailed } from '../../helpers/compass';
33
import {
44
context,
5-
assertTestingAtlasCloud,
6-
isTestingAtlasCloud,
5+
assertTestingWebAtlasCloud,
6+
isTestingWebAtlasCloud,
77
} from '../../helpers/test-runner-context';
88

99
describe('Error states', function () {
1010
let compass: Compass;
1111

1212
before(function () {
13-
if (!isTestingAtlasCloud()) {
13+
if (!isTestingWebAtlasCloud()) {
1414
this.skip();
1515
}
1616
});
@@ -23,7 +23,7 @@ describe('Error states', function () {
2323
it('should show error state if fetching connection info failed initially', async function () {
2424
compass = await init(this.test?.fullTitle(), {
2525
async onBeforeNavigate(browser) {
26-
assertTestingAtlasCloud(context);
26+
assertTestingWebAtlasCloud(context);
2727
const mock = await browser.mock(
2828
`/explorer/v1/groups/${context.atlasCloudProjectId}/clusters/connectionInfo`
2929
);

packages/compass-e2e-tests/tests/atlas-cloud/global-writes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { CompassBrowser } from '../../helpers/compass-browser';
1010
import { createGeospatialCollection } from '../../helpers/mongo-clients';
1111
import {
1212
getDefaultConnectionNames,
13-
isTestingAtlasCloud,
13+
isTestingWebAtlasCloud,
1414
} from '../../helpers/test-runner-context';
1515

1616
type GeoShardingFormData = {
@@ -74,7 +74,7 @@ describe('Global writes', function () {
7474
let browser: CompassBrowser;
7575

7676
before(function () {
77-
if (!isTestingAtlasCloud()) {
77+
if (!isTestingWebAtlasCloud()) {
7878
this.skip();
7979
}
8080
});

packages/compass-e2e-tests/tests/atlas-cloud/rolling-indexes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import type { CompassBrowser } from '../../helpers/compass-browser';
99
import { createNumbersCollection } from '../../helpers/mongo-clients';
1010
import {
1111
getDefaultConnectionNames,
12-
isTestingAtlasCloud,
12+
isTestingWebAtlasCloud,
1313
} from '../../helpers/test-runner-context';
1414

1515
describe('Rolling indexes', function () {
1616
let compass: Compass;
1717
let browser: CompassBrowser;
1818

1919
before(function () {
20-
if (!isTestingAtlasCloud()) {
20+
if (!isTestingWebAtlasCloud()) {
2121
this.skip();
2222
}
2323
});

0 commit comments

Comments
 (0)