Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #24 from bugsnag/boolean-args
Browse files Browse the repository at this point in the history
Better handling of boolean arguments
  • Loading branch information
bengourley authored Aug 1, 2018
2 parents 08ee643 + 4d11f1a commit 04e2846
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ const cli = meow(`
string: [
'app-version',
],
boolean: [
'overwrite',
'upload-node-modules',
'upload-sources',
'add-wildcard-prefix',
],
});

const conf = {
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ function prepareRequest(options) {
case 'tempDir': {
break;
}
case 'overwrite': {
// the presence of any value for this flag causes the API to interpret it as
// true, so only add it to the payload if it is truthy
if (options.overwrite) {
formData[name] = String(value);
}
break;
}
// Basic fields (strings/booleans) & future fields
default: {
formData[name] = String(value);
Expand Down
10 changes: 10 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const stripProjectRoot = require('./index').stripProjectRoot
const upload = require('./index').upload
const validateOptions = require('./index').validateOptions
const prepareRequest = require('./index').prepareRequest

test('upload function exists', () => {
expect(typeof upload).toBe('function');
Expand Down Expand Up @@ -71,3 +72,12 @@ describe('validateOptions', () => {
}).toThrow('You must provide a path to the source map you want to upload.');
});
});

describe('prepareRequest', () => {
test('removes options.overwrite when false', () => {
expect(prepareRequest({ overwrite: false }).formData).toEqual({});
});
test('does not remove options.overwrite when true', () => {
expect(prepareRequest({ overwrite: true }).formData).toEqual({ overwrite: 'true' });
});
});

0 comments on commit 04e2846

Please sign in to comment.