Skip to content

Commit 9ea42cf

Browse files
addaleaxgagik
andauthored
fix(e2e-tests): make version test independent of package.json files (#2343)
`--version`, `version()` and `--build-info` all source their version information differently. It should be sufficient to include a test to verify that they all match, without having to rely on the specific dependency from the e2e-test package.json file (which is in line with the general idea that e2e tests should not actually depend on the specific shell implementation and only test externally visible behavior of that implementation). Co-authored-by: Gagik Amaryan <[email protected]>
1 parent 6be1b90 commit 9ea42cf

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,26 @@ describe('e2e', function () {
3333
const testServer = startSharedTestServer();
3434

3535
describe('--version', function () {
36-
it('shows version and matches @mongosh/cli-repl', async function () {
37-
const expectedPackageVersion: string =
38-
// eslint-disable-next-line @typescript-eslint/no-var-requires
39-
require('../package.json')['dependencies']['@mongosh/cli-repl'];
36+
it('gives the same result with version(), --version and --build-info', async function () {
37+
// version() sources its version data from the shell-api package's generated files,
38+
// --version from the cli-repl package.json and --build-info from the generated build-info.json
39+
// (if available), which should all match.
40+
const shell = this.startTestShell({ args: ['--nodb'] });
41+
await shell.waitForPrompt();
42+
const versionFromShellApi = (await shell.executeLine('version()'))
43+
.replace(/>/g, '')
44+
.trim();
4045

41-
const shell = this.startTestShell({ args: ['--version'] });
42-
await shell.waitForSuccessfulExit();
46+
const versionShell = this.startTestShell({ args: ['--version'] });
47+
await versionShell.waitForSuccessfulExit();
48+
const versionFromCliFlag = versionShell.output.trim();
4349

44-
shell.assertContainsOutput(expectedPackageVersion);
50+
const buildInfoShell = this.startTestShell({ args: ['--build-info'] });
51+
await buildInfoShell.waitForSuccessfulExit();
52+
const versionFromBuildInfo = JSON.parse(buildInfoShell.output).version;
53+
54+
expect(versionFromShellApi).to.equal(versionFromCliFlag);
55+
expect(versionFromCliFlag).to.equal(versionFromBuildInfo);
4556
});
4657
});
4758

@@ -479,24 +490,6 @@ describe('e2e', function () {
479490
await client.close();
480491
});
481492

482-
it('version', async function () {
483-
const expectedPackageVersion: string =
484-
// eslint-disable-next-line @typescript-eslint/no-var-requires
485-
require('../package.json')['dependencies']['@mongosh/cli-repl'];
486-
487-
expect(expectedPackageVersion).not.null;
488-
489-
const versionShell = this.startTestShell({ args: ['--version'] });
490-
await versionShell.waitForSuccessfulExit();
491-
492-
const versionFromShell = versionShell.output;
493-
494-
await shell.executeLine('version()');
495-
shell.assertNoErrors();
496-
shell.assertContainsOutput(expectedPackageVersion);
497-
shell.assertContainsOutput(versionFromShell);
498-
});
499-
500493
it('fle addon is available', async function () {
501494
const result = await shell.executeLine(
502495
'`<${typeof db._mongo._serviceProvider.createClientEncryption}>`'

0 commit comments

Comments
 (0)