diff --git a/src/echo.js b/src/echo.js index 2b0e7d9..045c35e 100644 --- a/src/echo.js +++ b/src/echo.js @@ -29,6 +29,6 @@ function _echo(opts, messages) { } console.log.apply(console, messages); - return messages.join(' '); + return messages.join(' ') + '\n'; } module.exports = _echo; diff --git a/test/echo.js b/test/echo.js index 7887d88..87c48e2 100644 --- a/test/echo.js +++ b/test/echo.js @@ -5,6 +5,14 @@ import utils from './utils/utils'; shell.config.silent = true; +test.beforeEach(t => { + t.context.tmp = utils.getTempDir(); +}); + +test.afterEach.always(t => { + shell.rm('-rf', t.context.tmp); +}); + // // Valids // @@ -57,3 +65,17 @@ test.cb('-e option', t => { t.end(); }); }); + +test.cb('piping to a file', t => { + // see issue #476 + shell.mkdir(t.context.tmp); + const tmp = `${t.context.tmp}/echo.txt`; + const script = `require('../global.js'); echo('A').toEnd('${tmp}'); echo('B').toEnd('${tmp}');`; + utils.runScript(script, (err, stdout) => { + const result = shell.cat(tmp); + t.falsy(err); + t.is(stdout, 'A\nB\n'); + t.is(result.toString(), 'A\nB\n'); + t.end(); + }); +});