@@ -120,21 +120,23 @@ function tests(suiteName, dbName, dbType, viewType) {
120120 } ) ;
121121
122122 if ( dbType === 'local' && viewType === 'temp' ) {
123- it ( "with a closure" , function ( ) {
123+ it ( "with a closure" , async function ( ) {
124124 const db = new PouchDB ( dbName ) ;
125- return db . bulkDocs ( { docs : [
125+ await db . bulkDocs ( { docs : [
126126 { foo : 'bar' } ,
127127 { _id : 'volatile' , foo : 'baz' }
128- ] } ) . then ( function ( ) {
129- const queryFun = ( function ( test ) {
130- return function ( doc , emit ) {
131- if ( doc . _id === test ) {
132- emit ( doc . foo ) ;
133- }
134- } ;
135- } ( 'volatile' ) ) ;
136- return db . query ( queryFun , { reduce : false } ) ;
137- } ) . should . become ( {
128+ ] } ) ;
129+
130+ const queryFun = ( function ( test ) {
131+ return function ( doc , emit ) {
132+ if ( doc . _id === test ) {
133+ emit ( doc . foo ) ;
134+ }
135+ } ;
136+ } ( 'volatile' ) ) ;
137+
138+ const res = await db . query ( queryFun , { reduce : false } ) ;
139+ res . should . deep . equal ( {
138140 total_rows : 1 ,
139141 offset : 0 ,
140142 rows : [
@@ -147,47 +149,45 @@ function tests(suiteName, dbName, dbType, viewType) {
147149 } ) ;
148150 } ) ;
149151 }
150- if ( viewType === 'temp' && dbType !== 'http' ) {
151152
152- it ( 'Test simultaneous temp views' , function ( ) {
153+ if ( viewType === 'temp' && dbType !== 'http' ) {
154+ it ( 'Test simultaneous temp views' , async function ( ) {
153155 const db = new PouchDB ( dbName ) ;
154- return db . put ( { _id : '0' , foo : 1 , bar : 2 , baz : 3 } ) . then ( function ( ) {
155- return Promise . all ( [ 'foo' , 'bar' , 'baz' ] . map ( function ( key , i ) {
156- const fun = 'function(doc){emit(doc.' + key + ');}' ;
157- return db . query ( { map : fun } ) . then ( function ( res ) {
158- res . rows . should . deep . equal ( [ {
159- id : '0' ,
160- key : i + 1 ,
161- value : null
162- } ] ) ;
163- } ) ;
164- } ) ) ;
165- } ) ;
156+ await db . put ( { _id : '0' , foo : 1 , bar : 2 , baz : 3 } ) ;
157+
158+ await Promise . all ( [ 'foo' , 'bar' , 'baz' ] . map ( async ( key , i ) => {
159+ const fun = 'function(doc){emit(doc.' + key + ');}' ;
160+ const res = await db . query ( { map : fun } ) ;
161+
162+ res . rows . should . deep . equal ( [ {
163+ id : '0' ,
164+ key : i + 1 ,
165+ value : null
166+ } ] ) ;
167+ } ) ) ;
166168 } ) ;
167169
168- it ( "Test passing just a function" , function ( ) {
170+ it ( "Test passing just a function" , async function ( ) {
169171 const db = new PouchDB ( dbName ) ;
170- return db . bulkDocs ( { docs : [
172+ await db . bulkDocs ( { docs : [
171173 { foo : 'bar' } ,
172174 { _id : 'volatile' , foo : 'baz' }
173- ] } ) . then ( function ( ) {
174- return db . get ( 'volatile' ) ;
175- } ) . then ( function ( doc ) {
176- return db . remove ( doc ) ;
177- } ) . then ( function ( ) {
178- return db . query ( function ( doc ) {
179- emit ( doc . foo , doc ) ;
180- } , { include_docs : true , reduce : false } ) ;
181- } ) . then ( function ( res ) {
182- res . rows . should . have . length ( 1 , 'Dont include deleted documents' ) ;
183- res . rows . forEach ( function ( x ) {
184- should . exist ( x . id ) ;
185- should . exist ( x . key ) ;
186- should . exist ( x . value ) ;
187- should . exist ( x . value . _rev ) ;
188- should . exist ( x . doc ) ;
189- should . exist ( x . doc . _rev ) ;
190- } ) ;
175+ ] } ) ;
176+ const doc = await db . get ( 'volatile' ) ;
177+ await db . remove ( doc ) ;
178+
179+ const res = await db . query ( { map :( doc ) =>
180+ emit ( doc . foo , doc ) } ,
181+ { include_docs : true , reduce : false } ) ;
182+
183+ res . rows . should . have . length ( 1 , 'Dont include deleted documents' ) ;
184+ res . rows . forEach ( ( x ) => {
185+ should . exist ( x . id ) ;
186+ should . exist ( x . key ) ;
187+ should . exist ( x . value ) ;
188+ should . exist ( x . value . _rev ) ;
189+ should . exist ( x . doc ) ;
190+ should . exist ( x . doc . _rev ) ;
191191 } ) ;
192192 } ) ;
193193 }
0 commit comments