Skip to content

Commit e0a3a52

Browse files
fraqewraithgar
authored andcommitted
Fix cb() never called in search with --json option
PR-URL: #2831 Credit: @fraqe Close: #2831 Reviewed-by: @isaacs
1 parent 9fe0df5 commit e0a3a52

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Diff for: lib/search/format-package-stream.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class JSONOutputStream extends Minipass {
4343

4444
end () {
4545
super.write(this._didFirst ? ']\n' : '\n]\n')
46+
super.end()
4647
}
4748
}
4849

Diff for: test/lib/search.js

+42
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,48 @@ t.test('search <name>', t => {
8282
src.end()
8383
})
8484

85+
t.test('search <name> --json', (t) => {
86+
const src = new Minipass()
87+
src.objectMode = true
88+
89+
flatOptions.json = true
90+
const libnpmsearch = {
91+
stream () {
92+
return src
93+
},
94+
}
95+
96+
const Search = requireInject('../../lib/search.js', {
97+
...mocks,
98+
libnpmsearch,
99+
})
100+
const search = new Search(npm)
101+
102+
search.exec(['libnpm'], (err) => {
103+
if (err)
104+
throw err
105+
106+
const parsedResult = JSON.parse(result)
107+
parsedResult.forEach((entry) => {
108+
entry.date = new Date(entry.date)
109+
})
110+
111+
t.same(
112+
parsedResult,
113+
libnpmsearchResultFixture,
114+
'should have expected search results as json'
115+
)
116+
117+
flatOptions.json = false
118+
t.end()
119+
})
120+
121+
for (const i of libnpmsearchResultFixture)
122+
src.write(i)
123+
124+
src.end()
125+
})
126+
85127
t.test('search <name> --searchexclude --searchopts', t => {
86128
npm.flatOptions.search = {
87129
...flatOptions.search,

0 commit comments

Comments
 (0)