Skip to content

Commit

Permalink
test.migration: simplify scenario/constructor mapping (#8750)
Browse files Browse the repository at this point in the history
Merge scenarios & constructors lists.

This should simplify adding future PouchDB versions to the migration tests as no
longer need to separately declare:

* eslint globals exclusions
* cleanup via `delete window`
* extra mapping between scenario and constructor
  • Loading branch information
alxndrsn authored Sep 17, 2023
1 parent 6e705df commit aa6d500
Showing 1 changed file with 18 additions and 37 deletions.
55 changes: 18 additions & 37 deletions tests/integration/browser.migration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* global PouchDBVersion110, PouchDBVersion200,
PouchDBVersion220, PouchDBVersion306, PouchDBVersion320,
PouchDBVersion360, PouchDBVersion731, PouchDBVersion801 */
'use strict';

describe('migration', function () {
Expand All @@ -12,16 +9,16 @@ describe('migration', function () {
(pref.length === 2 && pref[0] === 'idb' && pref[1] === 'websql');
}

var scenarios = [
'PouchDB v1.1.0',
'PouchDB v2.0.0',
'PouchDB v2.2.0',
'PouchDB v3.0.6',
'PouchDB v3.2.0',
'PouchDB v3.6.0',
'PouchDB v7.3.1',
'PouchDB v8.0.1',
'websql'
const scenarios = [
{ scenario: 'PouchDB v1.1.0', constructorName: 'PouchDBVersion110'} ,
{ scenario: 'PouchDB v2.0.0', constructorName: 'PouchDBVersion200'} ,
{ scenario: 'PouchDB v2.2.0', constructorName: 'PouchDBVersion220'} ,
{ scenario: 'PouchDB v3.0.6', constructorName: 'PouchDBVersion306'} ,
{ scenario: 'PouchDB v3.2.0', constructorName: 'PouchDBVersion320'} ,
{ scenario: 'PouchDB v3.6.0', constructorName: 'PouchDBVersion360'} ,
{ scenario: 'PouchDB v7.3.1', constructorName: 'PouchDBVersion731'} ,
{ scenario: 'PouchDB v8.0.1', constructorName: 'PouchDBVersion801'} ,
{ scenario: 'websql', constructorName: 'PouchDB'} ,
];

var skip = false;
Expand All @@ -41,7 +38,7 @@ describe('migration', function () {

// conditionally load all legacy PouchDB scripts to avoid pulling them in
// for test runs that don't test migrations
return Promise.all(scenarios.map(function (scenario) {
return Promise.all(scenarios.map(function ({ scenario }) {
var match = scenario.match(/PouchDB v([.\d]+)/);
if (!match) {
return testUtils.Promise.resolve();
Expand All @@ -58,46 +55,30 @@ describe('migration', function () {

after(function () {
// free memory
delete window.PouchDBVersion110;
delete window.PouchDBVersion200;
delete window.PouchDBVersion220;
delete window.PouchDBVersion306;
delete window.PouchDBVersion320;
delete window.PouchDBVersion360;
delete window.PouchDBVersion731;
delete window.PouchDBVersion801;
scenarios.forEach(({ constructorName }) => {
if (constructorName !== 'PouchDB') {
delete window[constructorName];
}
});
});

scenarios.forEach(function (scenario) {
scenarios.forEach(function ({ scenario, constructorName }) {

describe('migrate from ' + scenario, function () {

var dbs = {};
var constructors = {};

beforeEach(function (done) {
if (skip) {
return this.skip();
}

constructors = {
'PouchDB v1.1.0': PouchDBVersion110,
'PouchDB v2.0.0': PouchDBVersion200,
'PouchDB v2.2.0': PouchDBVersion220,
'PouchDB v3.0.6': PouchDBVersion306,
'PouchDB v3.2.0': PouchDBVersion320,
'PouchDB v3.6.0': PouchDBVersion360,
'PouchDB v7.3.1': PouchDBVersion731,
'PouchDB v8.0.1': PouchDBVersion801,
PouchDB: PouchDB
};

// need actual unique db names for these tests
var localName = testUtils.adapterUrl('local', 'test_migration_local');
var remoteName = testUtils.adapterUrl('http', 'test_migration_remote');

dbs.first = {
pouch : constructors[scenario] || PouchDB,
pouch : window[constructorName] || PouchDB,
local : localName,
remote : remoteName,
localOpts : {}
Expand Down

0 comments on commit aa6d500

Please sign in to comment.