shelljs/test/to.js
Nate Fischer 6ebc2d3db7 refactor(shellstring): return consistent objects
- fix(string): no longer overrides string prototype
 - exec() now returns a ShellString object
2016-02-19 14:54:30 -08:00

45 lines
974 B
JavaScript

var shell = require('..');
var assert = require('assert'),
fs = require('fs');
shell.config.silent = true;
shell.rm('-rf', 'tmp');
shell.mkdir('tmp');
//
// Invalids
//
// Normal strings don't have '.to()' anymore
var str = 'hello world';
assert.ok(typeof str.to === 'undefined');
shell.ShellString('hello world').to();
assert.ok(shell.error());
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
shell.ShellString('hello world').to('/asdfasdf/file');
assert.ok(shell.error());
//
// Valids
//
shell.ShellString('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');
// With a glob
shell.ShellString('goodbye').to('tmp/t*1');
var result = shell.cat('tmp/to1');
assert.equal(shell.error(), null);
assert.equal(result, 'goodbye');
shell.exit(123);