-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (57 loc) · 2.24 KB
/
index.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
var childProcess = require("child_process"),
fs = require("fs"),
phantomjs = require("phantomjs"),
binPath = phantomjs.path;
module.exports = {
initialize: function (options) {
console.log("Initialization started");
var urls = options._,
count = options.loop || 10,
totalCount = count,
outFile = options.out,
format = options.format || 'CSV',
cookieFile = options.cookieFile || 'cookies/cookie.txt',
cookieDomain = options.cookieDomain,
execCallback = function (error, stdout, stderr) {
if (stdout) {
//console.log(stdout);
fs.appendFile(outFile, stdout, function (err) {
if (err) {
throw err;
}
});
if (count--) {
console.log("Run count... " + (totalCount - count));
childProcess.exec([binPath, "scripts/run.js", urls[0], cookieFile, cookieDomain].join(" "), execCallback);
}
else {
console.log("Execution completed - Report stored in " + outFile);
}
}
if (stderr) {
console.log("ERROR: " + stderr);
}
if (error !== null) {
console.log('EXEC ERROR: ' + error);
}
};
var exists = fs.existsSync(outFile);
if (!exists) {
fs.writeFileSync(outFile, "Page Load Time,Resource URL,Requested After,Response Time\n");
}
if (urls.length) {
console.log("URL: " + urls[0]);
console.log("Repeat: " + count || 1);
console.log("Cookie File: " + cookieFile);
console.log("Cookie Domain: " + cookieDomain);
if (count--) {
console.log("Run count... " + (totalCount - count));
childProcess.exec([binPath, "scripts/run.js", urls[0], cookieFile, cookieDomain].join(" "), execCallback);
}
}
else {
// Throw error
console.log("URL not specified!");
}
}
};