File tree 2 files changed +43
-0
lines changed
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 {
43
43
44
44
end ( ) {
45
45
super . write ( this . _didFirst ? ']\n' : '\n]\n' )
46
+ super . end ( )
46
47
}
47
48
}
48
49
Original file line number Diff line number Diff line change @@ -82,6 +82,48 @@ t.test('search <name>', t => {
82
82
src . end ( )
83
83
} )
84
84
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
+
85
127
t . test ( 'search <name> --searchexclude --searchopts' , t => {
86
128
npm . flatOptions . search = {
87
129
...flatOptions . search ,
You can’t perform that action at this time.
0 commit comments