Skip to content

Commit

Permalink
Feat(respecDocWriter): throw if not a ReSpec doc (closes #704)
Browse files Browse the repository at this point in the history
 * Add check for respecIsReady on document object as first check
 * Added color + emoji
 * Fixed color of HTTP error also
  • Loading branch information
marcoscaceres committed Apr 21, 2016
1 parent 6a2f2c3 commit 0bfed3e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tools/respecDocWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,25 @@ const tasks = {
const response = yield nightmare
.goto(url);
if (response.code !== 200) {
const msg = `HTTP Error ${response.code}: ${url}`;
const warn = colors.warn(`📡 HTTP Error ${response.code}:`);
const msg = `${warn} ${colors.debug(url)}`;
throw new Error(msg);
}
const isRespecDoc = yield nightmare
.wait(function(){
return document.readyState === "complete";
})
.evaluate(function(){
if(document.hasOwnProperty("respectIsReady")){
return true;
}
// does it try to load ReSpec locally or remotely
const remoteScriptQuery = "script[src='https://www.w3.org/Tools/respec/respec-w3c-common']";
const query = `script[data-main*=profile-w3c-common], ${remoteScriptQuery}`;
return (document.querySelector(query)) ? true : false;
});
if(!isRespecDoc){
const msg = `${colors.warn("💣 Not a ReSpec source document?")} ${colors.debug(url)}`;
throw new Error(msg);
}
const html = yield nightmare
Expand Down

0 comments on commit 0bfed3e

Please sign in to comment.