Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ASK_SKIP_NEW_VERSION_REMINDER to enable skipping version ch… #160

Merged
merged 2 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/commands/abstract-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class AbstractCommand {
metricClient.startAction(commandInstance._name, 'command');

// Check if a new CLI version is released
this._remindsIfNewVersion(commandInstance.debug, () => {
this._remindsIfNewVersion(commandInstance.debug, process.env.ASK_SKIP_NEW_VERSION_REMINDER, () => {
try {
this._validateOptions(commandInstance);

Expand Down Expand Up @@ -179,7 +179,9 @@ class AbstractCommand {
}
}

_remindsIfNewVersion(doDebug, callback) {
_remindsIfNewVersion(doDebug, skip, callback) {
if (skip) return callback();

httpClient.request({
url: `${CONSTANTS.NPM_REGISTRY_URL_BASE}/${CONSTANTS.APPLICATION_NAME}/latest`,
method: CONSTANTS.HTTP_REQUEST.VERB.GET
Expand Down
21 changes: 16 additions & 5 deletions test/unit/commands/abstract-command-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Command test - AbstractCommand class', () => {
mockProcessExit = sinon.stub(process, 'exit');
mockConsoleError = sinon.stub(console, 'error');
sinon.stub(metricClient, 'sendData').resolves();
sinon.stub(AbstractCommand.prototype, '_remindsIfNewVersion').callsArgWith(1);
sinon.stub(AbstractCommand.prototype, '_remindsIfNewVersion').callsArgWith(2);
});

it('| should be able to register command', async () => {
Expand Down Expand Up @@ -311,11 +311,22 @@ describe('Command test - AbstractCommand class', () => {
sinon.restore();
});

it('| skip is set, should skip version check', (done) => {
// setup
const skip = true;
// call
AbstractCommand.prototype._remindsIfNewVersion(TEST_DO_DEBUG_FALSE, skip, () => {
// verify
expect(httpClient.request.called).equal(false);
done();
});
});

it('| http client request error, should warn it out and pass the process', (done) => {
// setup
httpClient.request.callsArgWith(3, TEST_HTTP_ERROR);
// call
AbstractCommand.prototype._remindsIfNewVersion(TEST_DO_DEBUG_FALSE, (err) => {
AbstractCommand.prototype._remindsIfNewVersion(TEST_DO_DEBUG_FALSE, undefined, (err) => {
// verify
expect(httpClient.request.args[0][0].url).equal(
`${CONSTANTS.NPM_REGISTRY_URL_BASE}/${CONSTANTS.APPLICATION_NAME}/latest`
Expand All @@ -334,7 +345,7 @@ describe('Command test - AbstractCommand class', () => {
const latestVersion = `${currentMajor + 1}.0.0`;
httpClient.request.callsArgWith(3, null, TEST_NPM_REGISTRY_DATA(latestVersion));
// call
AbstractCommand.prototype._remindsIfNewVersion(TEST_DO_DEBUG_FALSE, (err) => {
AbstractCommand.prototype._remindsIfNewVersion(TEST_DO_DEBUG_FALSE, undefined, (err) => {
// verify
expect(httpClient.request.args[0][0].url).equal(
`${CONSTANTS.NPM_REGISTRY_URL_BASE}/${CONSTANTS.APPLICATION_NAME}/latest`
Expand All @@ -355,7 +366,7 @@ It is recommended to use the latest version. Please update using "npm upgrade -g
const latestVersion = `${currentMajor}.${currentMinor + 1}.0`;
httpClient.request.callsArgWith(3, null, TEST_NPM_REGISTRY_DATA(latestVersion));
// call
AbstractCommand.prototype._remindsIfNewVersion(TEST_DO_DEBUG_FALSE, (err) => {
AbstractCommand.prototype._remindsIfNewVersion(TEST_DO_DEBUG_FALSE, undefined, (err) => {
// verify
expect(httpClient.request.args[0][0].url).equal(
`${CONSTANTS.NPM_REGISTRY_URL_BASE}/${CONSTANTS.APPLICATION_NAME}/latest`
Expand All @@ -375,7 +386,7 @@ It is recommended to use the latest version. Please update using "npm upgrade -g
// setup
httpClient.request.callsArgWith(3, null, TEST_NPM_REGISTRY_DATA(`${currentMajor}.${currentMinor}.0`));
// call
AbstractCommand.prototype._remindsIfNewVersion(TEST_DO_DEBUG_FALSE, (err) => {
AbstractCommand.prototype._remindsIfNewVersion(TEST_DO_DEBUG_FALSE, undefined, (err) => {
// verify
expect(httpClient.request.args[0][0].url).equal(
`${CONSTANTS.NPM_REGISTRY_URL_BASE}/${CONSTANTS.APPLICATION_NAME}/latest`
Expand Down