Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions packages/cli-repl/test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli-repl/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export async function eventually(fn: Function, options: { frequency?: number; timeout?: number } = {}): Promise<any> {
options = {
frequency: 100,
timeout: 10000,
timeout: process.env.IS_CI ? 10000 : 1000,
...options
};

Expand Down
40 changes: 32 additions & 8 deletions packages/cli-repl/test/test-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,31 @@ import stripAnsi from 'strip-ansi';
import assert from 'assert';

const PROMPT_PATTERN = /^> /m;
const ERROR_PATTERN = /Thrown:\n([^>]*)/m;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this go in a separate PR since it's a separate issue?

Copy link
Collaborator Author

@mcasimir mcasimir Jul 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without that change tests break when running on the compiled binary since the node version is slightly different from the one downloaded in the CI vm

const ERROR_PATTERN_1 = /Thrown:\n([^>]*)/m; // node <= 12.14
const ERROR_PATTERN_2 = /Uncaught[:\n ]+([^>]*)/m;

/**
* Test shell helper class.
*/
export class TestShell {
private static _openShells: TestShell[] = [];

static start(options: { args: string[] } = { args: [] }): TestShell {
const execPath = path.resolve(__dirname, '..', 'bin', 'mongosh.js');
static start(options: {
args: string[];
} = { args: [] }): TestShell {
let shellProcess: ChildProcess;

const process = 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(process);
const shell = new TestShell(shellProcess);
TestShell._openShells.push(shell);

return shell;
Expand All @@ -38,6 +47,7 @@ export class TestShell {
private _process: ChildProcess;

private _output: string;
private _onClose: Promise<number>;

constructor(shellProcess: ChildProcess) {
this._process = shellProcess;
Expand All @@ -54,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 {
Expand All @@ -72,6 +88,10 @@ export class TestShell {
});
}

waitForExit(): Promise<number> {
return this._onClose;
}

kill(): void {
this._process.kill();
}
Expand Down Expand Up @@ -132,7 +152,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());
}
}