diff --git a/tests/headless.js b/tests/headless.js index 05f1a134d4..c0e3e06308 100644 --- a/tests/headless.js +++ b/tests/headless.js @@ -14,6 +14,15 @@ 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:"); @@ -21,20 +30,55 @@ function runPhantom () { childProcess.stdout.pipe(process.stdout); childProcess.stderr.pipe(process.stderr); } - var childProcess = exec('phantomjs --ssl-protocol=any --ignore-ssl-errors=yes ./tests/phantom.js ' + (process.argv.slice(2).join(" ")), function () {}); + 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) { - process.exit(code); + 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(); } diff --git a/tools/respec2html.js b/tools/respec2html.js index 9cf0eb0c20..9fee1cd739 100755 --- a/tools/respec2html.js +++ b/tools/respec2html.js @@ -13,6 +13,7 @@ var page = require("webpage").create() , ignoreScripts = false , errors = [] , warnings = [] +, delay = 0 ; // report console.error on stderr @@ -31,6 +32,10 @@ if (args.indexOf("-w") !== -1) { reportWarnings = true; } +if (args.indexOf("--delay") !== -1) { + delay = args.splice(args.indexOf("--delay"), 2)[1]; +} + if (args.indexOf("--exclude-script") !== -1) { var idx = args.indexOf("--exclude-script"); var values = args.splice(idx, 2); @@ -83,7 +88,7 @@ page.open(source, function (status) { } else { console.error("Loading " + source); - page.evaluateAsync(function () { + setTimeout(function() { page.evaluateAsync(function () { function saveToPhantom () { require(["core/ui", "ui/save-html"], function (ui, saver) { saver.show(ui, respecConfig, document, respecEvents); @@ -92,6 +97,7 @@ page.open(source, function (status) { } if (document.respecDone) saveToPhantom(); else respecEvents.sub("end-all", saveToPhantom); +}, delay*1000); }); timer = setInterval(function () { if (timeout === 0) {