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
12 changes: 9 additions & 3 deletions packages/cli-repl/src/cli-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,17 @@ describe('CliRepl', () => {

context('with an actual server', () => {
const testServer = startTestServer('shared');
let cliRepl: CliRepl;

it('connects to a server and interacts with it', async() => {
beforeEach(() => {
cliRepl = new CliRepl(cliReplOptions);
});

afterEach(async() => {
await cliRepl.mongoshRepl.close();
});

it('connects to a server and interacts with it', async() => {
await cliRepl.start(await testServer.connectionString(), {});

output = '';
Expand All @@ -154,7 +162,6 @@ describe('CliRepl', () => {
});

it('asks for a password if one is required', async() => {
cliRepl = new CliRepl(cliReplOptions);
outputStream.on('data', (chunk) => {
if (chunk.includes('Enter password')) {
setImmediate(() => input.write('i want food\n'));
Expand All @@ -174,7 +181,6 @@ describe('CliRepl', () => {
});

it('respects a canceled password input', async() => {
cliRepl = new CliRepl(cliReplOptions);
outputStream.on('data', (chunk) => {
if (chunk.includes('Enter password')) {
setImmediate(() => input.write('\u0003')); // Ctrl+C
Expand Down
11 changes: 10 additions & 1 deletion packages/cli-repl/src/mongosh-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class MongoshNodeRepl {
}

repl.on('exit', async() => {
await internalState.close(true);
await this.close();
this.bus.emit('mongosh:exit', 0);
});

Expand Down Expand Up @@ -251,6 +251,15 @@ class MongoshNodeRepl {
}
return this._runtimeState;
}

async close(): Promise<void> {
const rs = this._runtimeState;
if (rs) {
this._runtimeState = null;
rs.repl.close();
await rs.internalState.close(true);
}
}
}

export default MongoshNodeRepl;