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: #3737 #3738

Merged
merged 1 commit into from Sep 14, 2021
Merged
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
2 changes: 1 addition & 1 deletion lib/search/format-package-stream.js
Expand Up @@ -42,7 +42,7 @@ class JSONOutputStream extends Minipass {
}

end () {
super.write(this._didFirst ? ']\n' : '\n]\n')
super.write(this._didFirst ? ']\n' : '\n[]\n')
super.end()
}
}
Expand Down
31 changes: 31 additions & 0 deletions test/lib/search.js
Expand Up @@ -130,6 +130,37 @@ t.test('search <name> --json', (t) => {
src.end()
})

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

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

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

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

t.equal(result, '\n[]\n', 'should have expected empty square brackets')

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

src.end()
})

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