-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(doctor): add binary dependency check (#1040)
no issue - checks if the node version has changed on start, to prevent issues with binary deps
- Loading branch information
Showing
7 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const chalk = require('chalk'); | ||
const {SystemError} = require('../../../errors'); | ||
|
||
const taskTitle = 'Checking binary dependencies'; | ||
|
||
function binaryDeps(ctx, task) { | ||
if (!ctx.instance) { | ||
return task.skip('Instance not set'); | ||
} | ||
|
||
if (process.versions.node !== ctx.instance.nodeVersion) { | ||
const currentVersion = ctx.instance.version; | ||
|
||
throw new SystemError({ | ||
message: 'The installed node version has changed since Ghost was installed.', | ||
help: `Run ${chalk.green(`ghost update ${currentVersion} --force`)} to re-install binary dependencies.`, | ||
task: taskTitle | ||
}); | ||
} | ||
} | ||
|
||
module.exports = { | ||
title: taskTitle, | ||
task: binaryDeps, | ||
category: ['start'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const {expect} = require('chai'); | ||
const sinon = require('sinon'); | ||
const semver = require('semver'); | ||
|
||
const {SystemError} = require('../../../../../lib/errors'); | ||
const check = require('../../../../../lib/commands/doctor/checks/binary-deps'); | ||
|
||
describe('Unit: Doctor Checks > Binary Deps', function () { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('exports proper task', function () { | ||
expect(check.title).to.equal('Checking binary dependencies'); | ||
expect(check.task).to.be.a('function'); | ||
expect(check.category).to.deep.equal(['start']); | ||
}); | ||
|
||
it('skips if instance not set', function () { | ||
const skip = sinon.stub(); | ||
|
||
check.task({}, {skip}); | ||
expect(skip.calledOnce).to.be.true; | ||
}); | ||
|
||
it('does nothing if node versions are the same', function () { | ||
const skip = sinon.stub(); | ||
const instance = {nodeVersion: process.versions.node}; | ||
|
||
check.task({instance}, {skip}); | ||
expect(skip.called).to.be.false; | ||
}); | ||
|
||
it('throws error if node versions are different', function () { | ||
const skip = sinon.stub(); | ||
const instance = {nodeVersion: semver.inc(process.versions.node, 'major')}; | ||
|
||
try { | ||
check.task({instance}, {skip}); | ||
} catch (error) { | ||
expect(error).to.be.an.instanceof(SystemError); | ||
expect(error.message).to.include('node version has changed'); | ||
expect(skip.called).to.be.false; | ||
return; | ||
} | ||
|
||
expect.fail('should have thrown an error'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters