-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
86 lines (70 loc) · 2.62 KB
/
test.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* globals describe, it */
var pluginInspect = require('..');
// If we were using additional plugins, we could load them here
var shell = require('shelljs'); // recommended
var fs = require('fs');
var util = require('util');
require('should');
// Newer versions of node use a symbol called util.inspect.custom.
var inspectAttribute = util.inspect.custom || 'inspect';
// override console.error() to cover up common.error() calls
console.error = function () { };
describe('plugin-inspect', function () {
it('does not get added to the shelljs instance', function () {
shell.should.not.have.property('inspect');
shell.should.not.have.property(util.inspect.custom);
});
it('does not override other commands or methods', function () {
/*
* Plugins shouldn't interfere with existing commands
*/
shell.cp.should.be.type('function');
shell.mv.should.be.type('function');
shell.ls().should.have.property('toEnd');
shell.ls().should.have.property('grep');
shell.ls().should.have.property('sed');
});
it('exports the plugin implementation', function () {
/*
* A plugin author can also export the implementation of their commands
*/
pluginInspect.should.be.type('object');
pluginInspect.customInspect.should.be.type('function');
});
it('gets added as a method on ShellStrings', function () {
/*
* Plugins can be methods on ShellStrings
*/
var ret = shell.ls();
ret[inspectAttribute].should.be.type('function');
});
it('works for strings', function () {
var ret = shell.cat('index.js');
util.inspect(ret).should.equal(fs.readFileSync('index.js', 'utf-8'));
});
it.skip('works for commands with no trailing newline', function () {
var ret = shell.pwd();
util.inspect(ret).should.equal(process.cwd() + '\n');
});
it('works for arrays', function () {
var ret = shell.cat('index.js');
util.inspect(ret).should.equal(fs.readFileSync('index.js', 'utf-8'));
});
it('gets applied directly to ShellStrings', function () {
var ret = new shell.ShellString('Hello world');
util.inspect(ret).should.be.type('string');
util.inspect(ret).should.equal('Hello world');
});
it('works for piped commands', function () {
var ret = shell.cat('index.js').grep('o');
util.inspect(ret).should.equal(shell.grep('o', 'index.js').toString());
});
it('works for commands that have errors', function () {
var ret = shell.rm('fakeFileName.txt');
util.inspect(ret).should.equal('');
});
it('does not break non-ShellString commands', function () {
var ret = shell.test('-f', 'index.js');
ret.should.equal(true);
});
});