navy
Version:
Quick and powerful development environments using Docker and Docker Compose
49 lines (47 loc) • 2.11 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _chai = require("chai");
var _sinon = _interopRequireDefault(require("sinon"));
var _errors = require("../errors");
/* eslint-env mocha */
describe('errors', function () {
describe('NavyError', function () {
it('should expose the message passed to the constructor', function () {
const err = new _errors.NavyError('something went wrong');
(0, _chai.expect)(err.message).to.equal('something went wrong');
});
it('should print a red ERROR banner followed by the message and blank lines via prettyPrint', function () {
const log = _sinon.default.stub(console, 'log');
try {
new _errors.NavyError('boom').prettyPrint();
} finally {
log.restore();
}
(0, _chai.expect)(log.callCount).to.equal(5);
(0, _chai.expect)(log.firstCall.args).to.eql([]);
(0, _chai.expect)(log.secondCall.args[0]).to.contain('ERROR');
(0, _chai.expect)(log.thirdCall.args).to.eql([]);
(0, _chai.expect)(log.getCall(3).args[0]).to.equal(' boom');
(0, _chai.expect)(log.getCall(4).args).to.eql([]);
});
});
describe('NavyNotInitialisedError', function () {
it('should be a NavyError that includes the navy name in the message', function () {
const err = new _errors.NavyNotInitialisedError('myenv');
(0, _chai.expect)(err).to.be.instanceof(_errors.NavyError);
(0, _chai.expect)(err.message).to.equal('Navy "myenv" not imported');
});
it('should call the parent prettyPrint and add a hint about navy import', function () {
const log = _sinon.default.stub(console, 'log');
try {
new _errors.NavyNotInitialisedError('foo').prettyPrint();
} finally {
log.restore();
}
const messages = log.getCalls().map(call => call.args[0] || '');
const hint = messages.find(m => typeof m === 'string' && m.includes('navy import'));
(0, _chai.expect)(hint).to.be.a('string');
(0, _chai.expect)(hint).to.contain('imported the navy');
});
});
});