UNPKG

navy

Version:

Quick and powerful development environments using Docker and Docker Compose

78 lines (76 loc) 2.77 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/doctor/clean-compose-files', function () { let sandbox; let getLaunchedNavyNamesStub; let startStub; let pathToNavyStub; let normaliseNavyNameStub; let rmStub; let cleanComposeFiles; beforeEach(function () { sandbox = _sinon.default.createSandbox(); getLaunchedNavyNamesStub = sandbox.stub().resolves([]); startStub = sandbox.stub(); pathToNavyStub = sandbox.stub().callsFake(name => `/state/${name}`); normaliseNavyNameStub = sandbox.stub().callsFake(name => name.toLowerCase()); rmStub = sandbox.stub().resolves(); cleanComposeFiles = _proxyquire.default.noCallThru()('../clean-compose-files', { '../../': { getLaunchedNavyNames: getLaunchedNavyNamesStub }, './util': { start: startStub }, '../../navy/state': { pathToNavy: pathToNavyStub }, '../../navy/util': { normaliseNavyName: normaliseNavyNameStub }, fs: { promises: { rm: rmStub } } }); }); afterEach(function () { sandbox.restore(); }); describe('default export', function () { it('should print a starting message', async function () { await cleanComposeFiles(); (0, _chai.expect)(startStub.calledOnce).to.equal(true); (0, _chai.expect)(startStub.firstCall.args[0]).to.contain('Cleaning'); }); it('should not call rm when there are no launched navies', async function () { getLaunchedNavyNamesStub.resolves([]); await cleanComposeFiles(); (0, _chai.expect)(rmStub.called).to.equal(false); }); it('should remove docker-compose.tmp.yml from each launched navy path', async function () { getLaunchedNavyNamesStub.resolves(['env-1', 'Dev']); await cleanComposeFiles(); (0, _chai.expect)(rmStub.callCount).to.equal(2); const paths = rmStub.getCalls().map(c => c.args[0]); (0, _chai.expect)(paths).to.include('/state/env-1/docker-compose.tmp.yml'); (0, _chai.expect)(paths).to.include('/state/dev/docker-compose.tmp.yml'); rmStub.getCalls().forEach(call => { (0, _chai.expect)(call.args[1]).to.eql({ recursive: true, force: true }); }); }); it('should normalise navy names when resolving paths', async function () { getLaunchedNavyNamesStub.resolves(['MyEnv']); await cleanComposeFiles(); (0, _chai.expect)(normaliseNavyNameStub.calledWith('MyEnv')).to.equal(true); }); }); });