Skip to content

Commit 6ccf6be

Browse files
vikaspotluri123acburdine
authored andcommitted
feat(mem-check): add skip flag
1 parent a852cdd commit 6ccf6be

File tree

9 files changed

+71
-10
lines changed

9 files changed

+71
-10
lines changed

lib/commands/doctor/checks/check-memory.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ function checkMemory() {
1616
module.exports = {
1717
title: 'Checking memory availability',
1818
task: checkMemory,
19+
enabled: ctx => ctx.argv['check-mem'] === true,
1920
category: ['install', 'start', 'update']
2021
};

lib/commands/doctor/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,13 @@ DoctorCommand.description = 'Check the system for any potential hiccups when ins
5656
DoctorCommand.longDescription = '$0 doctor [categories..]\n Run various checks to determine potential problems with your environment.'
5757
DoctorCommand.params = '[categories..]';
5858
DoctorCommand.global = true;
59+
DoctorCommand.options = {
60+
'check-mem': {
61+
alias: 'mem-check',
62+
description: '[--no-check-mem] Enable/Disable memory availability checks',
63+
type: 'boolean',
64+
default: true
65+
}
66+
}
5967

6068
module.exports = DoctorCommand;

lib/commands/install.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ const path = require('path');
33
const Command = require('../command');
44
const symlinkSync = require('symlink-or-copy').sync;
55
const SetupCommand = require('./setup');
6+
const DoctorCommand = require('./doctor');
67

78
class InstallCommand extends Command {
89
static configureOptions(commandName, yargs, extensions) {
910
yargs = super.configureOptions(commandName, yargs, extensions);
11+
yargs = DoctorCommand.configureOptions('doctor', yargs, extensions, true);
1012
return SetupCommand.configureOptions('setup', yargs, extensions, true);
1113
}
1214

1315
run(argv) {
1416
const fs = require('fs-extra');
1517
const every = require('lodash/every');
1618
const errors = require('../errors');
17-
const DoctorCommand = require('./doctor');
1819
const yarnInstall = require('../tasks/yarn-install');
1920
const ensureStructure = require('../tasks/ensure-structure');
2021

lib/commands/start.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const Command = require('../command');
3+
const DoctorCommand = require('./doctor');
34

45
class StartCommand extends Command {
56
static configureOptions(commandName, yargs, extensions) {
@@ -15,11 +16,11 @@ class StartCommand extends Command {
1516
Object.assign(this.options, omit(options, Object.keys(this.options)));
1617
});
1718

18-
return super.configureOptions(commandName, yargs, extensions);
19+
yargs = super.configureOptions(commandName, yargs, extensions);
20+
return DoctorCommand.configureOptions('doctor', yargs, extensions, true);
1921
}
2022

2123
run(argv) {
22-
const DoctorCommand = require('./doctor');
2324
const ProcessManager = require('../process-manager');
2425

2526
const instance = this.system.getInstance();

lib/commands/update.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ const path = require('path');
55
// Utils
66
const errors = require('../errors');
77
const Command = require('../command');
8+
const DoctorCommand = require('./doctor');
89

910
class UpdateCommand extends Command {
11+
static configureOptions(commandName, yargs, extensions) {
12+
yargs = super.configureOptions(commandName, yargs, extensions);
13+
return DoctorCommand.configureOptions('doctor', yargs, extensions, true);
14+
}
15+
1016
run(argv) {
1117
const chalk = require('chalk');
1218
const semver = require('semver');
1319

14-
const DoctorCommand = require('./doctor');
1520
const MigrateCommand = require('./migrate');
1621
const migrate = require('../tasks/migrate');
1722

test/unit/commands/doctor/checks/check-memory-spec.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,43 @@ describe('Unit: Doctor Checks > Memory', function () {
1919

2020
expect(checkMem.title).to.equal('Checking memory availability');
2121
expect(checkMem.task).to.be.a('function');
22+
expect(checkMem.enabled).to.a('function');
2223
expect(checkMem.category).to.deep.equal(['install', 'start', 'update']);
2324
});
2425

25-
it('errors if not enough memory is available', function () {
26+
it('enabled is determined by check-mem argument', function () {
27+
const memCheck = require(modulePath);
28+
const ctx = {
29+
argv: {'check-mem': false}
30+
};
31+
32+
expect(memCheck.enabled(ctx)).to.be.false;
33+
ctx.argv['check-mem'] = true;
34+
expect(memCheck.enabled(ctx)).to.be.true;
35+
});
36+
37+
it('fails if not enough memory is available', function () {
2638
const osStub = sandbox.stub(os, 'freemem').returns(10);
2739
const memCheck = require(modulePath);
40+
const ctx = {
41+
argv: {'check-mem': true}
42+
};
2843

29-
return memCheck.task().catch((error) => {
44+
return memCheck.task(ctx).catch((error) => {
3045
expect(error).to.be.an.instanceof(errors.SystemError);
3146
expect(error.message).to.match(/MB of memory available for smooth operation/);
3247
expect(osStub.calledOnce).to.be.true;
3348
});
3449
});
3550

36-
it('works if there is enough memory', function () {
51+
it('passes if there is enough memory', function () {
3752
const osStub = sandbox.stub(os, 'freemem').returns(157286400);
3853
const memCheck = require(modulePath);
54+
const ctx = {
55+
argv: {'check-mem': true}
56+
};
3957

40-
return memCheck.task().then(() => {
58+
return memCheck.task(ctx).then(() => {
4159
expect(osStub.calledOnce).to.be.true;
4260
});
4361
});

test/unit/commands/install-spec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ const modulePath = '../../../lib/commands/install';
99
const errors = require('../../../lib/errors');
1010

1111
describe('Unit: Commands > Install', function () {
12-
it('configureOptions adds setup options as well', function () {
12+
it('configureOptions adds setup & doctor options', function () {
1313
const superStub = sinon.stub().returnsArg(1);
1414
const setupStub = sinon.stub().returnsArg(1);
15+
const doctorStub = sinon.stub().returnsArg(1);
1516

1617
// Needed for extension
1718
class Command {}
1819
Command.configureOptions = superStub;
1920

2021
const InstallCommand = proxyquire(modulePath, {
2122
'./setup': {configureOptions: setupStub},
23+
'./doctor': {configureOptions: doctorStub},
2224
'../command': Command
2325
});
2426

@@ -28,6 +30,8 @@ describe('Unit: Commands > Install', function () {
2830
expect(superStub.calledWithExactly('install', {yargs: true}, [{extensiona: true}])).to.be.true;
2931
expect(setupStub.calledOnce).to.be.true;
3032
expect(setupStub.calledWithExactly('setup', {yargs: true}, [{extensiona: true}], true)).to.be.true;
33+
expect(doctorStub.calledOnce).to.be.true;
34+
expect(doctorStub.calledWithExactly('doctor', {yargs: true}, [{extensiona: true}], true)).to.be.true;
3135
});
3236

3337
describe('run', function () {

test/unit/commands/start-spec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,11 @@ describe('Unit: Commands > Start', function () {
219219
});
220220
});
221221

222-
// @todo: Add more tests if necessary
223222
it('configureOptions loops over extensions', function () {
223+
const doctorStub = sinon.stub().returnsArg(1);
224+
const StartCommand = proxyquire(modulePath, {
225+
'./doctor': {configureOptions: doctorStub}
226+
});
224227
const extensions = [{
225228
config: {options: {start: {test: true}}}
226229
}, {}];
@@ -230,5 +233,6 @@ describe('Unit: Commands > Start', function () {
230233
StartCommand.configureOptions.call({options: {}}, 'Test', yargs, extensions, true);
231234
expect(yargs.option.called).to.be.true;
232235
expect(yargs.option.args[0][0]).to.equal('test');
236+
expect(doctorStub.calledOnce).to.be.true;
233237
});
234238
});

test/unit/commands/update-spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ const errors = require('../../../lib/errors');
1313
const Instance = require('../../../lib/instance');
1414

1515
describe('Unit: Commands > Update', function () {
16+
it('configureOptions adds setup & doctor options', function () {
17+
const superStub = sinon.stub().returnsArg(1);
18+
const doctorStub = sinon.stub().returnsArg(1);
19+
20+
// Needed for extension
21+
class Command {}
22+
Command.configureOptions = superStub;
23+
24+
const InstallCommand = proxyquire(modulePath, {
25+
'./doctor': {configureOptions: doctorStub},
26+
'../command': Command
27+
});
28+
29+
const result = InstallCommand.configureOptions('install', {yargs: true}, [{extensiona: true}]);
30+
expect(result).to.deep.equal({yargs: true});
31+
expect(superStub.calledOnce).to.be.true;
32+
expect(superStub.calledWithExactly('install', {yargs: true}, [{extensiona: true}])).to.be.true;
33+
});
34+
1635
describe('run', function () {
1736
it('doesn\'t run tasks if no new versions are available', function () {
1837
const UpdateCommand = require(modulePath);

0 commit comments

Comments
 (0)