Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: Empty command should be sent to eval function #11871

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 0 additions & 6 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,6 @@ function REPLServer(prompt,
return;
}
}
} else {
// Print a new line when hitting enter.
if (!self.bufferedCommand) {
finish(null);
return;
}
}

const evalCmd = self.bufferedCommand + cmd + '\n';
Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-repl-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const repl = require('repl');

{
let evalCalledWithExpectedArgs = false;

const options = {
eval: common.mustCall((cmd, context) => {
// Assertions here will not cause the test to exit with an error code
// so set a boolean that is checked in process.on('exit',...) instead.
evalCalledWithExpectedArgs = (cmd === '\n');
})
};

const r = repl.start(options);

try {
// Empty strings should be sent to the repl's eval function
r.write('\n');
} finally {
r.write('.exit\n');
}

process.on('exit', () => {
assert(evalCalledWithExpectedArgs);
});
Copy link
Member

Choose a reason for hiding this comment

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

I think you don’t need for the process to exit, the eval callback should be called synchronousl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can simplify the test file, just wrote it this way to match the existing ones (cp test/parallel/test-repl-{eval,empty}.js).

}