Skip to content

Commit

Permalink
fix: show spinner during update check
Browse files Browse the repository at this point in the history
no issue
- when on a slow connection, there's no UI output indicating something is going on. This ensures that some output is generated showing that an update check is occurring
  • Loading branch information
acburdine committed Jul 26, 2018
1 parent 1874d5d commit c9cf6d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
6 changes: 5 additions & 1 deletion lib/utils/update-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ const pkg = require('../../package.json');
* @param {UI} ui ui instance
*/
module.exports = function updateCheck(ui) {
return latestVersion(pkg.name).then((latest) => {
return ui.run(
() => latestVersion(pkg.name),
'Checking for Ghost-CLI updates',
{clear: true}
).then((latest) => {
if (semver.lt(pkg.version, latest)) {
const chalk = require('chalk');

Expand Down
27 changes: 19 additions & 8 deletions test/unit/utils/update-check-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ describe('Unit: Utils > update-check', function () {
const pkg = {name: 'ghost', version: '1.0.0'};
const testError = new Error('update check');
const latestVersion = sinon.stub().rejects(testError);
const ui = {run: sinon.stub().callsFake(fn => fn())}

const updateCheck = proxyquire(modulePath, {
'../../package.json': pkg,
'latest-version': latestVersion
});

updateCheck().catch((err) => {
updateCheck(ui).catch((err) => {
expect(err.message).to.equal(testError.message);
expect(ui.run.calledOnce).to.be.true;
expect(latestVersion.calledOnce).to.be.true;
expect(latestVersion.calledWithExactly('ghost')).to.be.true;
done();
Expand All @@ -28,15 +30,19 @@ describe('Unit: Utils > update-check', function () {
it('doesn\'t do anything if there are no updates', function () {
const pkg = {name: 'ghost', version: '1.0.0'};
const latestVersion = sinon.stub().resolves('1.0.0');
const logStub = sinon.stub();
const ui = {
run: sinon.stub().callsFake(fn => fn()),
log: sinon.stub()
};

const updateCheck = proxyquire(modulePath, {
'../../package.json': pkg,
'latest-version': latestVersion
});

return updateCheck({log: logStub}).then(() => {
expect(logStub.called).to.be.false;
return updateCheck(ui).then(() => {
expect(ui.run.calledOnce).to.be.true;
expect(ui.log.called).to.be.false;
expect(latestVersion.calledOnce).to.be.true;
expect(latestVersion.calledWithExactly('ghost')).to.be.true;
});
Expand All @@ -45,17 +51,22 @@ describe('Unit: Utils > update-check', function () {
it('logs a message if an update is available', function () {
const pkg = {name: 'ghost', version: '1.0.0'};
const latestVersion = sinon.stub().resolves('1.1.0');
const logStub = sinon.stub();
const ui = {
run: sinon.stub().callsFake(fn => fn()),
log: sinon.stub()
};

const updateCheck = proxyquire(modulePath, {
'../../package.json': pkg,
'latest-version': latestVersion
});

return updateCheck({log: logStub}).then(() => {
expect(logStub.calledOnce).to.be.true;
return updateCheck(ui).then(() => {
expect(ui.run.calledOnce).to.be.true;
expect(ui.log.calledOnce).to.be.true;

const log = logStub.args[0][0];

const log = ui.log.args[0][0];

expect(stripAnsi(log)).to.match(/You are running an outdated version of Ghost-CLI/);

Expand Down

0 comments on commit c9cf6d3

Please sign in to comment.