22
33describe ( 'migration' , function ( ) {
44
5- function usingDefaultPreferredAdapters ( ) {
5+ function usingIdb ( ) {
66 var pref = PouchDB . preferredAdapters ;
77 // Firefox will have ['idb'], Chrome will have ['idb', 'websql']
88 return ( pref . length === 1 && pref [ 0 ] === 'idb' ) ||
99 ( pref . length === 2 && pref [ 0 ] === 'idb' && pref [ 1 ] === 'websql' ) ;
1010 }
1111
12+ function usingIndexeddb ( ) {
13+ const pref = PouchDB . preferredAdapters ;
14+ // FUTURE: treat indexeddb adapter as the preferred option?
15+ return pref . length === 1 && pref [ 0 ] === 'indexeddb' ;
16+ }
17+
18+ function usingDefaultPreferredAdapters ( ) {
19+ return usingIdb ( ) || usingIndexeddb ( ) ;
20+ }
21+
1222 const scenarios = [
1323 { scenario : 'PouchDB v1.1.0' , constructorName : 'PouchDBVersion110' } ,
1424 { scenario : 'PouchDB v2.0.0' , constructorName : 'PouchDBVersion200' } ,
@@ -43,7 +53,15 @@ describe('migration', function () {
4353 if ( ! match ) {
4454 return testUtils . Promise . resolve ( ) ;
4555 }
46- return testUtils . asyncLoadScript ( 'deps/pouchdb-' + match [ 1 ] + '-postfixed.js' ) ;
56+
57+ const loader = testUtils . asyncLoadScript ( 'deps/pouchdb-' + match [ 1 ] + '-postfixed.js' ) ;
58+
59+ if ( usingIndexeddb ( ) && versionGte ( scenario , '7.2.1' ) ) {
60+ return loader
61+ . then ( ( ) => testUtils . asyncLoadScript ( 'deps/pouchdb-' + match [ 1 ] + '-indexeddb-postfixed.js' ) ) ;
62+ } else {
63+ return loader ;
64+ }
4765 } ) ) ;
4866 } ) ;
4967
@@ -86,6 +104,12 @@ describe('migration', function () {
86104
87105 if ( scenario in PouchDB . adapters ) {
88106 dbs . first . localOpts . adapter = scenario ;
107+ } else if ( usingIndexeddb ( ) ) {
108+ // use indexeddb adapter for both old and new DBs:
109+ // * cannot currently migrate idb -> indexeddb automatically
110+ // * in these tests, idb adapter is always the default for old PouchDB
111+ // bundles, even if indexeddb is available
112+ dbs . first . localOpts . adapter = 'indexeddb' ;
89113 }
90114 // else scenario might not make sense for this browser, so just use
91115 // same adapter for both
@@ -98,6 +122,12 @@ describe('migration', function () {
98122 testUtils . cleanup ( [ dbs . first . local , dbs . second . local ] , done ) ;
99123 } ) ;
100124
125+ before ( function ( ) {
126+ if ( usingIndexeddb ( ) && ! versionGte ( scenario , '7.2.1' ) ) {
127+ return this . skip ( ) ;
128+ }
129+ } ) ;
130+
101131 var origDocs = [
102132 { _id : '0' , a : 1 , b : 1 } ,
103133 { _id : '3' , a : 4 , b : 16 } ,
@@ -244,7 +274,7 @@ describe('migration', function () {
244274 } ) ;
245275 } ) ;
246276
247- if ( oldVersionGte ( '2.2.0' ) ) {
277+ if ( versionGte ( scenario , '2.2.0' ) ) {
248278 it ( "Test persistent views don't require update" , function ( done ) {
249279 var oldPouch = new dbs . first . pouch ( dbs . first . local , dbs . first . localOpts ) ;
250280 var docs = origDocs . slice ( ) . concat ( [ {
@@ -420,7 +450,7 @@ describe('migration', function () {
420450 } ) ;
421451 }
422452
423- if ( oldVersionGte ( '3.0.6' ) ) {
453+ if ( versionGte ( scenario , '3.0.6' ) ) {
424454 // attachments didn't really work until this release
425455 it ( '#2818 Testing attachments with compaction of dups' , function ( ) {
426456 var docs = [
@@ -819,7 +849,7 @@ describe('migration', function () {
819849 } ) ;
820850 }
821851
822- if ( oldVersionGte ( '3.2.0' ) ) {
852+ if ( versionGte ( scenario , '3.2.0' ) ) {
823853 it ( '#3136 Testing later winningSeqs' , function ( ) {
824854 var tree = [
825855 [
@@ -898,7 +928,7 @@ describe('migration', function () {
898928 } ) ;
899929 }
900930
901- if ( oldVersionGte ( '3.6.0' ) ) {
931+ if ( versionGte ( scenario , '3.6.0' ) ) {
902932 it ( '#3646 - Should finish with 0 documents' , function ( ) {
903933 var data = [
904934 {
@@ -1134,20 +1164,20 @@ describe('migration', function () {
11341164 } ) ;
11351165 }
11361166 } ) ;
1167+ } ) ;
1168+ } ) ;
11371169
1138- function oldVersionGte ( minimumRequired ) {
1139- const match = scenario . match ( / ^ P o u c h D B v ( [ . \d ] + ) $ / ) ;
1140- if ( ! match ) { return false ; }
1141- const actual = match [ 1 ] . split ( '.' ) ;
1170+ function versionGte ( scenario , minimumRequired ) {
1171+ const match = scenario . match ( / ^ P o u c h D B v ( [ . \d ] + ) $ / ) ;
1172+ if ( ! match ) { return false ; }
1173+ const actual = match [ 1 ] . split ( '.' ) ;
11421174
1143- const min = minimumRequired . split ( '.' ) ;
1175+ const min = minimumRequired . split ( '.' ) ;
11441176
1145- for ( let i = 0 ; i < min . length ; ++ i ) {
1146- if ( actual [ i ] > min [ i ] ) { return true ; }
1147- if ( actual [ i ] < min [ i ] ) { return false ; }
1148- }
1177+ for ( let i = 0 ; i < min . length ; ++ i ) {
1178+ if ( actual [ i ] > min [ i ] ) { return true ; }
1179+ if ( actual [ i ] < min [ i ] ) { return false ; }
1180+ }
11491181
1150- return true ;
1151- }
1152- } ) ;
1153- } ) ;
1182+ return true ;
1183+ }
0 commit comments