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
4 changes: 3 additions & 1 deletion packages/cli-repl/test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { promises as fs, createReadStream } from 'fs';
import { promisify } from 'util';
import rimraf from 'rimraf';
import path from 'path';
import { readReplLogfile } from './repl-helpers';
import { readReplLogfile, hasNodeBug38314 } from './repl-helpers';

describe('e2e', function() {
const testServer = startTestServer('shared');
Expand Down Expand Up @@ -517,6 +517,8 @@ describe('e2e', function() {
let result;
result = await shell.executeLine('require("a")');
expect(result).to.match(/Error: Cannot find module 'a'/);
// Wait for double prompt because of Node.js REPL bug
if (hasNodeBug38314()) await eventually(() => shell.assertContainsOutput('> > '));
result = await shell.executeLine('require("./a")');
expect(result).to.match(/^A$/m);
result = await shell.executeLine('require("b")');
Expand Down
16 changes: 15 additions & 1 deletion packages/cli-repl/test/repl-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import chai, { expect } from 'chai';
import sinon from 'ts-sinon';
import sinonChai from 'sinon-chai';
import chaiAsPromised from 'chai-as-promised';
import repl from 'repl';
import { PassThrough } from 'stream';
import type { MongoshBus, MongoshBusEventsMap } from '@mongosh/types';

chai.use(sinonChai);
Expand Down Expand Up @@ -76,6 +78,17 @@ async function readReplLogfile(logPath: string) {
.map((line) => JSON.parse(line));
}

// https://github.com/nodejs/node/pull/38314
function hasNodeBug38314() {
const input = new PassThrough();
const output = new PassThrough();
const evalFn = (code, ctx, filename, cb) => cb(new Error('err'));
const prompt = 'prompt#';
repl.start({ input, output, eval: evalFn, prompt });
input.end('s\n');
return String(output.read()).includes('prompt#prompt#');
}

export {
expect,
sinon,
Expand All @@ -85,5 +98,6 @@ export {
waitEval,
waitCompletion,
fakeTTYProps,
readReplLogfile
readReplLogfile,
hasNodeBug38314
};