From 4fdc3509c942501fdad204b33ece9de7e7458cdf Mon Sep 17 00:00:00 2001 From: mcasimir Date: Tue, 30 Jun 2020 21:40:53 +0200 Subject: [PATCH 1/6] test on compiled binaries --- .evergreen.yml | 5 +++++ packages/cli-repl/test/test-shell.ts | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.evergreen.yml b/.evergreen.yml index 930b8886fb..1fd62372fa 100644 --- a/.evergreen.yml +++ b/.evergreen.yml @@ -94,6 +94,9 @@ functions: set -e source .evergreen/.setup_env export EVERGREEN_EXPANSIONS_PATH="$(pwd)/../tmp/expansions.yaml" + export MONGOSH_TEST_EXECUTABLE_PATH="$(pwd)/dist/mongosh" + echo "$MONGOSH_TEST_EXECUTABLE_PATH" + npm run compile-exec npm run test-ci test_ps: - command: expansions.write @@ -106,6 +109,8 @@ functions: shell: powershell script: | .\.evergreen\SetupEnv + $Env:MONGOSH_TEST_EXECUTABLE_PATH = $(Join-Path -Path '.' -ChildPath 'dist/mongosh.exe' -Resolve) + echo "$Env:MONGOSH_TEST_EXECUTABLE_PATH" $Env:EVERGREEN_EXPANSIONS_PATH = $(Join-Path -Path '..' -ChildPath 'tmp/expansions.yaml' -Resolve) npm run test-ci release_macos: diff --git a/packages/cli-repl/test/test-shell.ts b/packages/cli-repl/test/test-shell.ts index 389c54af07..44a2ca7a59 100644 --- a/packages/cli-repl/test/test-shell.ts +++ b/packages/cli-repl/test/test-shell.ts @@ -16,14 +16,18 @@ const ERROR_PATTERN = /Thrown:\n([^>]*)/m; export class TestShell { private static _openShells: TestShell[] = []; - static start(options: { args: string[] } = { args: [] }): TestShell { - const execPath = path.resolve(__dirname, '..', 'bin', 'mongosh.js'); - - const process = spawn('node', [execPath, ...options.args], { + static start(options: { + args: string[]; + executablePath?: string; + } = { args: [] }): TestShell { + const execPath = process.env.MONGOSH_TEST_EXECUTABLE_PATH || + path.resolve(__dirname, '..', 'bin', 'mongosh.js'); + + const shellProcess = spawn('node', [execPath, ...options.args], { stdio: [ 'pipe', 'pipe', 'pipe' ] }); - const shell = new TestShell(process); + const shell = new TestShell(shellProcess); TestShell._openShells.push(shell); return shell; From 9eb9eb24fb43b5f6b324f77048aa341bb3421834 Mon Sep 17 00:00:00 2001 From: mcasimir Date: Wed, 1 Jul 2020 15:07:11 +0200 Subject: [PATCH 2/6] fix: e2e test running on binary in everygreen --- packages/cli-repl/test/test-shell.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/cli-repl/test/test-shell.ts b/packages/cli-repl/test/test-shell.ts index 44a2ca7a59..56c3ab4b2c 100644 --- a/packages/cli-repl/test/test-shell.ts +++ b/packages/cli-repl/test/test-shell.ts @@ -20,12 +20,17 @@ export class TestShell { args: string[]; executablePath?: string; } = { args: [] }): TestShell { - const execPath = process.env.MONGOSH_TEST_EXECUTABLE_PATH || - path.resolve(__dirname, '..', 'bin', 'mongosh.js'); + let shellProcess: ChildProcess; - const shellProcess = spawn('node', [execPath, ...options.args], { - stdio: [ 'pipe', 'pipe', 'pipe' ] - }); + if (process.env.MONGOSH_TEST_EXECUTABLE_PATH) { + shellProcess = spawn(process.env.MONGOSH_TEST_EXECUTABLE_PATH, [...options.args], { + stdio: [ 'pipe', 'pipe', 'pipe' ] + }); + } else { + shellProcess = spawn('node', [path.resolve(__dirname, '..', 'bin', 'mongosh.js'), ...options.args], { + stdio: [ 'pipe', 'pipe', 'pipe' ] + }); + } const shell = new TestShell(shellProcess); TestShell._openShells.push(shell); From f80d2be96dad5e86da134fc90b3b28e28f996369 Mon Sep 17 00:00:00 2001 From: mcasimir Date: Wed, 1 Jul 2020 15:29:10 +0200 Subject: [PATCH 3/6] Remove unused option --- packages/cli-repl/test/test-shell.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cli-repl/test/test-shell.ts b/packages/cli-repl/test/test-shell.ts index 56c3ab4b2c..897f57839b 100644 --- a/packages/cli-repl/test/test-shell.ts +++ b/packages/cli-repl/test/test-shell.ts @@ -18,7 +18,6 @@ export class TestShell { static start(options: { args: string[]; - executablePath?: string; } = { args: [] }): TestShell { let shellProcess: ChildProcess; From 4c6b2e7439de2333ec6b85afad115f966a11ec71 Mon Sep 17 00:00:00 2001 From: mcasimir Date: Thu, 2 Jul 2020 08:52:45 +0200 Subject: [PATCH 4/6] e2e tests support for node >= 12.16 --- packages/cli-repl/test/test-shell.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli-repl/test/test-shell.ts b/packages/cli-repl/test/test-shell.ts index 897f57839b..7976507965 100644 --- a/packages/cli-repl/test/test-shell.ts +++ b/packages/cli-repl/test/test-shell.ts @@ -8,7 +8,7 @@ import stripAnsi from 'strip-ansi'; import assert from 'assert'; const PROMPT_PATTERN = /^> /m; -const ERROR_PATTERN = /Thrown:\n([^>]*)/m; +const ERROR_PATTERN = /(Thrown|Uncaught):\n([^>]*)/m; /** * Test shell helper class. From a2469c668f6c109e9e316b5e9cecddb86bc2e48f Mon Sep 17 00:00:00 2001 From: mcasimir Date: Thu, 2 Jul 2020 09:25:04 +0200 Subject: [PATCH 5/6] fix error pattern for e2e --- packages/cli-repl/test/helpers.ts | 2 +- packages/cli-repl/test/test-shell.ts | 11 +++++++++-- testing/integration-testing-hooks.ts | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/cli-repl/test/helpers.ts b/packages/cli-repl/test/helpers.ts index cd9f27015a..1a864cb9f7 100644 --- a/packages/cli-repl/test/helpers.ts +++ b/packages/cli-repl/test/helpers.ts @@ -1,7 +1,7 @@ export async function eventually(fn: Function, options: { frequency?: number; timeout?: number } = {}): Promise { options = { frequency: 100, - timeout: 10000, + timeout: process.env.IS_CI ? 10000 : 1000, ...options }; diff --git a/packages/cli-repl/test/test-shell.ts b/packages/cli-repl/test/test-shell.ts index 7976507965..3ad66538bd 100644 --- a/packages/cli-repl/test/test-shell.ts +++ b/packages/cli-repl/test/test-shell.ts @@ -8,7 +8,8 @@ import stripAnsi from 'strip-ansi'; import assert from 'assert'; const PROMPT_PATTERN = /^> /m; -const ERROR_PATTERN = /(Thrown|Uncaught):\n([^>]*)/m; +const ERROR_PATTERN_1 = /Thrown:\n([^>]*)/m; // node <= 12.14 +const ERROR_PATTERN_2 = /Uncaught[:\n ]+([^>]*)/m; /** * Test shell helper class. @@ -125,6 +126,8 @@ export class TestShell { assertContainsError(expectedError: string): void { const allErrors = this._getAllErrors(); + console.log(allErrors); + if (!allErrors.find((error) => error.includes(expectedError))) { throw new assert.AssertionError({ message: `Expected shell errors to include ${JSON.stringify(expectedError)}`, @@ -140,7 +143,11 @@ export class TestShell { } private _getAllErrors(): string[] { - return [...(this._output as any).matchAll(ERROR_PATTERN)] + const output = (this._output as any); + return [ + ...output.matchAll(ERROR_PATTERN_1), + ...output.matchAll(ERROR_PATTERN_2) + ] .map(m => m[1].trim()); } } diff --git a/testing/integration-testing-hooks.ts b/testing/integration-testing-hooks.ts index ac44c06763..ce199e4c6f 100644 --- a/testing/integration-testing-hooks.ts +++ b/testing/integration-testing-hooks.ts @@ -1,7 +1,7 @@ const mongodbRunnerBefore = require('mongodb-runner/mocha/before'); const mongodbRunnerAfter = require('mongodb-runner/mocha/after'); -export const LOCAL_INSTANCE_PORT = 27018; +export const LOCAL_INSTANCE_PORT = 27028; export const LOCAL_INSTANCE_HOST = 'localhost'; /** From c2a8962e16b9eb4290d93a01c3a6a5874a6886c7 Mon Sep 17 00:00:00 2001 From: mcasimir Date: Thu, 2 Jul 2020 13:25:02 +0200 Subject: [PATCH 6/6] test(e2e): add waitForExit and fix --version --- packages/cli-repl/test/e2e.spec.ts | 12 ++++++------ packages/cli-repl/test/test-shell.ts | 13 +++++++++++-- testing/integration-testing-hooks.ts | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/cli-repl/test/e2e.spec.ts b/packages/cli-repl/test/e2e.spec.ts index cd3adda6f8..a294f199b7 100644 --- a/packages/cli-repl/test/e2e.spec.ts +++ b/packages/cli-repl/test/e2e.spec.ts @@ -16,12 +16,12 @@ describe('e2e', function() { it('shows version', async() => { const shell = TestShell.start({ args: [ '--version' ] }); - await eventually(() => { - shell.assertNoErrors(); - shell.assertContainsOutput( - require('../package.json').version - ); - }); + await shell.waitForExit(); + + shell.assertNoErrors(); + shell.assertContainsOutput( + require('../package.json').version + ); }); }); diff --git a/packages/cli-repl/test/test-shell.ts b/packages/cli-repl/test/test-shell.ts index 3ad66538bd..10dabf55f6 100644 --- a/packages/cli-repl/test/test-shell.ts +++ b/packages/cli-repl/test/test-shell.ts @@ -47,6 +47,7 @@ export class TestShell { private _process: ChildProcess; private _output: string; + private _onClose: Promise; constructor(shellProcess: ChildProcess) { this._process = shellProcess; @@ -63,6 +64,12 @@ export class TestShell { shellProcess.stderr.on('data', (chunk) => { this._output += stripAnsi(stderrDecoder.write(chunk)); }); + + this._onClose = new Promise((resolve) => { + shellProcess.once('close', (code) => { + resolve(code); + }); + }); } get output(): string { @@ -81,6 +88,10 @@ export class TestShell { }); } + waitForExit(): Promise { + return this._onClose; + } + kill(): void { this._process.kill(); } @@ -126,8 +137,6 @@ export class TestShell { assertContainsError(expectedError: string): void { const allErrors = this._getAllErrors(); - console.log(allErrors); - if (!allErrors.find((error) => error.includes(expectedError))) { throw new assert.AssertionError({ message: `Expected shell errors to include ${JSON.stringify(expectedError)}`, diff --git a/testing/integration-testing-hooks.ts b/testing/integration-testing-hooks.ts index ce199e4c6f..ac44c06763 100644 --- a/testing/integration-testing-hooks.ts +++ b/testing/integration-testing-hooks.ts @@ -1,7 +1,7 @@ const mongodbRunnerBefore = require('mongodb-runner/mocha/before'); const mongodbRunnerAfter = require('mongodb-runner/mocha/after'); -export const LOCAL_INSTANCE_PORT = 27028; +export const LOCAL_INSTANCE_PORT = 27018; export const LOCAL_INSTANCE_HOST = 'localhost'; /**