Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cb() never called in search with --json option #2831

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -80,6 +80,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