Skip to content

Commit

Permalink
fix: remove extra warning on unset deprecated option
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovRoman committed Sep 3, 2024
1 parent 75f3c2a commit 448b9a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function option({
: defaultValue;
} else if (!isDeprecated) {
throw new MissingOptionError(locator.name);
} else {
isSetByUser = false;
}

if (isSetByUser && isDeprecated) {
Expand Down
23 changes: 23 additions & 0 deletions test/option.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
const sinon = require('sinon');
const {option} = require('../lib/core');
const {MissingOptionError} = require('../lib/errors');

describe('option', () => {
let consoleWarnStub;

beforeEach(() => {
consoleWarnStub = sinon.stub(console, 'warn');
});

afterEach(() => {
consoleWarnStub.restore();
});

const LAZY_CONFIG = {
root: {defaultKey: 'defaultValue'}
};
Expand Down Expand Up @@ -155,6 +166,18 @@ describe('option', () => {
const parser = option({isDeprecated: true});
assert.doesNotThrow(() => parser({}, LAZY_CONFIG), MissingOptionError);
});

it('should not log warning on deprecated option', () => {
option({isDeprecated: true})({}, LAZY_CONFIG);

assert.notCalled(consoleWarnStub);
});
});

it('should log warning on deprecated option if option is set', () => {
option({isDeprecated: true})({envVar: 'foo'}, LAZY_CONFIG);

assert.calledWith(consoleWarnStub, sinon.match('option is deprecated'));
});

function testAfterParseCallback(name) {
Expand Down

0 comments on commit 448b9a8

Please sign in to comment.