forked from piuccio/node-coverage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
78 lines (73 loc) · 2.34 KB
/
server.js
File metadata and controls
78 lines (73 loc) · 2.34 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
var fs = require("fs");
var argv = require("optimist")
.usage("Start a simple web server to instrument JS code.")
.options("d", {
"alias" : "doc-root",
"default" : "/var/www"
}).describe("d", "Document Root. Content from this path will be served by the server")
.options("r", {
"alias" : "report-dir",
"default" : "/var/log/node-coverage"
}).describe("r", "Directory where reports are stored.")
.options("p", {
"alias" : "port",
"default" : 8080
}).describe("p", "Web server port")
.options("a", {
"alias" : "admin-port",
"default" : 8787
}).describe("a", "Admin server port")
.boolean("h").alias("h", "help")
.boolean("function")
.default("function", false)
.describe("function", "Enable function coverage. Disable with --no-function")
.boolean("condition")
.default("condition", true)
.describe("condition", "Enable condition coverage. Disable with --no-condition")
.boolean("session")
.default("session", true)
.describe("session", "Store instrumented code in session storage. This reduces the burden on browsers. Disable with --no-session")
.options("i", {
"alias" : "ignore"
}).describe("i", "Ignore file or folder. This file/folder won't be instrumented. Path relative to document root")
.boolean("proxy")
.default("proxy", false)
.describe("proxy", "Start the instrumentation server in HTTP proxy mode on port specified by -p.")
.argv;
if (argv.h) {
require("optimist").showHelp();
} else {
try {
var stat = fs.statSync(argv.r);
if (!stat.isDirectory()) {
throw new Error(argv.r + " is not a directory");
}
var ignore = argv.i || [];
if (!ignore.forEach) {
ignore = [ignore];
}
/* Instrumentation server */
if (argv.proxy) {
require("./lib/server/proxy").start(argv.d, argv.p, argv.r, argv.a, {
"function" : argv["function"],
"condition" : argv.condition,
"doHighlight" : true
});
} else {
require("./lib/server/instrumentation").start(argv.d, argv.p, argv.r, argv.a, {
"function" : argv["function"],
"condition" : argv.condition,
"doHighlight" : !argv.session,
"ignore" : ignore.map(function (path) {
if (path.charAt(0) !== "/") {
return "/" + path;
}
})
});
}
/* Admin server */
require("./lib/server/administration").start(argv.d, argv.p, argv.r, argv.a);
} catch (ex) {
console.error("Please specify a valid report directory", ex);
}
}