Skip to content

Commit

Permalink
test: improve error messaging and add more tests to enjoyBy feature
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Oct 30, 2018
1 parent b0ea20a commit 96410c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Expand Up @@ -83,7 +83,13 @@ function pickManifest (packument, wanted, opts) {
)
if (!manifest) {
err = new Error(
`No matching version found for ${packument.name}@${wanted}`
`No matching version found for ${packument.name}@${wanted}${
opts.enjoyBy
? ` with an Enjoy By date of ${
new Date(opts.enjoyBy).toLocaleString()
}. Maybe try a different date?`
: ''
}`
)
err.code = 'ETARGET'
err.name = packument.name
Expand Down
10 changes: 10 additions & 0 deletions test/index.js
Expand Up @@ -289,5 +289,15 @@ test('accepts opts.enjoyBy option to do date-based cutoffs', t => {
enjoyBy: '2018-01-02'
})
t.equal(manifest.version, '2.0.0', 'filtered out 3.0.0 because of dates')
t.throws(() => {
pickManifest(metadata, '3.0.0', {
enjoyBy: '2018-01-02'
})
}, /Enjoy By date of/, 'trying to find by out-of-range version breaks')
t.throws(() => {
pickManifest(metadata, 'latest', {
enjoyBy: '2018-01-02'
})
}, /Enjoy By date of/, 'trying to find by tag breaks if date is out of range')
t.done()
})

0 comments on commit 96410c4

Please sign in to comment.