Skip to content

Commit 96bb074

Browse files
committed
fix(e2e-tests): make version test independent of package.json files
`--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).
1 parent 6be1b90 commit 96bb074

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

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

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,25 @@ 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+
const versionFromShellApi = (await shell.executeLine('version()'))
42+
.replace(/>/g, '')
43+
.trim();
4044

41-
const shell = this.startTestShell({ args: ['--version'] });
42-
await shell.waitForSuccessfulExit();
45+
const versionShell = this.startTestShell({ args: ['--version'] });
46+
await versionShell.waitForSuccessfulExit();
47+
const versionFromCliFlag = versionShell.output.trim();
48+
49+
const buildInfoShell = this.startTestShell({ args: ['--build-info'] });
50+
await buildInfoShell.waitForSuccessfulExit();
51+
const versionFromBuildInfo = JSON.parse(buildInfoShell.output).version;
4352

44-
shell.assertContainsOutput(expectedPackageVersion);
53+
expect(versionFromShellApi).to.equal(versionFromCliFlag);
54+
expect(versionFromCliFlag).to.equal(versionFromBuildInfo);
4555
});
4656
});
4757

@@ -479,24 +489,6 @@ describe('e2e', function () {
479489
await client.close();
480490
});
481491

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-
500492
it('fle addon is available', async function () {
501493
const result = await shell.executeLine(
502494
'`<${typeof db._mongo._serviceProvider.createClientEncryption}>`'

0 commit comments

Comments
 (0)