Skip to content

Commit

Permalink
Run respec2html on example files in test suite
Browse files Browse the repository at this point in the history
close #501
  • Loading branch information
dontcallmedom committed Jan 11, 2016
1 parent 5c90cec commit 35154d4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
50 changes: 47 additions & 3 deletions tests/headless.js
Expand Up @@ -14,27 +14,71 @@ 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);
}
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();
}
8 changes: 7 additions & 1 deletion tools/respec2html.js
Expand Up @@ -13,6 +13,7 @@ var page = require("webpage").create()
, ignoreScripts = false
, errors = []
, warnings = []
, delay = 0
;

// report console.error on stderr
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 35154d4

Please sign in to comment.