diff --git a/src/to.js b/src/to.js index f029999..65d6d54 100644 --- a/src/to.js +++ b/src/to.js @@ -22,6 +22,7 @@ function _to(options, file) { try { fs.writeFileSync(file, this.toString(), 'utf8'); + return this; } catch(e) { common.error('could not write to file (code '+e.code+'): '+file, true); } diff --git a/src/toEnd.js b/src/toEnd.js index f6d099d..bf29a65 100644 --- a/src/toEnd.js +++ b/src/toEnd.js @@ -22,6 +22,7 @@ function _toEnd(options, file) { try { fs.appendFileSync(file, this.toString(), 'utf8'); + return this; } catch(e) { common.error('could not append to file (code '+e.code+'): '+file, true); } diff --git a/test/to.js b/test/to.js index 7e8f6db..fea4665 100644 --- a/test/to.js +++ b/test/to.js @@ -23,9 +23,12 @@ assert.ok(shell.error()); // Valids // -'hello world'.to('tmp/to1'); +'hello world'.to('tmp/to1').to('tmp/to2'); var result = shell.cat('tmp/to1'); assert.equal(shell.error(), null); assert.equal(result, 'hello world'); +result = shell.cat('tmp/to2'); +assert.equal(shell.error(), null); +assert.equal(result, 'hello world'); shell.exit(123); diff --git a/test/toEnd.js b/test/toEnd.js index 53c8d6c..15d3290 100644 --- a/test/toEnd.js +++ b/test/toEnd.js @@ -22,11 +22,15 @@ assert.ok(shell.error()); // assert.equal(fs.existsSync('tmp/toEnd1'), false); //Check file toEnd() creates does not already exist +assert.equal(fs.existsSync('tmp/toEnd2'), false); 'hello '.toEnd('tmp/toEnd1'); assert.equal(fs.existsSync('tmp/toEnd1'), true); //Check that file was created -'world'.toEnd('tmp/toEnd1'); //Write some more to the file +'world'.toEnd('tmp/toEnd1').toEnd('tmp/toEnd2'); //Write some more to the file var result = shell.cat('tmp/toEnd1'); assert.equal(shell.error(), null); assert.equal(result, 'hello world'); //Check that the result is what we expect +result = shell.cat('tmp/toEnd2'); +assert.equal(shell.error(), null); +assert.equal(result, 'world'); //Check that the result is what we expect shell.exit(123);