Skip to content

Commit

Permalink
Update to JSDOM 10.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed May 5, 2017
1 parent 26c72e0 commit eba2a94
Show file tree
Hide file tree
Showing 40 changed files with 219 additions and 214 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"license": "BSD-3-Clause",
"author": {
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"
"url": "https://bost.ocks.org/mike"
},
"main": "build/d3-selection.js",
"module": "index",
Expand All @@ -30,8 +30,8 @@
},
"devDependencies": {
"eslint": "3",
"jsdom": "9",
"package-preamble": "0.0",
"jsdom": "10",
"package-preamble": "0.1",
"rollup": "0.41",
"tape": "4",
"uglify-js": "^2.8.11"
Expand Down
6 changes: 3 additions & 3 deletions test/creator-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var tape = require("tape"),
jsdom = require("jsdom"),
jsdom = require("./jsdom"),
d3 = require("../");

tape("d3.creator(name).call(element) returns a new element with the given name", function(test) {
var document = jsdom.jsdom("<body class='foo'>");
var document = jsdom("<body class='foo'>");
test.deepEqual(type(d3.creator("h1").call(document.body)), {namespace: "http://www.w3.org/1999/xhtml", name: "H1"});
test.deepEqual(type(d3.creator("xhtml:h1").call(document.body)), {namespace: "http://www.w3.org/1999/xhtml", name: "H1"});
test.deepEqual(type(d3.creator("svg").call(document.body)), {namespace: "http://www.w3.org/2000/svg", name: "svg"});
Expand All @@ -12,7 +12,7 @@ tape("d3.creator(name).call(element) returns a new element with the given name",
});

tape("d3.creator(name).call(element) can inherit the namespace from the given element", function(test) {
var document = jsdom.jsdom("<body class='foo'><svg></svg>"),
var document = jsdom("<body class='foo'><svg></svg>"),
svg = document.querySelector("svg");
test.deepEqual(type(d3.creator("g").call(document.body)), {namespace: "http://www.w3.org/1999/xhtml", name: "G"});
test.deepEqual(type(d3.creator("g").call(svg)), {namespace: "http://www.w3.org/2000/svg", name: "g"});
Expand Down
6 changes: 3 additions & 3 deletions test/event-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var tape = require("tape"),
jsdom = require("jsdom"),
jsdom = require("./jsdom"),
d3 = require("../");

tape("d3.event is set exactly during the callback of an event listener", function(test) {
var event,
document = jsdom.jsdom("<h1 id='one'></h1>"),
document = jsdom("<h1 id='one'></h1>"),
one = document.querySelector("#one"),
selection = d3.selectAll([one]).on("click", function() { event = d3.event; });
test.equal(d3.event, null);
Expand All @@ -19,7 +19,7 @@ tape("d3.event is restored to its previous value during reentrant events", funct
var event1,
event2,
event3,
document = jsdom.jsdom("<h1 id='one'></h1>"),
document = jsdom("<h1 id='one'></h1>"),
one = document.querySelector("#one"),
selection = d3.selectAll([one]).on("foo", function() { event1 = d3.event; selection.dispatch("bar"); event3 = d3.event; }).on("bar", function() { event2 = d3.event; });
test.equal(d3.event, null);
Expand Down
5 changes: 5 additions & 0 deletions test/jsdom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var jsdom = require("jsdom");

module.exports = function(html) {
return (new jsdom.JSDOM(html)).window.document;
};
4 changes: 2 additions & 2 deletions test/matcher-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var tape = require("tape"),
jsdom = require("jsdom"),
jsdom = require("./jsdom"),
d3 = require("../");

tape("d3.matcher(selector).call(element) returns true if the element matches the selector", function(test) {
var document = jsdom.jsdom("<body class='foo'>");
var document = jsdom("<body class='foo'>");
test.equal(d3.matcher("body").call(document.body), true);
test.equal(d3.matcher(".foo").call(document.body), true);
test.equal(d3.matcher("body.foo").call(document.body), true);
Expand Down
2 changes: 1 addition & 1 deletion test/namespace-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var tape = require("tape"),
jsdom = require("jsdom"),
jsdom = require("./jsdom"),
d3 = require("../");

tape("d3.namespace(name) returns name if there is no namespace prefix", function(test) {
Expand Down
2 changes: 1 addition & 1 deletion test/namespaces-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var tape = require("tape"),
jsdom = require("jsdom"),
jsdom = require("./jsdom"),
d3 = require("../");

tape("d3.namespaces is the expected map", function(test) {
Expand Down
14 changes: 7 additions & 7 deletions test/select-test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var tape = require("tape"),
jsdom = require("jsdom"),
jsdom = require("./jsdom"),
d3 = require("../");

tape("d3.select(…) returns an instanceof d3.selection", function(test) {
var document = jsdom.jsdom("<h1>hello</h1>");
var document = jsdom("<h1>hello</h1>");
test.ok(d3.select(document) instanceof d3.selection);
test.end();
});

tape("d3.select(string) selects the first element that matches the selector string", function(test) {
var document = global.document = jsdom.jsdom("<h1 id='one'>foo</h1><h1 id='two'>bar</h1>");
var document = global.document = jsdom("<h1 id='one'>foo</h1><h1 id='two'>bar</h1>");
try {
test.deepEqual(d3.select("h1"), {_groups: [[document.querySelector("h1")]], _parents: [document.documentElement]});
test.end();
Expand All @@ -19,26 +19,26 @@ tape("d3.select(string) selects the first element that matches the selector stri
});

tape("d3.select(element) selects the given element", function(test) {
var document = jsdom.jsdom("<h1>hello</h1>");
var document = jsdom("<h1>hello</h1>");
test.deepEqual(d3.select(document.body), {_groups: [[document.body]], _parents: [null]});
test.deepEqual(d3.select(document.documentElement), {_groups: [[document.documentElement]], _parents: [null]});
test.end();
});

tape("d3.select(window) selects the given window", function(test) {
var document = jsdom.jsdom("<h1>hello</h1>");
var document = jsdom("<h1>hello</h1>");
test.deepEqual(d3.select(document.defaultView), {_groups: [[document.defaultView]], _parents: [null]});
test.end();
});

tape("d3.select(document) selects the given document", function(test) {
var document = jsdom.jsdom("<h1>hello</h1>");
var document = jsdom("<h1>hello</h1>");
test.deepEqual(d3.select(document), {_groups: [[document]], _parents: [null]});
test.end();
});

tape("d3.select(null) selects null", function(test) {
var document = jsdom.jsdom("<h1>hello</h1><null></null><undefined></undefined>");
var document = jsdom("<h1>hello</h1><null></null><undefined></undefined>");
test.deepEqual(d3.select(null), {_groups: [[null]], _parents: [null]});
test.deepEqual(d3.select(undefined), {_groups: [[undefined]], _parents: [null]});
test.deepEqual(d3.select(), {_groups: [[undefined]], _parents: [null]});
Expand Down
12 changes: 6 additions & 6 deletions test/selectAll-test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var tape = require("tape"),
jsdom = require("jsdom"),
jsdom = require("./jsdom"),
d3 = require("../");

tape("d3.selectAll(…) returns an instanceof d3.selection", function(test) {
var document = jsdom.jsdom("<h1>hello</h1>");
var document = jsdom("<h1>hello</h1>");
test.ok(d3.selectAll([document]) instanceof d3.selection);
test.end();
});

tape("d3.selectAll(string) selects all elements that match the selector string, in order", function(test) {
var document = global.document = jsdom.jsdom("<h1 id='one'>foo</h1><h1 id='two'>bar</h1>");
var document = global.document = jsdom("<h1 id='one'>foo</h1><h1 id='two'>bar</h1>");
try {
test.deepEqual(d3.selectAll("h1"), {_groups: [document.querySelectorAll("h1")], _parents: [document.documentElement]});
test.end();
Expand All @@ -19,13 +19,13 @@ tape("d3.selectAll(string) selects all elements that match the selector string,
});

tape("d3.selectAll(nodeList) selects a NodeList of elements", function(test) {
var document = jsdom.jsdom("<h1>hello</h1><h2>world</h2>");
var document = jsdom("<h1>hello</h1><h2>world</h2>");
test.deepEqual(d3.selectAll(document.querySelectorAll("h1,h2")), {_groups: [document.querySelectorAll("h1,h2")], _parents: [null]});
test.end();
});

tape("d3.selectAll(array) selects an array of elements", function(test) {
var document = jsdom.jsdom("<h1>hello</h1><h2>world</h2>"),
var document = jsdom("<h1>hello</h1><h2>world</h2>"),
h1 = document.querySelector("h1"),
h2 = document.querySelector("h2");
test.deepEqual(d3.selectAll([h1, h2]), {_groups: [[h1, h2]], _parents: [null]});
Expand Down Expand Up @@ -54,7 +54,7 @@ tape("d3.selectAll(null) selects a new empty array each time", function(test) {
});

tape("d3.selectAll(array) can select an array that contains null", function(test) {
var document = jsdom.jsdom("<h1>hello</h1><h2>world</h2>"),
var document = jsdom("<h1>hello</h1><h2>world</h2>"),
h1 = document.querySelector("h1");
test.deepEqual(d3.selectAll([null, h1, null]), {_groups: [[null, h1, null]], _parents: [null]});
test.end();
Expand Down
30 changes: 15 additions & 15 deletions test/selection/append-test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var tape = require("tape"),
jsdom = require("jsdom"),
jsdom = require("../jsdom"),
d3 = require("../../");

tape("selection.append(…) returns a selection", function(test) {
var document = jsdom.jsdom();
var document = jsdom();
test.ok(d3.select(document.body).append("h1") instanceof d3.selection);
test.end();
});

tape("selection.append(name) appends a new element of the specified name as the last child of each selected element", function(test) {
var document = jsdom.jsdom("<div id='one'><span class='before'></span></div><div id='two'><span class='before'></span></div>"),
var document = jsdom("<div id='one'><span class='before'></span></div><div id='two'><span class='before'></span></div>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
selection = d3.selectAll([one, two]).append("span"),
Expand All @@ -20,7 +20,7 @@ tape("selection.append(name) appends a new element of the specified name as the
});

tape("selection.append(name) observes the specified namespace, if any", function(test) {
var document = jsdom.jsdom("<div id='one'></div><div id='two'></div>"),
var document = jsdom("<div id='one'></div><div id='two'></div>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
selection = d3.selectAll([one, two]).append("svg:g"),
Expand All @@ -34,7 +34,7 @@ tape("selection.append(name) observes the specified namespace, if any", function

tape("selection.append(name) uses createElement, not createElementNS, if the implied namespace is the same as the document", function(test) {
var pass = 0,
document = jsdom.jsdom("<div id='one'></div><div id='two'></div>"),
document = jsdom("<div id='one'></div><div id='two'></div>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
createElement = document.createElement;
Expand All @@ -53,7 +53,7 @@ tape("selection.append(name) uses createElement, not createElementNS, if the imp
});

tape("selection.append(name) observes the implicit namespace, if any", function(test) {
var document = jsdom.jsdom("<div id='one'></div><div id='two'></div>"),
var document = jsdom("<div id='one'></div><div id='two'></div>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
selection = d3.selectAll([one, two]).append("svg"),
Expand All @@ -66,7 +66,7 @@ tape("selection.append(name) observes the implicit namespace, if any", function(
});

tape("selection.append(name) observes the inherited namespace, if any", function(test) {
var document = jsdom.jsdom("<div id='one'></div><div id='two'></div>"),
var document = jsdom("<div id='one'></div><div id='two'></div>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
selection = d3.selectAll([one, two]).append("svg").append("g"),
Expand All @@ -81,7 +81,7 @@ tape("selection.append(name) observes the inherited namespace, if any", function
tape("selection.append(name) observes a custom namespace, if any", function(test) {
try {
d3.namespaces.d3js = "https://d3js.org/2016/namespace";
var document = jsdom.jsdom("<div id='one'></div><div id='two'></div>"),
var document = jsdom("<div id='one'></div><div id='two'></div>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
selection = d3.selectAll([one, two]).append("d3js"),
Expand All @@ -97,7 +97,7 @@ tape("selection.append(name) observes a custom namespace, if any", function(test
});

tape("selection.append(function) appends the returned element as the last child of each selected element", function(test) {
var document = jsdom.jsdom("<div id='one'><span class='before'></span></div><div id='two'><span class='before'></span></div>"),
var document = jsdom("<div id='one'><span class='before'></span></div><div id='two'><span class='before'></span></div>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
selection = d3.selectAll([one, two]).append(function() { return document.createElement("SPAN"); }),
Expand All @@ -108,7 +108,7 @@ tape("selection.append(function) appends the returned element as the last child
});

tape("selection.append(function) passes the creator function data, index and group", function(test) {
var document = jsdom.jsdom("<parent id='one'><child id='three'></child><child id='four'></child></parent><parent id='two'><child id='five'></child></parent>"),
var document = jsdom("<parent id='one'><child id='three'></child><child id='four'></child></parent><parent id='two'><child id='five'></child></parent>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
three = document.querySelector("#three"),
Expand All @@ -131,15 +131,15 @@ tape("selection.append(function) passes the creator function data, index and gro
});

tape("selection.append(…) propagates data if defined on the originating element", function(test) {
var document = jsdom.jsdom("<parent><child>hello</child></parent>"),
var document = jsdom("<parent><child>hello</child></parent>"),
parent = document.querySelector("parent");
parent.__data__ = 0; // still counts as data even though falsey
test.equal(d3.select(parent).append("child").datum(), 0);
test.end();
});

tape("selection.append(…) will not propagate data if not defined on the originating element", function(test) {
var document = jsdom.jsdom("<parent><child>hello</child></parent>"),
var document = jsdom("<parent><child>hello</child></parent>"),
parent = document.querySelector("parent"),
child = document.querySelector("child");
child.__data__ = 42;
Expand All @@ -149,7 +149,7 @@ tape("selection.append(…) will not propagate data if not defined on the origin
});

tape("selection.append(…) propagates parents from the originating selection", function(test) {
var document = jsdom.jsdom("<parent></parent><parent></parent>"),
var document = jsdom("<parent></parent><parent></parent>"),
parents = d3.select(document).selectAll("parent"),
childs = parents.append("child");
test.deepEqual(parents, {_groups: [document.querySelectorAll("parent")], _parents: [document]});
Expand All @@ -159,7 +159,7 @@ tape("selection.append(…) propagates parents from the originating selection",
});

tape("selection.append(…) can select elements when the originating selection is nested", function(test) {
var document = jsdom.jsdom("<parent id='one'><child></child></parent><parent id='two'><child></child></parent>"),
var document = jsdom("<parent id='one'><child></child></parent><parent id='two'><child></child></parent>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
selection = d3.selectAll([one, two]).selectAll("child").append("span"),
Expand All @@ -170,7 +170,7 @@ tape("selection.append(…) can select elements when the originating selection i
});

tape("selection.append(…) skips missing originating elements", function(test) {
var document = jsdom.jsdom("<h1></h1>"),
var document = jsdom("<h1></h1>"),
h1 = document.querySelector("h1"),
selection = d3.selectAll([, h1]).append("span"),
span = h1.querySelector("span");
Expand Down
14 changes: 7 additions & 7 deletions test/selection/attr-test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var tape = require("tape"),
jsdom = require("jsdom"),
jsdom = require("../jsdom"),
d3 = require("../../");

tape("selection.attr(name) returns the value of the attribute with the specified name on the first selected element", function(test) {
var document = jsdom.jsdom("<h1 class='c1 c2'>hello</h1><h1 class='c3'></h1>");
var document = jsdom("<h1 class='c1 c2'>hello</h1><h1 class='c3'></h1>");
test.equal(d3.select(document).select("h1").attr("class"), "c1 c2");
test.equal(d3.selectAll([null, document]).select("h1").attr("class"), "c1 c2");
test.end();
});

tape("selection.attr(name) coerces the specified name to a string", function(test) {
var document = jsdom.jsdom("<h1 class='c1 c2'>hello</h1><h1 class='c3'></h1>");
var document = jsdom("<h1 class='c1 c2'>hello</h1><h1 class='c3'></h1>");
test.equal(d3.select(document).select("h1").attr({toString: function() { return "class"; }}), "c1 c2");
test.end();
});
Expand Down Expand Up @@ -63,7 +63,7 @@ tape("selection.attr(name, null) observes the namespace prefix, if any", functio
});

tape("selection.attr(name, value) sets the value of the attribute with the specified name on the selected elements", function(test) {
var document = jsdom.jsdom("<h1 id='one' class='c1 c2'>hello</h1><h1 id='two' class='c3'></h1>"),
var document = jsdom("<h1 id='one' class='c1 c2'>hello</h1><h1 id='two' class='c3'></h1>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
selection = d3.selectAll([one, two]);
Expand All @@ -74,7 +74,7 @@ tape("selection.attr(name, value) sets the value of the attribute with the speci
});

tape("selection.attr(name, null) removes the attribute with the specified name on the selected elements", function(test) {
var document = jsdom.jsdom("<h1 id='one' foo='bar' class='c1 c2'>hello</h1><h1 id='two' foo='bar' class='c3'></h1>"),
var document = jsdom("<h1 id='one' foo='bar' class='c1 c2'>hello</h1><h1 id='two' foo='bar' class='c3'></h1>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
selection = d3.selectAll([one, two]);
Expand All @@ -85,7 +85,7 @@ tape("selection.attr(name, null) removes the attribute with the specified name o
});

tape("selection.attr(name, function) sets the value of the attribute with the specified name on the selected elements", function(test) {
var document = jsdom.jsdom("<h1 id='one' class='c1 c2'>hello</h1><h1 id='two' class='c3'></h1>"),
var document = jsdom("<h1 id='one' class='c1 c2'>hello</h1><h1 id='two' class='c3'></h1>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
selection = d3.selectAll([one, two]);
Expand All @@ -96,7 +96,7 @@ tape("selection.attr(name, function) sets the value of the attribute with the sp
});

tape("selection.attr(name, function) passes the value function data, index and group", function(test) {
var document = jsdom.jsdom("<parent id='one'><child id='three'></child><child id='four'></child></parent><parent id='two'><child id='five'></child></parent>"),
var document = jsdom("<parent id='one'><child id='three'></child><child id='four'></child></parent><parent id='two'><child id='five'></child></parent>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
three = document.querySelector("#three"),
Expand Down
6 changes: 3 additions & 3 deletions test/selection/call-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var tape = require("tape"),
jsdom = require("jsdom"),
jsdom = require("../jsdom"),
d3 = require("../../");

tape("selection.call(function) calls the specified function, passing the selection", function(test) {
var result,
document = jsdom.jsdom(),
document = jsdom(),
selection = d3.select(document);
test.equal(selection.call(function(selection) { result = selection; }), selection);
test.equal(result, selection);
Expand All @@ -15,7 +15,7 @@ tape("selection.call(function, arguments…) calls the specified function, passi
var result = [],
foo = {},
bar = {},
document = jsdom.jsdom(),
document = jsdom(),
selection = d3.select(document);
test.equal(selection.call(function(selection, a, b) { result.push(selection, a, b); }, foo, bar), selection);
test.deepEqual(result, [selection, foo, bar]);
Expand Down
Loading

0 comments on commit eba2a94

Please sign in to comment.