Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
5 lars 1
var webpage = require("webpage"),
2
    fs = require("fs");
3
 
4
var html_path = fs.absolute("test.html");
5
var examples = [];
6
 
7
function run_example(example_index) {
8
  if (example_index >= examples.length) {
9
    phantom.exit(0);
10
    return;
11
  }
12
 
13
  var example = examples[example_index];
14
  var snapshot_index = 0;
15
  var page = webpage.create();
16
 
17
  page.viewportSize = { width: 500, height: 300 };
18
  page.clipRect = { width: 500, height: 300 };
19
  page.onAlert = function (msg) {
20
    var e = JSON.parse(msg);
21
    if (e.fn == "snapshot") {
22
      page.render("output/" + example.name + snapshot_index + ".png");
23
      snapshot_index += 1;
24
    } else if (e.fn == "mousemove") {
25
      page.sendEvent("mousemove", e.x, e.y);
26
    }
27
  };
28
 
29
  page.open(html_path, function (status) {
30
    if (status == "fail") {
31
      console.log("Failed to load test page: " + example.name);
32
      phantom.exit(1);
33
    } else {
34
      page.evaluate(example.runner);
35
    }
36
    page.close();
37
    run_example(example_index + 1);
38
  });
39
}
40
 
41
exports.def = function (name, runner) {
42
  examples.push({ name: name, runner: runner });
43
};
44
 
45
exports.run = function () {
46
  if (fs.isDirectory("output")) {
47
    fs.list("output").forEach(function (path) {
48
      if (path != "." && path != "..") {
49
        fs.remove("output/" + path);
50
      }
51
    });
52
  } else {
53
    fs.makeDirectory("output");
54
  }
55
  run_example(0);
56
};