Skip to content

Commit

Permalink
Fix cb() never called in search with --json option
Browse files Browse the repository at this point in the history
PR-URL: #2831
Credit: @fraqe
Close: #2831
Reviewed-by: @isaacs
  • Loading branch information
fraqe authored and wraithgar committed Mar 9, 2021
1 parent 9fe0df5 commit e0a3a52
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/search/format-package-stream.js
Expand Up @@ -43,6 +43,7 @@ class JSONOutputStream extends Minipass {

end () {
super.write(this._didFirst ? ']\n' : '\n]\n')
super.end()
}
}

Expand Down
42 changes: 42 additions & 0 deletions test/lib/search.js
Expand Up @@ -82,6 +82,48 @@ t.test('search <name>', t => {
src.end()
})

t.test('search <name> --json', (t) => {
const src = new Minipass()
src.objectMode = true

flatOptions.json = true
const libnpmsearch = {
stream () {
return src
},
}

const Search = requireInject('../../lib/search.js', {
...mocks,
libnpmsearch,
})
const search = new Search(npm)

search.exec(['libnpm'], (err) => {
if (err)
throw err

const parsedResult = JSON.parse(result)
parsedResult.forEach((entry) => {
entry.date = new Date(entry.date)
})

t.same(
parsedResult,
libnpmsearchResultFixture,
'should have expected search results as json'
)

flatOptions.json = false
t.end()
})

for (const i of libnpmsearchResultFixture)
src.write(i)

src.end()
})

t.test('search <name> --searchexclude --searchopts', t => {
npm.flatOptions.search = {
...flatOptions.search,
Expand Down

0 comments on commit e0a3a52

Please sign in to comment.