Skip to content
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
5 changes: 4 additions & 1 deletion src/helpers/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export const convertOptionsFromArguments = options => {
value = JSON.parse(value);
}

if (option.type === 'string' && !value) {
if (
(option.type === 'string' && !value) ||
(option.type !== 'boolean' && typeof value === 'boolean')
) {
value = undefined;
}

Expand Down
22 changes: 21 additions & 1 deletion src/helpers/arguments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ describe('convertOptionsFromArguments', () => {
process.argv = [
'/usr/local/bin/node',
'lighthouse-check',
'--verbose',
'--ipsum',
'lorem',
'--hello',
'world',
'--foo',
'bar'
'bar',
'--some-string'
];
});

Expand Down Expand Up @@ -63,6 +65,24 @@ describe('convertOptionsFromArguments', () => {
expect(actual).toEqual(expected);
});

it('should treat explicitly defined boolean types as "true" when a value is empty', () => {
const actual = convertOptionsFromArguments({
verbose: {
type: 'boolean'
}
});
expect(actual.verbose).toEqual(true);
});

it('should ignore empty flag values that are not explicitly defined as boolean types', () => {
const actual = convertOptionsFromArguments({
'some-string': {
type: 'string'
}
});
expect(actual['some-string']).toBeUndefined();
});

it('should create correct types from CLI string argument', () => {
const options = convertOptionsFromArguments({
myEmptyString: {
Expand Down