WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit fe36ee3

Browse files
committed
chore(e2e-tests): make startTestShell regular function instead of mocha monkey-patch
1 parent d4e633c commit fe36ee3

18 files changed

+254
-245
lines changed

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/test/e2e-analytics.spec.ts

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

45
describe('e2e Analytics Node', function () {
56
const replSetName = 'replicaSet';
@@ -32,7 +33,7 @@ describe('e2e Analytics Node', function () {
3233
],
3334
};
3435

35-
const shell = this.startTestShell({
36+
const shell = startTestShell(this, {
3637
args: [await rs0.connectionString()],
3738
});
3839
await shell.waitForPrompt();
@@ -51,7 +52,7 @@ describe('e2e Analytics Node', function () {
5152

5253
context('without readPreference', function () {
5354
it('a direct connection ends up at primary', async function () {
54-
const shell = this.startTestShell({
55+
const shell = startTestShell(this, {
5556
args: [await rs0.connectionString()],
5657
});
5758
await shell.waitForPrompt();
@@ -64,13 +65,13 @@ describe('e2e Analytics Node', function () {
6465

6566
context('specifying readPreference and tags', function () {
6667
it('ends up at the ANALYTICS node', async function () {
67-
const shell = this.startTestShell({
68+
const shell = startTestShell(this, {
6869
args: [
6970
`${await rs0.connectionString()}?replicaSet=${replSetName}&readPreference=secondary&readPreferenceTags=nodeType:ANALYTICS`,
7071
],
7172
});
7273

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

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
skipIfApiStrict,
88
startSharedTestServer,
99
} 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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { skipIfApiStrict, startSharedTestServer } from '@mongosh/testing';
22
import type { TestShell } from './test-shell';
3+
import { startTestShell } from './test-shell-context';
34

45
describe('e2e startup banners', function () {
56
skipIfApiStrict();
@@ -8,7 +9,7 @@ describe('e2e startup banners', function () {
89

910
context('without special configuration', function () {
1011
it('shows startup warnings', async function () {
11-
const shell = this.startTestShell({
12+
const shell = startTestShell(this, {
1213
args: [await testServer.connectionString()],
1314
});
1415
await shell.waitForPrompt();
@@ -26,7 +27,7 @@ describe('e2e startup banners', function () {
2627
let helperShell: TestShell;
2728

2829
beforeEach(async function () {
29-
helperShell = this.startTestShell({
30+
helperShell = startTestShell(this, {
3031
args: [await testServer.connectionString()],
3132
});
3233
await helperShell.waitForPrompt();
@@ -43,7 +44,7 @@ describe('e2e startup banners', function () {
4344
});
4445

4546
it('shows automation notices', async function () {
46-
const shell = this.startTestShell({
47+
const shell = startTestShell(this, {
4748
args: [await testServer.connectionString()],
4849
});
4950
await shell.waitForPrompt();

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { MongoClient } from 'mongodb';
44
import * as bson from 'bson';
55
import type { TestShell } from './test-shell';
66
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)