11"use strict" ;
22
3- describe ( "test.issue7810.js" , function ( ) {
4- var adapter = testUtils . adapterType ( ) ;
5- var dbs = { } ;
3+ describe ( "test.issue7810.js" , ( ) => {
4+ const adapter = testUtils . adapterType ( ) ;
5+ const dbs = { } ;
66
77 const docData = {
88 _id : "foobar" ,
@@ -12,16 +12,13 @@ describe("test.issue7810.js", function () {
1212 indexedPairTwo : 'bar'
1313 } ;
1414
15- function findInDbs ( query ) {
16- return dbs . withIndex . find ( query ) . then ( ( withIndexResults ) =>
17- dbs . withoutIndex . find ( query ) . then ( ( withoutIndexResults ) => ( {
18- withIndexResults,
19- withoutIndexResults,
20- } ) )
21- ) ;
22- }
15+ const findInDbs = async ( query ) => {
16+ const withIndexResults = await dbs . withIndex . find ( query ) ;
17+ const withoutIndexResults = await dbs . withoutIndex . find ( query ) ;
18+ return { withIndexResults, withoutIndexResults } ;
19+ } ;
2320
24- function createIndicesAndPutData ( ) {
21+ const createIndicesAndPutData = ( ) => {
2522 return Promise . all ( [
2623 dbs . withIndex . createIndex ( {
2724 index : {
@@ -39,9 +36,9 @@ describe("test.issue7810.js", function () {
3936 dbs . withIndex . put ( docData ) ,
4037 dbs . withoutIndex . put ( docData ) ,
4138 ] ) ;
42- }
39+ } ;
4340
44- function assertWithAndWithoutLengthOf ( results , docLen ) {
41+ const assertWithAndWithoutLengthOf = ( results , docLen ) => {
4542 const { withIndexResults, withoutIndexResults } = results ;
4643 const withIndexDocs = withIndexResults . docs . length ;
4744 const withoutIndexDocs = withoutIndexResults . docs . length ;
@@ -53,148 +50,121 @@ describe("test.issue7810.js", function () {
5350 const suffix = docLen === 1 ? '' : 's' ;
5451 withIndexDocs . should . equal ( docLen , `indexed should return ${ docLen } doc${ suffix } ` ) ;
5552 withoutIndexDocs . should . equal ( docLen , `non-indexed should return ${ docLen } doc${ suffix } ` ) ;
56- }
53+ } ;
5754
58- beforeEach ( function ( ) {
55+ beforeEach ( async ( ) => {
5956 dbs . withIndexName = testUtils . adapterUrl ( adapter , "with_index" ) ;
6057 dbs . withoutIndexName = testUtils . adapterUrl ( adapter , "without_index" ) ;
6158 dbs . withIndex = new PouchDB ( dbs . withIndexName ) ;
6259 dbs . withoutIndex = new PouchDB ( dbs . withoutIndexName ) ;
6360
64- return createIndicesAndPutData ( ) ;
61+ await createIndicesAndPutData ( ) ;
6562 } ) ;
6663
67- afterEach ( function ( done ) {
64+ afterEach ( ( done ) => {
6865 testUtils . cleanup ( [ dbs . withIndexName , dbs . withoutIndexName ] , done ) ;
6966 } ) ;
7067
71- it ( "Testing issue #7810 with selector {} - should return 1 doc" , function ( ) {
72- var query = {
68+ it ( "Testing issue #7810 with selector {} - should return 1 doc" , async ( ) => {
69+ const query = {
7370 selector : { } ,
7471 limit : 1 ,
7572 } ;
76- return findInDbs ( query ) . then (
77- ( results ) => {
78- assertWithAndWithoutLengthOf ( results , 1 ) ;
79- }
80- ) ;
73+ const results = await findInDbs ( query ) ;
74+ assertWithAndWithoutLengthOf ( results , 1 ) ;
8175 } ) ;
8276
83- it ( "Testing issue #7810 with selector { _id: {} } - should return 0 docs" , function ( ) {
84- var query = {
77+ it ( "Testing issue #7810 with selector { _id: {} } - should return 0 docs" , async ( ) => {
78+ const query = {
8579 selector : {
8680 _id : { } ,
8781 } ,
8882 limit : 1 ,
8983 } ;
90- return findInDbs ( query ) . then (
91- ( results ) => {
92- assertWithAndWithoutLengthOf ( results , 0 ) ;
93- }
94- ) ;
84+ const results = await findInDbs ( query ) ;
85+ assertWithAndWithoutLengthOf ( results , 0 ) ;
9586 } ) ;
9687
97- it ( "Testing issue #7810 with selector { indexedField: {} } - should return 0 docs" , function ( ) {
98- var query = {
88+ it ( "Testing issue #7810 with selector { indexedField: {} } - should return 0 docs" , async ( ) => {
89+ const query = {
9990 selector : {
10091 indexedField : { } ,
10192 } ,
10293 limit : 1 ,
10394 } ;
104- return findInDbs ( query ) . then (
105- ( results ) => {
106- assertWithAndWithoutLengthOf ( results , 0 ) ;
107- }
108- ) ;
95+ const results = await findInDbs ( query ) ;
96+ assertWithAndWithoutLengthOf ( results , 0 ) ;
10997 } ) ;
11098
111- it ( "Testing issue #7810 with selector { _id: 'foobar'} - should return 1 doc" , function ( ) {
112- var query = {
99+ it ( "Testing issue #7810 with selector { _id: 'foobar'} - should return 1 doc" , async ( ) => {
100+ const query = {
113101 selector : {
114102 _id : "foobar" ,
115103 } ,
116104 limit : 1 ,
117105 } ;
118- return findInDbs ( query ) . then (
119- ( results ) => {
120- assertWithAndWithoutLengthOf ( results , 1 ) ;
121- }
122- ) ;
106+ const results = await findInDbs ( query ) ;
107+ assertWithAndWithoutLengthOf ( results , 1 ) ;
123108 } ) ;
124109
125- it ( "Testing issue #7810 with selector { indexedField: 'foobaz' } - should return 1 doc" , function ( ) {
126- var query = {
110+ it ( "Testing issue #7810 with selector { indexedField: 'foobaz' } - should return 1 doc" , async ( ) => {
111+ const query = {
127112 selector : {
128113 indexedField : "foobaz" ,
129114 } ,
130115 limit : 1 ,
131116 } ;
132- return findInDbs ( query ) . then (
133- ( results ) => {
134- assertWithAndWithoutLengthOf ( results , 1 ) ;
135- }
136- ) ;
117+ const results = await findInDbs ( query ) ;
118+ assertWithAndWithoutLengthOf ( results , 1 ) ;
137119 } ) ;
138120
139- it ( "Testing issue #7810 with selector { numericField: 1337} - should return 1 doc" , function ( ) {
140- var query = {
121+ it ( "Testing issue #7810 with selector { numericField: 1337} - should return 1 doc" , async ( ) => {
122+ const query = {
141123 selector : {
142124 numericField : 1337 ,
143125 } ,
144126 limit : 1 ,
145127 } ;
146- return findInDbs ( query ) . then (
147- ( results ) => {
148- assertWithAndWithoutLengthOf ( results , 1 ) ;
149- }
150- ) ;
128+ const results = await findInDbs ( query ) ;
129+ assertWithAndWithoutLengthOf ( results , 1 ) ;
151130 } ) ;
152131
153- it ( "Testing issue #7810 with selector { numericField: 404 } - should return 0 docs" , function ( ) {
154- var query = {
132+ it ( "Testing issue #7810 with selector { numericField: 404 } - should return 0 docs" , async ( ) => {
133+ const query = {
155134 selector : {
156135 numericField : 404 ,
157136 } ,
158137 limit : 1 ,
159138 } ;
160- return findInDbs ( query ) . then (
161- ( results ) => {
162- assertWithAndWithoutLengthOf ( results , 0 ) ;
163- }
164- ) ;
139+ const results = await findInDbs ( query ) ;
140+ assertWithAndWithoutLengthOf ( results , 0 ) ;
165141 } ) ;
166142
167143
168- it ( "Testing issue #7810 with selector { indexedPairOne: 'foo' } - should return 1 docs" , function ( ) {
169- var query = {
144+ it ( "Testing issue #7810 with selector { indexedPairOne: 'foo' } - should return 1 docs" , async ( ) => {
145+ const query = {
170146 selector : {
171147 indexedPairOne : 'foo' ,
172148 } ,
173149 limit : 1 ,
174150 } ;
175- return findInDbs ( query ) . then (
176- ( results ) => {
177- assertWithAndWithoutLengthOf ( results , 1 ) ;
178- }
179- ) ;
151+ const results = await findInDbs ( query ) ;
152+ assertWithAndWithoutLengthOf ( results , 1 ) ;
180153 } ) ;
181154
182- it ( "Testing issue #7810 with selector { indexedPairOne: 'baz' } - should return 0 docs" , function ( ) {
183- var query = {
155+ it ( "Testing issue #7810 with selector { indexedPairOne: 'baz' } - should return 0 docs" , async ( ) => {
156+ const query = {
184157 selector : {
185158 indexedPairOne : 'baz'
186159 } ,
187160 limit : 1 ,
188161 } ;
189- return findInDbs ( query ) . then (
190- ( results ) => {
191- assertWithAndWithoutLengthOf ( results , 0 ) ;
192- }
193- ) ;
162+ const results = await findInDbs ( query ) ;
163+ assertWithAndWithoutLengthOf ( results , 0 ) ;
194164 } ) ;
195165
196- it ( "Testing issue #7810 with selector {} - should return 1 out of 2 docs" , function ( ) {
197- var query = {
166+ it ( "Testing issue #7810 with selector {} - should return 1 out of 2 docs" , async ( ) => {
167+ const query = {
198168 selector : { } ,
199169 limit : 1 ,
200170 } ;
@@ -205,15 +175,11 @@ describe("test.issue7810.js", function () {
205175 indexedPairOne : 'bob' ,
206176 indexedPairTwo : 'david'
207177 } ;
208- return Promise . all ( [
178+ await Promise . all ( [
209179 dbs . withIndex . put ( otherDoc ) ,
210180 dbs . withoutIndex . put ( otherDoc )
211- ] ) . then ( function ( ) {
212- return findInDbs ( query ) . then (
213- ( results ) => {
214- assertWithAndWithoutLengthOf ( results , 1 ) ;
215- }
216- ) ;
217- } ) ;
181+ ] ) ;
182+ const results = await findInDbs ( query ) ;
183+ assertWithAndWithoutLengthOf ( results , 1 ) ;
218184 } ) ;
219185} ) ;
0 commit comments