forked from googlearchive/code-prettify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_in_node
More file actions
executable file
·99 lines (85 loc) · 2.45 KB
/
Copy pathtest_in_node
File metadata and controls
executable file
·99 lines (85 loc) · 2.45 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
#!/usr/bin/env node
var Path = require("path");
var Url = require("url");
var proc = Path.basename(process.argv[1]);
var modules_failed = [];
var please_require = function(module) {
try {
return require(module);
} catch(error) {
console.error("%s: %s, %s", proc, error.name, error.message);
modules_failed.push(module);
return null;
}
}
var Browser = please_require("zombie");
var htmlToText = please_require("html-to-text");
if(modules_failed.length !== 0) {
console.log("%s: You probably need to run:", proc);
modules_failed.forEach(function(module) {
console.log("%s: npm install %s", proc, module);
});
process.exit(2);
}
var zombie_opts = { debug: false };
var htt_opts = { wordwrap: (process.stdout.columns || 120) };
var showSection = function(sectionName, sectionHtml) {
console.log("%s: ######## %s ########", proc, sectionName);
var plainText = htmlToText.fromString(sectionHtml, htt_opts);
console.log(plainText);
}
var jobs = process.argv.slice(2);
var return_code = 0;
var browser = null;
var check_cb = null;
var problem_cb = null;
var startBrowser = function() {
if(browser) {
browser.close();
}
var url = jobs.shift();
if(url === undefined) {
console.log("%s: complete", proc);
process.exit(return_code);
return;
}
var url_obj = Url.parse(url);
if(!url_obj.protocol) {
url_obj.protocol = "file";
url = Url.format(url_obj);
}
console.log("%s: Loading %s ...", proc, url);
browser = new Browser();
browser.visit(url, zombie_opts, null).then(check_cb).fail(problem_cb);
};
problem_cb = function(error) {
return_code = 1;
console.warn("Test failed: ", error);
startBrowser();
}
check_cb = function() {
var done = false;
var one_prob = function(err_obj) {
console.warn("%s: %s, %s; %s", proc, err_obj.type,
err_obj.message, err_obj.data.error);
return_code = 1;
done = true;
};
(browser.errors || []).forEach(one_prob);
(browser.document.errors || []).forEach(one_prob);
var report = browser.html("#errorReport");
if(report.match(/Test results/i)) {
done = true;
showSection("TEST RESULTS", report);
}
var timing = browser.html("#timing");
if(timing) {
showSection("TIMING", timing);
}
if(done) {
startBrowser();
} else {
browser.wait().then(check_cb).fail(problem_cb);
}
}
startBrowser();