Skip to content

Commit

Permalink
Merge pull request jsdom#543 from godmar/withhtml5
Browse files Browse the repository at this point in the history
Support running tests under html5 parser
  • Loading branch information
domenic committed Dec 14, 2012
2 parents e7e0ae3 + dcc7991 commit 3d3082c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/jsdom/browser/index.js
Expand Up @@ -346,7 +346,7 @@ exports.createWindow = function(dom, options) {
* With cache: ~80ms
*/
var defaultParser = null;
function getDefaultParser() {
var getDefaultParser = exports.getDefaultParser = function () {
if (defaultParser === null) {
try {
defaultParser = require('htmlparser');
Expand All @@ -363,6 +363,17 @@ function getDefaultParser() {
return defaultParser;
}

/**
* Export getter/setter of default parser to facilitate testing
* with different HTML parsers.
*/
exports.setDefaultParser = function (parser) {
if (typeof parser == 'object') {
defaultParser = parser;
} else if (typeof parser == 'string')
defaultParser = require(parser);
}

/**
* Augments the given DOM by adding browser-specific properties and methods (BOM).
* Returns the augmented DOM.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -191,7 +191,8 @@
"contextify" : "0.1.x"
},
"optionalDependencies": {
"contextify" : "0.1.x"
"contextify" : "0.1.x",
"html5" : ">=0.3.8"
},
"devDependencies" : {
"nodeunit" : ">=0.5.x",
Expand Down
8 changes: 8 additions & 0 deletions test/runner
Expand Up @@ -20,6 +20,8 @@ var optimist = require('optimist')
.describe('t', 'choose the test cases to run. ie: -t jquery')
.alias('d', 'debug')
.describe('d', 'run in node\'s interactive debugger mode')
.alias('p', 'parser')
.describe('p', 'the HTML parser to use (e.g. html5); default is htmlparser')
.alias('v', 'verbose')
.describe('v', 'show all tests that are being run');

Expand Down Expand Up @@ -134,6 +136,12 @@ files.map(function (p) {
}
});

if (argv.parser) {
var browser = require("../lib/jsdom/browser/index");
console.log("Using parser " + argv.parser);
browser.setDefaultParser(argv.parser);
}

nodeunit.runModules(modulesToRun, {
moduleStart: function (name) {
currentModule = name.replace('.js', '');
Expand Down

0 comments on commit 3d3082c

Please sign in to comment.