nci/test/commands/shell.js

51 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-12-03 22:23:41 +00:00
'use strict';
var expect = require('expect.js'),
ShellCommand = require('../../lib/command/shell').Command;
describe('Shell command', function() {
var shellCommand;
it('Should be created without errors', function() {
shellCommand = new ShellCommand({
2014-12-14 20:04:00 +00:00
emitOut: true
2014-12-03 22:23:41 +00:00
});
});
it('Default shell should be sh', function() {
expect(shellCommand.shell).equal('/bin/sh');
});
2014-12-14 19:51:41 +00:00
var collectData = function(result, field) {
return function(data) {
result[field] += data;
};
};
var std = {out: '', err: ''};
2014-12-03 22:23:41 +00:00
it('echo "Hello world" should be done', function(done) {
2014-12-14 19:51:41 +00:00
shellCommand.on('stdout', collectData(std, 'out'));
shellCommand.on('stderr', collectData(std, 'err'));
shellCommand.run({cmd: 'echo "Hello world1"'}, function(err) {
2014-12-03 22:23:41 +00:00
expect(err).not.ok();
2014-12-14 19:51:41 +00:00
expect(std.err).equal('');
expect(std.out).equal('Hello world1\n');
2014-12-03 22:23:41 +00:00
done();
});
});
2014-12-14 19:51:41 +00:00
it('echo1 "Hello world" should fails', function(done) {
std.out = '';
std.err = '';
shellCommand.run({cmd: 'echo1 "Hello world"'}, function(err) {
expect(err).ok();
expect(err).an(Error);
2015-06-13 19:38:38 +00:00
expect(err.message).contain('echo1:');
expect(err.message).contain('not found');
2014-12-14 19:51:41 +00:00
expect(std.err).equal('');
expect(std.out).equal('');
done();
});
});
2014-12-03 22:23:41 +00:00
});