-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle null values for dependency objects
the current GitHub npm package registry returns packuments where the various dependency objects are set to a null literal which causes the destructuring defaults to not apply, so we should guard against that for a bit of added safety here.
- Loading branch information
Showing
2 changed files
with
32 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,44 @@ | ||
const t = require('tap') | ||
const getDepSpec = require('../lib/get-dep-spec.js') | ||
|
||
t.equal(getDepSpec({ dependencies: { dep: '1' } }, 'dep'), '1') | ||
t.equal(getDepSpec({ optionalDependencies: { dep: '1' } }, 'dep'), '1') | ||
t.equal(getDepSpec({ peerDependencies: { dep: '1' } }, 'dep'), '1') | ||
t.equal(getDepSpec({ | ||
dependencies: { dep: '1' } | ||
}, 'dep'), '1') | ||
|
||
t.equal(getDepSpec({ | ||
optionalDependencies: { dep: '1' } | ||
}, 'dep'), '1') | ||
|
||
t.equal(getDepSpec({ | ||
dependencies: null, | ||
optionalDependencies: { dep: '1' } | ||
}, 'dep'), '1', 'allows dependencies to be null') | ||
|
||
t.equal(getDepSpec({ | ||
peerDependencies: { dep: '1' } | ||
}, 'dep'), '1') | ||
|
||
t.equal(getDepSpec({ | ||
dependencies: null, | ||
optioanlDependencies: null, | ||
peerDependencies: { dep: '1' } | ||
}, 'dep'), '1', 'allows optionalDependencies to be null') | ||
|
||
t.equal(getDepSpec({ | ||
dependencies: { dep: '1' }, | ||
optionalDependencies: { dep: '2' }, | ||
}, 'dep'), '1', 'prefer prod deps over optional') | ||
|
||
t.equal(getDepSpec({ | ||
dependencies: { dep: '1' }, | ||
peerDependencies: { dep: '2' }, | ||
}, 'dep'), '1', 'prefer prod deps over peer') | ||
|
||
t.equal(getDepSpec({ | ||
optionalDependencies: { dep: '1' }, | ||
peerDependencies: { dep: '2' }, | ||
}, 'dep'), '1', 'prefer optional deps over peer') | ||
t.equal(getDepSpec({ devDependencies: { dep: '1' } }, 'dep'), null, | ||
'ignore dev') | ||
|
||
t.equal(getDepSpec({ | ||
devDependencies: { dep: '1' } | ||
}, 'dep'), null, 'ignore dev') |