UNPKG

navy

Version:

Quick and powerful development environments using Docker and Docker Compose

71 lines (69 loc) 2.39 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _chai = require("chai"); var _sinon = _interopRequireDefault(require("sinon")); var _mergeActionOptions = require("../merge-action-options"); /* eslint-env mocha */ describe('cli/util/merge-action-options', function () { it('should return parsed opts when command is missing', function () { const opts = { navy: 'dev' }; (0, _chai.expect)((0, _mergeActionOptions.mergeActionOptions)(opts, null)).to.equal(opts); }); it('should return parsed opts when optsWithGlobals is missing', function () { const opts = { navy: 'dev' }; (0, _chai.expect)((0, _mergeActionOptions.mergeActionOptions)(opts, {})).to.equal(opts); }); it('should merge optsWithGlobals so global navy wins over subcommand defaults', function () { const command = { optsWithGlobals: () => ({ navy: 'dev', json: true }) }; const merged = (0, _mergeActionOptions.mergeActionOptions)({ navy: 'default', json: false }, command); (0, _chai.expect)(merged.navy).to.equal('dev'); (0, _chai.expect)(merged.json).to.equal(true); }); it('should call optsWithGlobals on the command', function () { const spy = _sinon.default.stub().returns({ navy: 'x' }); (0, _mergeActionOptions.mergeActionOptions)({ navy: 'y' }, { optsWithGlobals: spy }); (0, _chai.expect)(spy.calledOnce).to.equal(true); }); it('should let an explicit subcommand option beat the inherited parent default', function () { const command = { optsWithGlobals: () => ({ navy: 'parent-default' }), getOptionValueSource: key => key === 'navy' ? 'cli' : 'default' }; const merged = (0, _mergeActionOptions.mergeActionOptions)({ navy: 'from-subcommand' }, command); (0, _chai.expect)(merged.navy).to.equal('from-subcommand'); }); it('should keep the parent value when the subcommand value came from its default', function () { const command = { optsWithGlobals: () => ({ navy: 'from-parent' }), getOptionValueSource: () => 'default' }; const merged = (0, _mergeActionOptions.mergeActionOptions)({ navy: 'subcommand-default' }, command); (0, _chai.expect)(merged.navy).to.equal('from-parent'); }); });