Skip to content

Commit c4a40a0

Browse files
committed
fix(checks): show skipped instead of passed for stack & mysql checks
no issue - mark task as skipped instead of completed if the mysql or system stack check fails but the user chooses to ignore the failure
1 parent 1decded commit c4a40a0

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

lib/commands/doctor/checks/mysql.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const includes = require('lodash/includes');
55

66
const errors = require('../../../errors');
77

8-
function mysqlCheck(ctx) {
8+
function mysqlCheck(ctx, task) {
99
// On ubuntu, mysqld is in `/usr/sbin` but it's not automatically in the PATH of non-root users
1010
// So, we modify the path env var to make things work
1111
const options = ctx.system.platform.linux ? {env: {PATH: `/usr/sbin:${process.env.PATH}`}} : {};
@@ -23,9 +23,14 @@ ${chalk.blue('c)')} run ${chalk.cyan('`ghost install local`')} to get a developm
2323
ctx.ui.confirm(chalk.blue('Continue anyway?'), false) :
2424
Promise.resolve({yes: false});
2525

26-
return confirmPromise.then(answer => answer.yes || Promise.reject(
27-
new errors.SystemError('MySQL check failed.')
28-
));
26+
return confirmPromise.then((answer) => {
27+
if (answer.yes) {
28+
task.skip('MySQL check skipped');
29+
return Promise.resolve();
30+
}
31+
32+
return Promise.reject(new errors.SystemError('MySQL check failed.'));
33+
});
2934
});
3035
}
3136

lib/commands/doctor/checks/system-stack.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const execa = require('execa');
44

55
const errors = require('../../../errors');
66

7-
function systemStack(ctx) {
7+
function systemStack(ctx, task) {
88
let promise;
99

1010
if (!ctx.system.platform.linux) {
@@ -35,18 +35,28 @@ function systemStack(ctx) {
3535
});
3636
}
3737

38-
return promise.then(() => { return {yes: true}; }).catch((error) => {
38+
return promise.catch((error) => {
3939
ctx.ui.log(
4040
`System checks failed with message: '${error.message}'
4141
Some features of Ghost-CLI may not work without additional configuration.
4242
For local installs we recommend using \`ghost install local\` instead.`,
4343
'yellow'
4444
);
4545

46-
return ctx.ui.allowPrompt ? ctx.ui.confirm(chalk.blue('Continue anyway?'), false) : Promise.resolve({yes: false});
47-
}).then(answer => answer.yes || Promise.reject(
48-
new errors.SystemError('System checks failed.')
49-
));
46+
return (ctx.ui.allowPrompt ?
47+
ctx.ui.confirm(chalk.blue('Continue anyway?'), false) :
48+
Promise.resolve({yes: false})
49+
).then((answer) => {
50+
if (answer.yes) {
51+
task.skip('System stack check skipped');
52+
return Promise.resolve();
53+
}
54+
55+
return Promise.reject(
56+
new errors.SystemError('System checks failed.')
57+
);
58+
});
59+
});
5060
}
5161

5262
module.exports = {

test/unit/commands/doctor/checks/mysql-spec.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,19 @@ describe('Unit: Doctor Checks > mysql', function () {
4949
const execaStub = sandbox.stub(execa, 'shell').rejects();
5050
const logStub = sandbox.stub();
5151
const confirmStub = sandbox.stub().resolves({yes: true});
52+
const skipStub = sandbox.stub();
5253

5354
const ctx = {
5455
ui: {log: logStub, confirm: confirmStub, allowPrompt: true},
5556
system: {platform: {linux: true}}
5657
};
5758

58-
return mysqlCheck.task(ctx).then(() => {
59+
return mysqlCheck.task(ctx, {skip: skipStub}).then(() => {
5960
expect(execaStub.calledOnce).to.be.true;
6061
expect(logStub.calledOnce).to.be.true;
6162
expect(logStub.args[0][0]).to.match(/MySQL install not found/);
6263
expect(confirmStub.calledOnce).to.be.true;
64+
expect(skipStub.calledOnce).to.be.true;
6365
});
6466
});
6567

test/unit/commands/doctor/checks/system-stack-spec.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,20 @@ describe('Unit: Doctor Checks > systemStack', function () {
7474
const execaStub = sandbox.stub(execa, 'shell').resolves();
7575
const logStub = sandbox.stub();
7676
const confirmStub = sandbox.stub().resolves({yes: true});
77+
const skipStub = sandbox.stub();
7778

7879
const ctx = {
7980
ui: {log: logStub, confirm: confirmStub, allowPrompt: true},
8081
system: {platform: {linux: false}}
8182
};
8283

83-
return systemStack.task(ctx).then(() => {
84+
return systemStack.task(ctx, {skip: skipStub}).then(() => {
8485
expect(execaStub.called).to.be.false;
8586
expect(logStub.calledOnce).to.be.true;
8687
expect(logStub.args[0][0]).to.match(/failed with message/);
8788
expect(logStub.args[0][0]).to.match(/not Linux/);
8889
expect(confirmStub.calledOnce).to.be.true;
90+
expect(skipStub.calledOnce).to.be.true;
8991
});
9092
});
9193

0 commit comments

Comments
 (0)