forked from shelljs/shelljs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathto.js
More file actions
60 lines (48 loc) · 1.42 KB
/
to.js
File metadata and controls
60 lines (48 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import fs from 'fs';
import test from 'ava';
import shell from '..';
import utils from './utils/utils';
test.beforeEach(t => {
t.context.tmp = utils.getTempDir();
shell.config.resetForTesting();
shell.mkdir(t.context.tmp);
});
test.afterEach.always(t => {
shell.rm('-rf', t.context.tmp);
});
//
// Invalids
//
test('Normal strings don\'t have \'.to()\' anymore', t => {
const str = 'hello world';
t.is(str.to, undefined);
});
test('no file argument', t => {
shell.ShellString('hello world').to();
t.truthy(shell.error());
});
test('cannot write to a non-existent directory', t => {
t.falsy(fs.existsSync('/asdfasdf')); // sanity check
shell.ShellString('hello world').to('/asdfasdf/file');
t.truthy(shell.error());
});
//
// Valids
//
test('can be chained', t => {
shell.ShellString('hello world').to(`${t.context.tmp}/to1`).to(`${t.context.tmp}/to2`);
let result = shell.cat(`${t.context.tmp}/to1`);
t.falsy(shell.error());
t.is(result.toString(), 'hello world');
result = shell.cat(`${t.context.tmp}/to2`);
t.falsy(shell.error());
t.is(result.toString(), 'hello world');
});
test('With a glob', t => {
shell.touch(`${t.context.tmp}/to1`);
shell.ShellString('goodbye').to(`${t.context.tmp}/t*1`);
t.falsy(fs.existsSync(`${t.context.tmp}/t*1`), 'globs are not interpreted literally');
const result = shell.cat(`${t.context.tmp}/to1`);
t.falsy(shell.error());
t.is(result.toString(), 'goodbye');
});