From 5be505e7ef5f80b882dd960e68ea664fa1be0cb3 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 10 Feb 2016 21:44:15 -0800 Subject: [PATCH 1/2] test: minimal repl eval option test Fixes: https://github.com/nodejs/node/issues/3544 --- test/parallel/test-repl-eval.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/parallel/test-repl-eval.js diff --git a/test/parallel/test-repl-eval.js b/test/parallel/test-repl-eval.js new file mode 100644 index 000000000000..ac32e858415c --- /dev/null +++ b/test/parallel/test-repl-eval.js @@ -0,0 +1,22 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const repl = require('repl'); + +{ + const options = { + eval: common.mustCall((cmd, context) => { + assert.strictEqual(cmd, 'foo\n'); + assert.deepStrictEqual(context, {animal: 'Sterrance'}); + }) + }; + + const r = repl.start(options); + r.context = {animal: 'Sterrance'}; + + try { + r.write('foo\n'); + } finally { + r.write('.exit\n'); + } +} From e7ebcda38b66e11ba803e0cf12bb2f89b9a841cc Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 10 Feb 2016 23:16:39 -0800 Subject: [PATCH 2/2] fixup --- test/parallel/test-repl-eval.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-repl-eval.js b/test/parallel/test-repl-eval.js index ac32e858415c..7e5c7d39946c 100644 --- a/test/parallel/test-repl-eval.js +++ b/test/parallel/test-repl-eval.js @@ -4,19 +4,26 @@ const assert = require('assert'); const repl = require('repl'); { + let evalCalledWithExpectedArgs = false; + const options = { eval: common.mustCall((cmd, context) => { - assert.strictEqual(cmd, 'foo\n'); - assert.deepStrictEqual(context, {animal: 'Sterrance'}); + // 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'); }) }; const r = repl.start(options); - r.context = {animal: 'Sterrance'}; + r.context = {foo: 'bar'}; try { r.write('foo\n'); } finally { r.write('.exit\n'); } + + process.on('exit', () => { + assert(evalCalledWithExpectedArgs); + }); }