Skip to content

Commit

Permalink
(#197) - Bring test utils into the monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-de-vries committed Jan 26, 2018
1 parent aff7e82 commit 85e262f
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 12 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
"memdown": "^1.2.4",
"mocha": "^3.2.0",
"navigator": "^1.0.1",
"pouchdb-plugin-helper": "^5.0.1",
"sqldown": "^2.1.0",
"sqlite3": "^3.1.13",
"supertest": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/http-pouchdb/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {PouchDB} = require('pouchdb-plugin-helper/testutils');
const {PouchDB} = require('../testutils');
const buildHTTPPouchDB = require('../../packages/node_modules/http-pouchdb');
const should = require('chai').should();

Expand Down
2 changes: 1 addition & 1 deletion tests/pouchdb-auth/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Auth = require('../../packages/node_modules/pouchdb-auth');
const stuff = require('pouchdb-plugin-helper/testutils');
const stuff = require('../testutils');
const extend = require('extend');

stuff.PouchDB.plugin(Auth);
Expand Down
2 changes: 1 addition & 1 deletion tests/pouchdb-list/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const stuff = require('pouchdb-plugin-helper/testutils');
const stuff = require('../testutils');
const List = require('../../packages/node_modules/pouchdb-list');

stuff.PouchDB.plugin(List);
Expand Down
2 changes: 1 addition & 1 deletion tests/pouchdb-replicator/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Promise = require('bluebird');
global.Promise = Promise; //use bluebird for all promises
const {PouchDB, setup, teardown, should} = require('pouchdb-plugin-helper/testutils');
const {PouchDB, setup, teardown, should} = require('../testutils');
const Replicator = require('../../packages/node_modules/pouchdb-replicator');
const extend = require('extend');

Expand Down
2 changes: 1 addition & 1 deletion tests/pouchdb-rewrite/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const stuff = require('pouchdb-plugin-helper/testutils');
const stuff = require('../testutils');
const Rewrite = require('../../packages/node_modules/pouchdb-rewrite');

const List = require('../../packages/node_modules/pouchdb-list');
Expand Down
2 changes: 1 addition & 1 deletion tests/pouchdb-seamless-auth/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const stuff = require('pouchdb-plugin-helper/testutils');
const stuff = require('../testutils');
const SeamlessAuth = require('../../packages/node_modules/pouchdb-seamless-auth');

stuff.waitUntilReady = () => SeamlessAuth(stuff.PouchDB);
Expand Down
2 changes: 1 addition & 1 deletion tests/pouchdb-security/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Security = require('../../packages/node_modules/pouchdb-security');
const Show = require('../../packages/node_modules/pouchdb-show');
const stuff = require('pouchdb-plugin-helper/testutils');
const stuff = require('../testutils');

stuff.PouchDB.plugin(Security);
stuff.Security = Security;
Expand Down
2 changes: 1 addition & 1 deletion tests/pouchdb-show/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const stuff = require('pouchdb-plugin-helper/testutils');
const stuff = require('../testutils');
const Show = require('../../packages/node_modules/pouchdb-show');

stuff.PouchDB.plugin(Show);
Expand Down
2 changes: 1 addition & 1 deletion tests/pouchdb-update/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const stuff = require('pouchdb-plugin-helper/testutils');
const stuff = require('../testutils');
const Update = require('../../packages/node_modules/pouchdb-update');

stuff.PouchDB.plugin(Update);
Expand Down
2 changes: 1 addition & 1 deletion tests/pouchdb-validation/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Validation = require('../../packages/node_modules/pouchdb-validation');
const stuff = require('pouchdb-plugin-helper/testutils');
const stuff = require('../testutils');

stuff.PouchDB.plugin(Validation);
stuff.onlyTestValidationDoc = {
Expand Down
2 changes: 1 addition & 1 deletion tests/pouchdb-vhost/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const stuff = require('pouchdb-plugin-helper/testutils');
const stuff = require('../testutils');
const Show = require('../../packages/node_modules/pouchdb-show');
const Rewrite = require('pouchdb-rewrite');
const VirtualHost = require('../../packages/node_modules/pouchdb-vhost');
Expand Down
76 changes: 76 additions & 0 deletions tests/testutils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
var fs = require('fs');
var path = require('path');
var Promise = require('pouchdb-promise');
var chai = require('chai');

exports.PouchDB = require('pouchdb').defaults({
db: require('memdown')
});

var testConfig;
var home = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
var confPath = path.join(home, '.pouchdb-plugin-helper-conf.json');
try {
testConfig = JSON.parse(fs.readFileSync(confPath, {encoding: 'utf8'}));
} catch (err) {
testConfig = {};
}

exports.should = chai.should();

var db;

exports.setup = function () {
db = new exports.PouchDB('test');
return db;
};

exports.setupWithDoc = function () {
exports.setup();
return db.put({
_id: 'mytest',
test: true
}).then(function (info) {
return {
db: db,
rev: info.rev
};
});
};

exports.setupWithDocAndAttachment = function () {
var res;
return exports.setupWithDoc().then(function (info) {
res = info;
var buffer = new Buffer('abcd', 'ascii');
return db.putAttachment('attachment_test', 'text', buffer, 'text/plain');
}).then(function (info) {
res.attRev = info.rev;
return res;
});
};

exports.teardown = function () {
return db.destroy();
};

exports.shouldThrowError = function (func) {
return Promise.resolve().then(function () {
return func();
}).then(function () {
'No error thrown while it should have been'.should.equal('');
}).catch(function (err) {
return err;
});
};

exports.BASE_URL = testConfig.base_url || 'http://localhost:5984';
exports.HTTP_AUTH = testConfig.username ? {
username: testConfig.username,
password: testConfig.password
} : null;

exports.setupHTTP = function () {
db = new exports.PouchDB(exports.BASE_URL + '/pouchdb-plugin-helper-db', {auth: exports.HTTP_AUTH});
return db;
};

0 comments on commit 85e262f

Please sign in to comment.