Skip to content

Commit 6e705df

Browse files
authored
test.migration: simplify version number checks (#8749)
Replace hard-coded lists of subsequent version numbers with equivalent implementation of semver.gte(). This should: * reduce toil when adding new pouch versions to migration tests * reduce the chance of accidentally exlcuding a new pouch version from migration tests * make test intention clearer
1 parent c056539 commit 6e705df

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

tests/integration/browser.migration.js

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,33 +75,6 @@ describe('migration', function () {
7575
var dbs = {};
7676
var constructors = {};
7777

78-
var post220 = [
79-
'PouchDB v2.2.0',
80-
'PouchDB v3.0.6',
81-
'PouchDB v3.2.0',
82-
'PouchDB v3.6.0',
83-
'PouchDB v7.3.1',
84-
'PouchDB v8.0.1',
85-
].indexOf(scenario) !== -1;
86-
var post306 = [
87-
'PouchDB v3.0.6',
88-
'PouchDB v3.2.0',
89-
'PouchDB v3.6.0',
90-
'PouchDB v7.3.1',
91-
'PouchDB v8.0.1',
92-
].indexOf(scenario) !== -1;
93-
var post320 = [
94-
'PouchDB v3.2.0',
95-
'PouchDB v3.6.0',
96-
'PouchDB v7.3.1',
97-
'PouchDB v8.0.1',
98-
].indexOf(scenario) !== -1;
99-
var post360 = [
100-
'PouchDB v3.6.0',
101-
'PouchDB v7.3.1',
102-
'PouchDB v8.0.1',
103-
].indexOf(scenario) !== -1;
104-
10578
beforeEach(function (done) {
10679
if (skip) {
10780
return this.skip();
@@ -296,7 +269,7 @@ describe('migration', function () {
296269
});
297270
});
298271

299-
if (post220) {
272+
if (oldVersionGte('2.2.0')) {
300273
it("Test persistent views don't require update", function (done) {
301274
var oldPouch = new dbs.first.pouch(dbs.first.local, dbs.first.localOpts);
302275
var docs = origDocs.slice().concat([{
@@ -472,7 +445,7 @@ describe('migration', function () {
472445
});
473446
}
474447

475-
if (post306) {
448+
if (oldVersionGte('3.0.6')) {
476449
// attachments didn't really work until this release
477450
it('#2818 Testing attachments with compaction of dups', function () {
478451
var docs = [
@@ -871,7 +844,7 @@ describe('migration', function () {
871844
});
872845
}
873846

874-
if (post320) {
847+
if (oldVersionGte('3.2.0')) {
875848
it('#3136 Testing later winningSeqs', function () {
876849
var tree = [
877850
[
@@ -950,7 +923,7 @@ describe('migration', function () {
950923
});
951924
}
952925

953-
if (post360) {
926+
if (oldVersionGte('3.6.0')) {
954927
it('#3646 - Should finish with 0 documents', function () {
955928
var data = [
956929
{
@@ -1186,5 +1159,20 @@ describe('migration', function () {
11861159
});
11871160
}
11881161
});
1162+
1163+
function oldVersionGte(minimumRequired) {
1164+
const match = scenario.match(/^PouchDB v([.\d]+)$/);
1165+
if (!match) { return false; }
1166+
const actual = match[1].split('.');
1167+
1168+
const min = minimumRequired.split('.');
1169+
1170+
for (let i=0; i<min.length; ++i) {
1171+
if (actual[i] > min[i]) { return true; }
1172+
if (actual[i] < min[i]) { return false; }
1173+
}
1174+
1175+
return true;
1176+
}
11891177
});
11901178
});

0 commit comments

Comments
 (0)