Repository navigation
test: minimal repl eval option test #5192
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 === 'foo\n' && context.foo === 'bar'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the parens here are unnecessary?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right. They're just there for clarity. If they're objectionable, I can remove them. |
||
| }) | ||
| }; | ||
|
|
||
| const r = repl.start(options); | ||
| r.context = {foo: 'bar'}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| try { | ||
| r.write('foo\n'); | ||
| } finally { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the exceptions are ignored?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless I'm mistaken, they'll only be ignored if there's a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although actually I see now that the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL :-) I always thought ignoring
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, the "does not exit with an error when it should" thing is now fixed. |
||
| r.write('.exit\n'); | ||
| } | ||
|
|
||
| process.on('exit', () => { | ||
| assert(evalCalledWithExpectedArgs); | ||
| }); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this block is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's there so that if we write a subsequent test (such as to test that
contextis sent on tab completion), we can make sure there are no side effects (because the variables are scoped to the block).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to block-scoped vars (i.e.
letandconst) this feature, though existing in es5, is now actually useful.