Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/node-red/node_modules/simple-cli/test/ drwxr-xr-x | |
| Viewing file: Select action/file-type: const sinon = require('sinon');
const proxyquire = require('proxyquire').noCallThru();
describe('simple cli', () => {
let stubs;
beforeEach(() => {
stubs = {
getDynamicValues: sinon.stub().callsArg(0),
spawn: sinon.stub(),
handleCustomOption: sinon.stub(),
debug: sinon.stub()
};
});
class Builder {
constructor() {
Object.assign(this, stubs);
}
}
const cli = proxyquire('../lib/simple-cli', {
'./builder': Builder
});
it('should return a function', () => {
cli('name').should.be.an.instanceOf(Function);
});
it('should create a multitask with a string', () => {
const grunt = {
registerMultiTask: sinon.stub()
};
cli('blah')(grunt);
grunt.registerMultiTask.should.have.been.calledWith('blah', 'A simple grunt wrapper for blah', sinon.match.func);
});
it('should create a multitask with an object', () => {
const grunt = {
registerMultiTask: sinon.stub()
};
cli('task', { description: 'description' })(grunt);
grunt.registerMultiTask.should.have.been.calledWith('task', 'description', sinon.match.func);
});
describe('configuring a task', () => {
let grunt, cb, options;
beforeEach(() => {
grunt = {
registerMultiTask: sinon.stub(),
fail: {
fatal: sinon.stub()
}
};
cb = sinon.stub();
options = {
description: 'description',
custom: {
foo: 'bar'
},
callback: cb
};
});
it('should handle success', () => {
cli('task', options)(grunt);
const task = grunt.registerMultiTask.getCall(0).args[2];
const context = {};
stubs.handleCustomOption.callsArg(1);
task.apply(context);
stubs.getDynamicValues.should.have.been.calledWith(sinon.match.func);
stubs.handleCustomOption.should.have.been.calledWith('foo', sinon.match.func);
stubs.spawn.should.have.been.called;
});
it('should handle async errors', () => {
cli('task', options)(grunt);
const task = grunt.registerMultiTask.getCall(0).args[2];
const context = {};
stubs.handleCustomOption.callsArgWith(1, 'error');
task.apply(context);
stubs.getDynamicValues.should.have.been.calledWith(sinon.match.func);
stubs.handleCustomOption.should.have.been.calledWith('foo', sinon.match.func);
grunt.fail.fatal.should.have.been.calledWith('error');
stubs.spawn.called.should.be.false();
});
it('should allow debugging', () => {
Builder.prototype.debugOn = true;
cli('task', options)(grunt);
const task = grunt.registerMultiTask.getCall(0).args[2];
const context = {};
stubs.handleCustomOption.callsArg(1);
task.apply(context);
stubs.getDynamicValues.should.have.been.calledWith(sinon.match.func);
stubs.handleCustomOption.should.have.been.calledWith('foo', sinon.match.func);
stubs.debug.should.have.been.called;
stubs.spawn.should.not.have.been.called;
});
});
});
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0046 ]-- |