Skip to content

Commit 99d5227

Browse files
authored
chore(e2e-tests): import from @mongosh/testing (#2615)
* chore(e2e-tests): import from `@mongosh/testing` * chore(testing): prevent accidentally starting shared test setup without installed cleanup hook * chore(e2e-tests): make startTestShell regular function instead of mocha monkey-patch
1 parent bc50511 commit 99d5227

23 files changed

+302
-293
lines changed

package-lock.json

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

packages/e2e-tests/.mocharc.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
{
2-
"require": [
3-
"ts-node/register",
4-
"../../scripts/import-expansions.js",
5-
"./test/test-shell-context.ts"
6-
],
2+
"require": ["ts-node/register", "../../scripts/import-expansions.js"],
73
"timeout": 15000,
84
"reporter": "../../configs/mocha-config-mongosh/reporter.ts",
95
"spec": ["./test/*.spec.ts"],

packages/e2e-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@mongodb-js/oidc-mock-provider": "^0.11.3",
3232
"@mongodb-js/prettier-config-devtools": "^1.0.1",
3333
"@mongodb-js/tsconfig-mongosh": "^1.0.0",
34+
"@mongosh/testing": "0.0.0-dev.0",
3435
"@types/chai-as-promised": "^8.0.2",
3536
"@types/node": "^22.15.30",
3637
"@types/rimraf": "^3.0.0",

packages/e2e-tests/test/e2e-analytics.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
2-
import { startTestCluster } from '../../testing/src/integration-testing-hooks';
3-
import { eventually } from '../../testing/src/eventually';
2+
import { startTestCluster, eventually } from '@mongosh/testing';
3+
import { startTestShell } from './test-shell-context';
44

55
describe('e2e Analytics Node', function () {
66
const replSetName = 'replicaSet';
@@ -33,7 +33,7 @@ describe('e2e Analytics Node', function () {
3333
],
3434
};
3535

36-
const shell = this.startTestShell({
36+
const shell = startTestShell(this, {
3737
args: [await rs0.connectionString()],
3838
});
3939
await shell.waitForPrompt();
@@ -52,7 +52,7 @@ describe('e2e Analytics Node', function () {
5252

5353
context('without readPreference', function () {
5454
it('a direct connection ends up at primary', async function () {
55-
const shell = this.startTestShell({
55+
const shell = startTestShell(this, {
5656
args: [await rs0.connectionString()],
5757
});
5858
await shell.waitForPrompt();
@@ -65,13 +65,13 @@ describe('e2e Analytics Node', function () {
6565

6666
context('specifying readPreference and tags', function () {
6767
it('ends up at the ANALYTICS node', async function () {
68-
const shell = this.startTestShell({
68+
const shell = startTestShell(this, {
6969
args: [
7070
`${await rs0.connectionString()}?replicaSet=${replSetName}&readPreference=secondary&readPreferenceTags=nodeType:ANALYTICS`,
7171
],
7272
});
7373

74-
const directConnectionToAnalyticsShell = this.startTestShell({
74+
const directConnectionToAnalyticsShell = startTestShell(this, {
7575
args: [`${await rs3.connectionString()}?directConnection=true`],
7676
});
7777
await Promise.all([

packages/e2e-tests/test/e2e-auth.spec.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { expect } from 'chai';
22
import type { Db, Document, MongoClientOptions } from 'mongodb';
33
import { MongoClient } from 'mongodb';
4-
import { eventually } from '../../testing/src/eventually';
54
import type { TestShell } from './test-shell';
65
import {
6+
eventually,
77
skipIfApiStrict,
88
startSharedTestServer,
9-
} from '../../testing/src/integration-testing-hooks';
9+
} from '@mongosh/testing';
10+
import { startTestShell } from './test-shell-context';
1011

1112
type AssertUserExists = (opts?: Document, username?: string) => Promise<void>;
1213
function createAssertUserExists(db: Db, dbName: string): AssertUserExists {
@@ -110,7 +111,7 @@ describe('Auth e2e', function () {
110111
beforeEach(async function () {
111112
const connectionString = await testServer.connectionString();
112113
dbName = `test-${Date.now()}`;
113-
shell = this.startTestShell({ args: [connectionString] });
114+
shell = startTestShell(this, { args: [connectionString] });
114115

115116
client = await MongoClient.connect(connectionString, {});
116117

@@ -878,7 +879,7 @@ describe('Auth e2e', function () {
878879
pathname: `/${dbName}`,
879880
}
880881
);
881-
shell = this.startTestShell({ args: [authConnectionString] });
882+
shell = startTestShell(this, { args: [authConnectionString] });
882883
await shell.waitForPrompt();
883884
shell.assertNoErrors();
884885
await shell.executeLine(`use ${dbName}`);
@@ -902,7 +903,7 @@ describe('Auth e2e', function () {
902903
pathname: `/${dbName}`,
903904
}
904905
);
905-
shell = this.startTestShell({ args: [authConnectionString] });
906+
shell = startTestShell(this, { args: [authConnectionString] });
906907
await shell.waitForPrompt();
907908
shell.assertNoErrors();
908909
await shell.executeLine(`use ${dbName}`);
@@ -929,7 +930,7 @@ describe('Auth e2e', function () {
929930
});
930931
it('can auth when there is -u and -p', async function () {
931932
const connectionString = await testServer.connectionString();
932-
shell = this.startTestShell({
933+
shell = startTestShell(this, {
933934
args: [
934935
connectionString,
935936
'-u',
@@ -964,7 +965,7 @@ describe('Auth e2e', function () {
964965
return this.skip(); // No SCRAM-SHA-1 in FIPS mode
965966
}
966967
const connectionString = await testServer.connectionString();
967-
shell = this.startTestShell({
968+
shell = startTestShell(this, {
968969
args: [
969970
connectionString,
970971
'-u',
@@ -988,7 +989,7 @@ describe('Auth e2e', function () {
988989
// This test is not particularly meaningful if we're using the system OpenSSL installation
989990
// and it is not properly configured for FIPS to begin with. This is the case on e.g.
990991
// Ubuntu 22.04 in evergreen CI.
991-
const preTestShell = this.startTestShell({
992+
const preTestShell = startTestShell(this, {
992993
args: [
993994
'--quiet',
994995
'--nodb',
@@ -1008,7 +1009,7 @@ describe('Auth e2e', function () {
10081009
}
10091010

10101011
const connectionString = await testServer.connectionString();
1011-
shell = this.startTestShell({
1012+
shell = startTestShell(this, {
10121013
args: [
10131014
connectionString,
10141015
'--tlsFIPSMode',
@@ -1033,7 +1034,7 @@ describe('Auth e2e', function () {
10331034
});
10341035
it('can auth with SCRAM-SHA-256', async function () {
10351036
const connectionString = await testServer.connectionString();
1036-
shell = this.startTestShell({
1037+
shell = startTestShell(this, {
10371038
args: [
10381039
connectionString,
10391040
'-u',
@@ -1054,7 +1055,7 @@ describe('Auth e2e', function () {
10541055
});
10551056
it('cannot auth when authenticationMechanism mismatches (sha256 -> sha1)', async function () {
10561057
const connectionString = await testServer.connectionString();
1057-
shell = this.startTestShell({
1058+
shell = startTestShell(this, {
10581059
args: [
10591060
connectionString,
10601061
'-u',
@@ -1075,7 +1076,7 @@ describe('Auth e2e', function () {
10751076
});
10761077
it('cannot auth when authenticationMechanism mismatches (sha1 -> sha256)', async function () {
10771078
const connectionString = await testServer.connectionString();
1078-
shell = this.startTestShell({
1079+
shell = startTestShell(this, {
10791080
args: [
10801081
connectionString,
10811082
'-u',
@@ -1096,7 +1097,7 @@ describe('Auth e2e', function () {
10961097
});
10971098
it('does not fail with kerberos not found for GSSAPI', async function () {
10981099
const connectionString = await testServer.connectionString();
1099-
shell = this.startTestShell({
1100+
shell = startTestShell(this, {
11001101
args: [
11011102
connectionString,
11021103
'-u',

packages/e2e-tests/test/e2e-aws.spec.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from 'chai';
22
import { spawnSync } from 'child_process';
3+
import { startTestShell } from './test-shell-context';
34

45
function assertEnvVariable(variableName: string): string {
56
if (process.env.MONGOSH_TEST_FORCE_API_STRICT) {
@@ -123,7 +124,7 @@ describe('e2e AWS AUTH', function () {
123124
context('without environment variables being present', function () {
124125
context('specifying explicit parameters', function () {
125126
it('connects with access key and secret', async function () {
126-
const shell = this.startTestShell({
127+
const shell = startTestShell(this, {
127128
args: [
128129
getConnectionString(),
129130
'--username',
@@ -145,7 +146,7 @@ describe('e2e AWS AUTH', function () {
145146

146147
it('connects with access key, secret, and session token for IAM role', async function () {
147148
const tokenDetails = generateIamSessionToken();
148-
const shell = this.startTestShell({
149+
const shell = startTestShell(this, {
149150
args: [
150151
getConnectionString(),
151152
'--username',
@@ -170,7 +171,7 @@ describe('e2e AWS AUTH', function () {
170171

171172
context('specifying connection string parameters', function () {
172173
it('connects with access key and secret', async function () {
173-
const shell = this.startTestShell({
174+
const shell = startTestShell(this, {
174175
args: [getConnectionString(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)],
175176
});
176177
const result = await shell.waitForPromptOrExit(
@@ -186,7 +187,7 @@ describe('e2e AWS AUTH', function () {
186187

187188
it('connects with access key, secret, and session token for IAM role', async function () {
188189
const tokenDetails = generateIamSessionToken();
189-
const shell = this.startTestShell({
190+
const shell = startTestShell(this, {
190191
args: [
191192
`${getConnectionString(
192193
tokenDetails.key,
@@ -212,7 +213,7 @@ describe('e2e AWS AUTH', function () {
212213
context('with AWS environment variables', function () {
213214
context('without any other parameters', function () {
214215
it('connects for the IAM user', async function () {
215-
const shell = this.startTestShell({
216+
const shell = startTestShell(this, {
216217
args: [getConnectionString()],
217218
env: {
218219
...process.env,
@@ -233,7 +234,7 @@ describe('e2e AWS AUTH', function () {
233234

234235
it('connects for the IAM role session', async function () {
235236
const tokenDetails = generateIamSessionToken();
236-
const shell = this.startTestShell({
237+
const shell = startTestShell(this, {
237238
args: [getConnectionString()],
238239
env: {
239240
...process.env,
@@ -256,7 +257,7 @@ describe('e2e AWS AUTH', function () {
256257

257258
context('with invalid environment but valid parameters', function () {
258259
it('connects for the IAM user', async function () {
259-
const shell = this.startTestShell({
260+
const shell = startTestShell(this, {
260261
args: [
261262
getConnectionString(),
262263
'--username',
@@ -283,7 +284,7 @@ describe('e2e AWS AUTH', function () {
283284

284285
it('connects for the IAM role session', async function () {
285286
const tokenDetails = generateIamSessionToken();
286-
const shell = this.startTestShell({
287+
const shell = startTestShell(this, {
287288
args: [
288289
getConnectionString(),
289290
'--username',

packages/e2e-tests/test/e2e-banners.spec.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import {
2-
skipIfApiStrict,
3-
startSharedTestServer,
4-
} from '../../testing/src/integration-testing-hooks';
1+
import { skipIfApiStrict, startSharedTestServer } from '@mongosh/testing';
52
import type { TestShell } from './test-shell';
3+
import { startTestShell } from './test-shell-context';
64

75
describe('e2e startup banners', function () {
86
skipIfApiStrict();
@@ -11,7 +9,7 @@ describe('e2e startup banners', function () {
119

1210
context('without special configuration', function () {
1311
it('shows startup warnings', async function () {
14-
const shell = this.startTestShell({
12+
const shell = startTestShell(this, {
1513
args: [await testServer.connectionString()],
1614
});
1715
await shell.waitForPrompt();
@@ -29,7 +27,7 @@ describe('e2e startup banners', function () {
2927
let helperShell: TestShell;
3028

3129
beforeEach(async function () {
32-
helperShell = this.startTestShell({
30+
helperShell = startTestShell(this, {
3331
args: [await testServer.connectionString()],
3432
});
3533
await helperShell.waitForPrompt();
@@ -46,7 +44,7 @@ describe('e2e startup banners', function () {
4644
});
4745

4846
it('shows automation notices', async function () {
49-
const shell = this.startTestShell({
47+
const shell = startTestShell(this, {
5048
args: [await testServer.connectionString()],
5149
});
5250
await shell.waitForPrompt();

packages/e2e-tests/test/e2e-bson.spec.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import type { Db } from 'mongodb';
33
import { MongoClient } from 'mongodb';
44
import * as bson from 'bson';
55
import type { TestShell } from './test-shell';
6-
import { startSharedTestServer } from '../../testing/src/integration-testing-hooks';
6+
import { startSharedTestServer } from '@mongosh/testing';
7+
import { startTestShell } from './test-shell-context';
78

89
describe('BSON e2e', function () {
910
const testServer = startSharedTestServer();
@@ -15,7 +16,7 @@ describe('BSON e2e', function () {
1516
beforeEach(async function () {
1617
const connectionString = await testServer.connectionString();
1718
dbName = `test-${Date.now()}`;
18-
shell = this.startTestShell({ args: [connectionString] });
19+
shell = startTestShell(this, { args: [connectionString] });
1920

2021
client = await MongoClient.connect(connectionString, {});
2122

@@ -674,7 +675,7 @@ describe('BSON e2e', function () {
674675

675676
it('can explicitly disable full-depth nesting (interactive mode)', async function () {
676677
shell.kill();
677-
shell = this.startTestShell({
678+
shell = startTestShell(this, {
678679
args: [await testServer.connectionString(), '--deepInspect=false'],
679680
});
680681
await shell.waitForPrompt();
@@ -686,15 +687,15 @@ describe('BSON e2e', function () {
686687

687688
it('does not deeply inspect objects in non-interactive mode for intermediate output', async function () {
688689
shell.kill();
689-
shell = this.startTestShell({
690+
shell = startTestShell(this, {
690691
args: [
691692
await testServer.connectionString(),
692693
'--eval',
693694
`use(${JSON.stringify(dbName)}); print(db.coll.findOne()); 0`,
694695
],
695696
});
696697
checkForDeepOutput(await shell.waitForCleanOutput(), false);
697-
shell = this.startTestShell({
698+
shell = startTestShell(this, {
698699
args: [
699700
await testServer.connectionString(),
700701
'--eval',
@@ -706,15 +707,15 @@ describe('BSON e2e', function () {
706707

707708
it('inspect full objects in non-interactive mode for final output', async function () {
708709
shell.kill();
709-
shell = this.startTestShell({
710+
shell = startTestShell(this, {
710711
args: [
711712
await testServer.connectionString(),
712713
'--eval',
713714
`use(${JSON.stringify(dbName)}); db.coll.findOne();`,
714715
],
715716
});
716717
checkForDeepOutput(await shell.waitForCleanOutput(), true);
717-
shell = this.startTestShell({
718+
shell = startTestShell(this, {
718719
args: [
719720
await testServer.connectionString(),
720721
'--eval',
@@ -726,7 +727,7 @@ describe('BSON e2e', function () {
726727

727728
it('can explicitly disable full-depth nesting (non-interactive mode)', async function () {
728729
shell.kill();
729-
shell = this.startTestShell({
730+
shell = startTestShell(this, {
730731
args: [
731732
await testServer.connectionString(),
732733
'--deepInspect=false',
@@ -735,7 +736,7 @@ describe('BSON e2e', function () {
735736
],
736737
});
737738
checkForDeepOutput(await shell.waitForCleanOutput(), false);
738-
shell = this.startTestShell({
739+
shell = startTestShell(this, {
739740
args: [
740741
await testServer.connectionString(),
741742
'--deepInspect=false',

0 commit comments

Comments
 (0)