forked from speced/respec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
headless.js
84 lines (76 loc) · 2.38 KB
/
headless.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
78
79
80
81
82
83
84
#!/usr/local/bin/node
/*jshint es5: true*/
var exec = require("child_process").exec
, express = require("express")
, pth = require("path")
, dir = pth.join(__dirname, "..")
, PORT = 3000
, builder = require("../tools/build-w3c-common")
;
var express = require('express');
var app = express();
app.use(express.static(dir));
app.listen(PORT);
var counter = 0;
function done() {
counter--;
if (!counter) {
process.exit(0);
}
}
function runPhantom () {
if (process.env.TRACE) {
console.log("PhantomJS version:");
var childProcess = exec('phantomjs -v', function () {});
childProcess.stdout.pipe(process.stdout);
childProcess.stderr.pipe(process.stderr);
}
counter++;
var childProcess = exec('phantomjs --ssl-protocol=tlsv1 ./tests/phantom.js ' + (process.argv.slice(2).join(" ")), function () {});
childProcess.stdout.pipe(process.stdout);
childProcess.stderr.pipe(process.stderr);
childProcess.on('exit', function(code) {
if (code > 0) {
process.exit(code);
}
done();
});
}
function buildFailureReporter(source) {
return function(code) {
if (code > 0) {
console.error("Running respec2html on " + source + " failed");
process.exit(code);
} else {
console.log("Success building " + source);
}
done();
}
}
function runRespec2html () {
var fs = require("fs");
// Run respec2html.js on each example file (except "embedder.html")
// and stops in error if any of them reports a warning or an error
var sources = fs.readdirSync("examples").filter(function(n) { return n.match(/\.html$/) && n !== "embedder.html" ;});
sources.forEach(function(s) {
// We use --delay 1 since the examples use the non-compiled version
// of respec, which takes a bit longer to load
var cmd = 'phantomjs --ssl-protocol=tlsv1 ./tools/respec2html.js --delay 1 -w -e examples/' + s;
console.log("Running " + cmd);
counter++;
var childProcess = exec(cmd, function () {});
childProcess.stderr.pipe(process.stderr);
childProcess.on('exit', buildFailureReporter(s));
});
}
if (!process.env.TRAVIS) {
builder.buildW3C(false, function () {
console.log("Script built");
runPhantom();
runRespec2html();
});
}
else {
runPhantom();
runRespec2html();
}