Skip to content

Commit 2dfadd1

Browse files
authored
tests/browser.migration: also run with indexeddb (#8766)
1 parent 2305add commit 2dfadd1

File tree

4 files changed

+76
-19
lines changed

4 files changed

+76
-19
lines changed

tests/integration/browser.migration.js

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22

33
describe('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(/^PouchDB v([.\d]+)$/);
1140-
if (!match) { return false; }
1141-
const actual = match[1].split('.');
1170+
function versionGte(scenario, minimumRequired) {
1171+
const match = scenario.match(/^PouchDB 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+
}

tests/integration/deps/get-postfixed-pouchdb-build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ log() {
77
echo "[get-postfixed-pouchdb-build] $*"
88
}
99

10+
indexeddb_support() {
11+
# indexeddb adapter introduced in v7.2.1
12+
# see: https://pouchdb.com/2020/02/12/pouchdb-7.2.0.html
13+
lesser="$(sort -V <(echo "$1") <(echo 7.2.1) | head -n1)"
14+
[[ "$lesser" = "7.2.1" ]]
15+
}
16+
1017
# Recently, postfixed JS files have been added in minified form.
1118
infix=".min"
1219
while [[ $# -gt 1 ]]; do
@@ -35,4 +42,20 @@ wget "https://github.com/pouchdb/pouchdb/releases/download/$version/pouchdb-${ve
3542
log "Converting globals..."
3643
sed "s/PouchDB/PouchDBVersion$nodots/g" "$tmp" > "$target"
3744

45+
log "Checking for indexeddb support..."
46+
if indexeddb_support "$version"; then
47+
log " indexeddb supported!"
48+
49+
tmp="$(mktemp)"
50+
target="./pouchdb-$version-indexeddb-postfixed.js"
51+
52+
log " Fetching indexeddb adapter..."
53+
wget "https://github.com/pouchdb/pouchdb/releases/download/$version/pouchdb.indexeddb.min.js" --output-document="$tmp"
54+
55+
log " Converting globals..."
56+
sed "s/PouchDB/PouchDBVersion$nodots/g" "$tmp" > "$target"
57+
else
58+
echo " indexeddb not supported by PouchDB v$version"
59+
fi
60+
3861
log "Completed OK."

tests/integration/deps/pouchdb-7.3.1-indexeddb-postfixed.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/deps/pouchdb-8.0.1-indexeddb-postfixed.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)