react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / htmlparser2 / node_modules / domhandler / test / tests.js
81149 viewsvar fs = require("fs"),1path = require("path"),2assert = require("assert"),3util = require("util"),4Parser = require("htmlparser2").Parser,5Handler = require("../");67var basePath = path.resolve(__dirname, "cases"),8inspectOpts = { showHidden: true, depth: null };910fs11.readdirSync(basePath)12.filter(RegExp.prototype.test, /\.json$/) //only allow .json files13.map(function(name){14return path.resolve(basePath, name);15})16.map(require)17.forEach(function(test){18it(test.name, function(){19var expected = test.expected;2021var handler = new Handler(function(err, actual){22assert.ifError(err);23try {24compare(expected, actual);25} catch(e){26e.expected = util.inspect(expected, inspectOpts);27e.actual = util.inspect(actual, inspectOpts);28throw e;29}30}, test.options);3132var data = test.html;3334var parser = new Parser(handler, test.options);3536//first, try to run the test via chunks37if (test.streaming || test.streaming === undefined){38for(var i = 0; i < data.length; i++){39parser.write(data.charAt(i));40}41parser.done();42}4344//then parse everything45parser.parseComplete(data);46});47});4849function compare(expected, result){50assert.equal(typeof expected, typeof result, "types didn't match");51if(typeof expected !== "object" || expected === null){52assert.strictEqual(expected, result, "result doesn't equal expected");53} else {54for(var prop in expected){55assert.ok(prop in result, "result didn't contain property " + prop);56compare(expected[prop], result[prop]);57}58}59}6061