File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+
85127t . test ( 'search <name> --searchexclude --searchopts' , t => {
86128 npm . flatOptions . search = {
87129 ...flatOptions . search ,
You can’t perform that action at this time.
0 commit comments