Skip to content

Commit aae31be

Browse files
fix: remove extra warning on unset deprecated option
1 parent 75f3c2a commit aae31be

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/core.js

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function option({
3232
: defaultValue;
3333
} else if (!isDeprecated) {
3434
throw new MissingOptionError(locator.name);
35+
} else {
36+
isSetByUser = false;
3537
}
3638

3739
if (isSetByUser && isDeprecated) {

test/option.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
const sinon = require('sinon');
12
const {option} = require('../lib/core');
23
const {MissingOptionError} = require('../lib/errors');
34

45
describe('option', () => {
6+
let consoleWarnStub;
7+
8+
beforeEach(() => {
9+
consoleWarnStub = sinon.stub(console, 'warn');
10+
});
11+
12+
afterEach(() => {
13+
consoleWarnStub.restore();
14+
});
15+
516
const LAZY_CONFIG = {
617
root: {defaultKey: 'defaultValue'}
718
};
@@ -155,6 +166,18 @@ describe('option', () => {
155166
const parser = option({isDeprecated: true});
156167
assert.doesNotThrow(() => parser({}, LAZY_CONFIG), MissingOptionError);
157168
});
169+
170+
it('should not log warning on deprecated option without any value', () => {
171+
option({isDeprecated: true})({}, LAZY_CONFIG);
172+
173+
assert.notCalled(consoleWarnStub);
174+
});
175+
});
176+
177+
it('should log warning on deprecated option if option is set', () => {
178+
option({isDeprecated: true})({envVar: 'foo'}, LAZY_CONFIG);
179+
180+
assert.calledWith(consoleWarnStub, sinon.match('option is deprecated'));
158181
});
159182

160183
function testAfterParseCallback(name) {

0 commit comments

Comments
 (0)