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
14 changes: 14 additions & 0 deletions packages/cli-repl/src/mongosh-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,4 +710,18 @@ describe('MongoshNodeRepl', () => {
expect(output).to.contain('Atlas Data Lake > ');
});
});

context('before the REPL starts', () => {
beforeEach(async() => {
await mongoshRepl.initialize(serviceProvider);
// No .start() call here.
});

it('does not show a prompt', async() => {
await mongoshRepl.loadExternalCode('setImmediate(() => { throw new Error(); })', '<eval>');
await tick();
expect(output).to.include('Error: \n');
expect(output).not.to.include('>');
});
});
});
5 changes: 5 additions & 0 deletions packages/cli-repl/src/mongosh-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class MongoshNodeRepl implements EvaluationListener {
onClearCommand?: EvaluationListener['onClearCommand'];
insideAutoComplete: boolean;
inspectDepth = 0;
started = false;

constructor(options: MongoshNodeReplOptions) {
this.input = options.input;
Expand Down Expand Up @@ -151,6 +152,9 @@ class MongoshNodeRepl implements EvaluationListener {
const originalDisplayPrompt = repl.displayPrompt.bind(repl);

repl.displayPrompt = (...args: any[]) => {
if (!this.started) {
return;
}
originalDisplayPrompt(...args);
this.lineByLineInput.nextLine();
};
Expand Down Expand Up @@ -242,6 +246,7 @@ class MongoshNodeRepl implements EvaluationListener {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async startRepl(_initializationToken: InitializationToken): Promise<void> {
this.started = true;
const { repl, internalState } = this.runtimeState();
// Only start reading from the input *after* we set up everything, including
// internalState.setCtx().
Expand Down