nci/test/commands/shell.js

56 lines
1.4 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({
2015-06-28 14:47:34 +00:00
emitOut: true,
attachStderr: 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-28 14:47:34 +00:00
// messages and codes are slightly different across the OSes
2015-06-13 19:41:37 +00:00
// e.g. at linux and macos
2015-06-28 14:47:34 +00:00
expect(err.message).match(
/^Spawned command exits with non-zero code: \d+/
);
expect(err.stderr).match(/echo1:.*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
});