UNPKG

navy

Version:

Quick and powerful development environments using Docker and Docker Compose

110 lines (108 loc) 3.87 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _chai = require("chai"); var _sinon = _interopRequireDefault(require("sinon")); var _proxyquire = _interopRequireDefault(require("proxyquire")); /* eslint-env mocha */ describe('cli/import', function () { let sandbox; let getNavyStub; let navyStub; let getImportOptionsForCLIStub; let importNavyStub; let fsStub; let consoleLogStub; let originalIsTTY; let importCli; beforeEach(function () { sandbox = _sinon.default.createSandbox(); navyStub = { name: 'env-1' }; getNavyStub = sandbox.stub().returns(navyStub); getImportOptionsForCLIStub = sandbox.stub().resolves({ configProvider: 'filesystem', path: '/some/path' }); importNavyStub = sandbox.stub().resolves(); fsStub = { readFileSync: sandbox.stub().returns(' ___ \n /___\\ \n') }; consoleLogStub = sandbox.stub(console, 'log'); originalIsTTY = process.stdout.isTTY; process.stdout.isTTY = false; importCli = _proxyquire.default.noCallThru()('../import', { '../util/fs': fsStub, '../': { getNavy: getNavyStub }, '../config-provider': { getImportOptionsForCLI: getImportOptionsForCLIStub }, './util': { importNavy: importNavyStub } }); }); afterEach(function () { process.stdout.isTTY = originalIsTTY; sandbox.restore(); }); describe('default export', function () { it('should resolve the navy instance using opts.navy', async function () { await importCli({ navy: 'env-1' }); (0, _chai.expect)(getNavyStub.calledOnce).to.equal(true); (0, _chai.expect)(getNavyStub.firstCall.args[0]).to.equal('env-1'); }); it('should read the sailing-boat ASCII art file', async function () { await importCli({ navy: 'env-1' }); (0, _chai.expect)(fsStub.readFileSync.calledOnce).to.equal(true); (0, _chai.expect)(fsStub.readFileSync.firstCall.args[0]).to.contain('sailing-boat.txt'); }); it('should derive initialise opts via getImportOptionsForCLI and pass them to importNavy', async function () { const opts = { navy: 'env-1', someOpt: 'value' }; const initialiseOpts = { configProvider: 'filesystem', path: '/cwd' }; getImportOptionsForCLIStub.resolves(initialiseOpts); await importCli(opts); (0, _chai.expect)(getImportOptionsForCLIStub.calledOnce).to.equal(true); (0, _chai.expect)(getImportOptionsForCLIStub.firstCall.args[0]).to.equal(opts); (0, _chai.expect)(importNavyStub.calledOnce).to.equal(true); (0, _chai.expect)(importNavyStub.firstCall.args[0]).to.equal(navyStub); (0, _chai.expect)(importNavyStub.firstCall.args[1]).to.equal(initialiseOpts); }); it('should log the post-import help line', async function () { await importCli({ navy: 'env-1' }); const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join(' '); (0, _chai.expect)(printed).to.contain('navy'); (0, _chai.expect)(printed).to.contain('any directory'); }); it('should not print the boat ASCII art when stdout is not a TTY', async function () { process.stdout.isTTY = false; await importCli({ navy: 'env-1' }); const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n'); (0, _chai.expect)(printed).to.not.contain('___'); }); it('should print the boat ASCII art when stdout is a TTY', async function () { process.stdout.isTTY = true; await importCli({ navy: 'env-1' }); const printed = consoleLogStub.getCalls().map(c => c.args[0] || '').join('\n'); (0, _chai.expect)(printed).to.contain('___'); }); }); });