forked from dagrejs/dagre-d3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-test.js
77 lines (69 loc) · 2.17 KB
/
demo-test.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
// A *very* simple test runner to ensure that the demos work as expected.
var webpage = require("webpage");
var system = require("system");
var stdout = system.stdout;
var stderr = system.stderr;
// Too bad this replaces the more function fs module from nodejs...
var fs = require("fs");
var start = new Date();
var red = "\033[31m";
var green = "\033[32m";
var grey = "\033[30;1m";
var reset = "\033[0m";
function htmlFile(file) { return file.match(/.*\.html/); }
fs.changeWorkingDirectory("./build/dist/demo");
var remaining = {};
ls(".", htmlFile).forEach(function(f) { remaining[f] = true; });
var testCount = Object.keys(remaining).length;
var failures = [];
stdout.write("\n");
stdout.write(grey + " ");
Object.keys(remaining).forEach(function(url) {
stdout.write(".");
var page = webpage.create();
page.onError = function(msg, trace) {
failures.push({ url: url, msg: msg, trace: trace });
testDone(url);
};
page.onLoadFinished = function(status) {
if (status !== "success") {
failures.push({ url: url, msg: "Could not load page" });
}
testDone(url);
};
page.open(url, function() {});
});
function ls(dir, filter) {
var set = [];
fs.list(dir).forEach(function(file) {
if (filter(file)) {
set.push(dir + "/" + file);
}
});
return set;
}
function testDone(url) {
delete remaining[url];
if (!Object.keys(remaining).length) {
stdout.write(reset + "\n");
stdout.write("\n");
failures.forEach(function(failure) {
stderr.write(red + "FAILED: " + failure.url + reset + "\n");
stderr.write(grey);
stderr.write(" " + failure.msg + "\n");
if (failure.trace) {
failure.trace.forEach(function(t) {
stderr.write(" " + t.file + ": " + t.line + (t.function ? " (in function '" + t.function + "')" : "") + "\n");
});
}
stderr.write(reset);
stderr.write("\n");
});
stdout.write(" " + green + (testCount - failures.length) + " passing" + reset);
if (failures.length) {
stdout.write(" " + red + (failures.length) + " failing" + reset);
}
stdout.write(grey + " (" + (new Date() - start) + "ms)" + reset + "\n\n");
phantom.exit(failures.length);
}
}