diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 |
commit | de98e0b232509d5f40c135d540a70e415272ff85 (patch) | |
tree | a79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/domutils/tests | |
parent | e0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff) | |
download | wallet-core-de98e0b232509d5f40c135d540a70e415272ff85.tar.xz |
node_modules
Diffstat (limited to 'node_modules/domutils/tests')
-rw-r--r-- | node_modules/domutils/tests/00-runtests.js | 64 | ||||
-rw-r--r-- | node_modules/domutils/tests/02-dom_utils.js | 15 | ||||
-rw-r--r-- | node_modules/domutils/tests/DomUtils/01-by_id.js | 56 | ||||
-rw-r--r-- | node_modules/domutils/tests/DomUtils/02-by_tagname.js | 23 | ||||
-rw-r--r-- | node_modules/domutils/tests/DomUtils/03-by_type.js | 23 | ||||
-rw-r--r-- | node_modules/domutils/tests/DomUtils/04-outer_html.js | 10 | ||||
-rw-r--r-- | node_modules/domutils/tests/DomUtils/05-inner_html.js | 10 |
7 files changed, 201 insertions, 0 deletions
diff --git a/node_modules/domutils/tests/00-runtests.js b/node_modules/domutils/tests/00-runtests.js new file mode 100644 index 000000000..cf7a3b7f8 --- /dev/null +++ b/node_modules/domutils/tests/00-runtests.js @@ -0,0 +1,64 @@ +var fs = require("fs"), + assert = require("assert"); + +var runCount = 0, + testCount = 0; + +function compare(expected, result){ + if(typeof expected !== typeof result){ + throw Error("types didn't match"); + } + if(typeof expected !== "object" || expected === null){ + if(expected !== result){ + throw Error("result doesn't equal expected"); + } + return; + } + + for(var prop in expected){ + if(!(prop in result)) throw Error("result didn't contain property " + prop); + compare(expected[prop], result[prop]); + } +} + +function runTests(test){ + //read files, load them, run them + fs.readdirSync(__dirname + test.dir + ).map(function(file){ + if(file[0] === ".") return false; + if(file.substr(-5) === ".json") return JSON.parse( + fs.readFileSync(__dirname + test.dir + file) + ); + return require(__dirname + test.dir + file); + }).forEach(function(file){ + if(!file) return; + var second = false; + + runCount++; + + console.log("Testing:", file.name); + + test.test(file, function(err, dom){ + assert.ifError(err); + compare(file.expected, dom); + + if(second){ + runCount--; + testCount++; + } + else second = true; + }); + }); + console.log("->", test.dir.slice(1, -1), "started"); +} + +//run all tests +[ + "./02-dom_utils.js" +].map(require).forEach(runTests); + +//log the results +(function check(){ + if(runCount !== 0) return process.nextTick(check); + console.log("Total tests:", testCount); +}());
\ No newline at end of file diff --git a/node_modules/domutils/tests/02-dom_utils.js b/node_modules/domutils/tests/02-dom_utils.js new file mode 100644 index 000000000..9a28b891b --- /dev/null +++ b/node_modules/domutils/tests/02-dom_utils.js @@ -0,0 +1,15 @@ +//generate a dom +var handler = new (require("domhandler"))(); + +(new (require("htmlparser2").Parser)(handler)).parseComplete( + Array(21).join("<?xml><tag1 id='asdf'> <script>text</script> <!-- comment --> <tag2> text </tag1>") +); + +var dom = handler.dom; + +exports.dir = "/DomUtils/"; + +exports.test = function(test, cb){ + cb(null, test.getElements(dom)); + cb(null, test.getByFunction(dom)); +};
\ No newline at end of file diff --git a/node_modules/domutils/tests/DomUtils/01-by_id.js b/node_modules/domutils/tests/DomUtils/01-by_id.js new file mode 100644 index 000000000..a5f02df24 --- /dev/null +++ b/node_modules/domutils/tests/DomUtils/01-by_id.js @@ -0,0 +1,56 @@ +var DomUtils = require("../.."); + +exports.name = "Get element by id"; +exports.getElements = function(dom){ + return DomUtils.getElements({id:"asdf"}, dom, true, 1)[0]; +}; +exports.getByFunction = function(dom){ + return DomUtils.getElementById("asdf", dom, true); +}; +exports.expected = { + "type": "tag", + "name": "tag1", + "attribs": { + "id": "asdf" + }, + "children": [ + { + "data": " ", + "type": "text" + }, + { + "type": "script", + "name": "script", + "attribs": {}, + "children": [ + { + "data": "text", + "type": "text" + } + ] + }, + { + "data": " ", + "type": "text" + }, + { + "data": " comment ", + "type": "comment" + }, + { + "data": " ", + "type": "text" + }, + { + "type": "tag", + "name": "tag2", + "attribs": {}, + "children": [ + { + "data": " text ", + "type": "text" + } + ] + } + ] +};
\ No newline at end of file diff --git a/node_modules/domutils/tests/DomUtils/02-by_tagname.js b/node_modules/domutils/tests/DomUtils/02-by_tagname.js new file mode 100644 index 000000000..125357c41 --- /dev/null +++ b/node_modules/domutils/tests/DomUtils/02-by_tagname.js @@ -0,0 +1,23 @@ +var DomUtils = require("../.."); + +exports.name = "Get elements by tagName"; +exports.getElements = function(dom){ + return DomUtils.getElements({tag_name:"tag2"}, dom, true); +}; +exports.getByFunction = function(dom){ + return DomUtils.getElementsByTagName("tag2", dom, true); +}; +exports.expected = []; +for(var i = 0; i < 20; i++) exports.expected.push( + { + "type": "tag", + "name": "tag2", + "attribs": {}, + "children": [ + { + "data": " text ", + "type": "text" + } + ] + } +);
\ No newline at end of file diff --git a/node_modules/domutils/tests/DomUtils/03-by_type.js b/node_modules/domutils/tests/DomUtils/03-by_type.js new file mode 100644 index 000000000..43bd66791 --- /dev/null +++ b/node_modules/domutils/tests/DomUtils/03-by_type.js @@ -0,0 +1,23 @@ +var DomUtils = require("../.."); + +exports.name = "Get elements by type"; +exports.getElements = function(dom){ + return DomUtils.getElements({tag_type:"script"}, dom, true); +}; +exports.getByFunction = function(dom){ + return DomUtils.getElementsByTagType("script", dom, true); +}; +exports.expected = []; +for(var i = 0; i < 20; i++) exports.expected.push( + { + "type": "script", + "name": "script", + "attribs": {}, + "children": [ + { + "data": "text", + "type": "text" + } + ] + } +);
\ No newline at end of file diff --git a/node_modules/domutils/tests/DomUtils/04-outer_html.js b/node_modules/domutils/tests/DomUtils/04-outer_html.js new file mode 100644 index 000000000..57aae971f --- /dev/null +++ b/node_modules/domutils/tests/DomUtils/04-outer_html.js @@ -0,0 +1,10 @@ +var DomUtils = require("../.."); + +exports.name = "Get outer HTML"; +exports.getElements = function(dom){ + return '<tag1 id="asdf"> <script>text</script> <!-- comment --> <tag2> text </tag2></tag1>'; +}; +exports.getByFunction = function(dom){ + return DomUtils.getOuterHTML(DomUtils.getElementById("asdf", dom, true)); +}; +exports.expected = '<tag1 id="asdf"> <script>text</script> <!-- comment --> <tag2> text </tag2></tag1>'; diff --git a/node_modules/domutils/tests/DomUtils/05-inner_html.js b/node_modules/domutils/tests/DomUtils/05-inner_html.js new file mode 100644 index 000000000..36a266163 --- /dev/null +++ b/node_modules/domutils/tests/DomUtils/05-inner_html.js @@ -0,0 +1,10 @@ +var DomUtils = require("../.."); + +exports.name = "Get inner HTML"; +exports.getElements = function(dom){ + return ' <script>text</script> <!-- comment --> <tag2> text </tag2>'; +}; +exports.getByFunction = function(dom){ + return DomUtils.getInnerHTML(DomUtils.getElementById("asdf", dom, true)); +}; +exports.expected = ' <script>text</script> <!-- comment --> <tag2> text </tag2>'; |