-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathdev-server.js
More file actions
executable file
·127 lines (111 loc) · 3.67 KB
/
dev-server.js
File metadata and controls
executable file
·127 lines (111 loc) · 3.67 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env node
'use strict';
const http = require('http');
var watch = require('watch-glob');
const serveHandler = require('serve-handler');
var debounce = require('lodash.debounce');
var browserify = require('browserify');
var fs = require('fs');
var queryParams = {};
if (process.env.ADAPTERS) {
queryParams.adapters = process.env.ADAPTERS;
}
if (process.env.VIEW_ADAPTERS) {
queryParams.viewAdapters = process.env.VIEW_ADAPTERS;
}
if (process.env.AUTO_COMPACTION) {
queryParams.autoCompaction = true;
}
if (process.env.POUCHDB_SRC) {
queryParams.src = process.env.POUCHDB_SRC;
}
if (process.env.PLUGINS) {
queryParams.plugins = process.env.PLUGINS;
}
if (process.env.COUCH_HOST) {
queryParams.couchHost = process.env.COUCH_HOST;
}
if (process.env.ITERATIONS) {
queryParams.iterations = process.env.ITERATIONS;
}
if (process.env.SRC_ROOT) {
queryParams.srcRoot = process.env.SRC_ROOT;
}
if (process.env.USE_MINIFIED) {
queryParams.useMinified = process.env.USE_MINIFIED;
}
var rebuildPromise = Promise.resolve();
function rebuildPouch() {
const buildPouchDB = require('./build-pouchdb');
rebuildPromise = rebuildPromise.then(buildPouchDB).then(function () {
console.log('Rebuilt packages/node_modules/pouchdb');
}).catch(console.error);
return rebuildPromise;
}
function browserifyPromise(src, dest) {
return new Promise(function (resolve, reject) {
browserify(src, {debug: true}).bundle().pipe(fs.createWriteStream(dest))
.on('finish', resolve)
.on('error', reject);
});
}
function rebuildTestUtils() {
rebuildPromise = rebuildPromise.then(function () {
return browserifyPromise('tests/integration/utils.js',
'tests/integration/utils-bundle.js');
}).then(function () {
console.log('Rebuilt tests/integration/utils-bundle.js');
}).catch(console.error);
return rebuildPromise;
}
function rebuildPerf() {
rebuildPromise = rebuildPromise.then(function () {
return browserifyPromise('tests/performance/index.js',
'tests/performance-bundle.js');
}).then(function () {
console.log('Rebuilt tests/performance-bundle.js');
}).catch(console.error);
return rebuildPromise;
}
function watchAll() {
watch(['packages/node_modules/*/src/**/*.js'],
debounce(rebuildPouch, 700, {leading: true}));
watch(['tests/integration/utils.js'],
debounce(rebuildTestUtils, 700, {leading: true}));
watch(['tests/performance/**/*.js'],
debounce(rebuildPerf, 700, {leading: true}));
}
var HTTP_PORT = 8000;
var serversStarted;
var readyCallback;
function startServers(callback) {
readyCallback = callback;
const server = http.createServer((req, res) => {
// Add cross-origin isolation headers to allow for more precise performance measurements.
// See: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#security_requirements
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
return serveHandler(req, res, { trailingSlash:true });
});
server.listen(HTTP_PORT, () => {
var testRoot = 'http://127.0.0.1:' + HTTP_PORT;
const query = new URLSearchParams(queryParams);
console.log(`Integration tests: ${testRoot}/tests/integration/?${query}`);
console.log(`Map/reduce tests: ${testRoot}/tests/mapreduce/?${query}`);
console.log(`pouchdb-find tests: ${testRoot}/tests/find/?${query}`);
console.log(`Performance tests: ${testRoot}/tests/performance/?${query}`);
serversStarted = true;
checkReady();
});
}
function checkReady() {
if (serversStarted && readyCallback) {
readyCallback();
}
}
if (require.main === module) {
startServers();
watchAll();
} else {
module.exports.start = startServers;
}