-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
utils.js
82 lines (72 loc) · 2.22 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
var reporter = require('./perf.reporter');
var test = require('tape');
var commonUtils = require('../common-utils.js');
var Promise = require('lie');
var grep;
if (global.window && global.window.location && global.window.location.search) {
grep = global.window.location.search.match(/[&?]grep=([^&]+)/);
grep = grep && grep[1];
} else if (process && process.env) {
grep = process.env.GREP;
}
exports.runTests = function (PouchDB, suiteName, testCases, opts) {
testCases.forEach(function (testCase, i) {
if (grep && suiteName.indexOf(grep) === -1 &&
testCase.name.indexOf(grep) === -1) {
return;
}
if (testCase.iterations === 0) {
return;
}
test('benchmarking', function (t) {
var db;
var setupObj;
var localDbName = commonUtils.safeRandomDBName();
t.test('setup', function (t) {
opts.size = 3000;
db = new PouchDB(localDbName, opts);
testCase.setup(db, function (err, res) {
setupObj = res;
if (i === 0) {
reporter.startSuite(suiteName);
}
reporter.start(testCase);
t.end();
});
});
t.test(testCase.name, function (t) {
t.plan(testCase.assertions);
var num = 0;
function after(err) {
if (err) {
t.error(err);
reporter.log(testCase.name + ' errored: ' + err.message + '\n');
}
if (++num < testCase.iterations) {
process.nextTick(function () {
testCase.test(db, num, setupObj, after);
});
} else {
t.ok(testCase.name + ' completed');
}
}
testCase.test(db, num, setupObj, after);
});
t.test('teardown', function (t) {
var testCaseTeardown =
testCase.tearDown ? testCase.tearDown : Promise.resolve;
testCaseTeardown(db, setupObj).then(function () {
reporter.end(testCase);
var opts = {adapter : db.adapter};
return new PouchDB(localDbName, opts).destroy();
}).then(function () {
t.end();
if (i === testCases.length - 1) {
reporter.complete(suiteName);
}
});
});
});
});
};