-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix-d3-global' into 3.4.13
- Loading branch information
Showing
2 changed files
with
26 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
var document = require("jsdom").jsdom("<html><head></head><body></body></html>"), | ||
window = document.parentWindow, | ||
var document = require("jsdom").jsdom(), | ||
globals = {}; | ||
|
||
// stash globals | ||
// Stash old globals. | ||
if ("d3" in global) globals.d3 = global.d3; | ||
if ("window" in global) globals.window = global.window; | ||
global.window = window; | ||
if ("document" in global) globals.document = global.document; | ||
global.document = document; | ||
|
||
// https://github.com/chad3814/CSSStyleDeclaration/issues/3 | ||
var CSSStyleDeclaration_prototype = window.CSSStyleDeclaration.prototype, | ||
CSSStyleDeclaration_setProperty = CSSStyleDeclaration_prototype.setProperty; | ||
CSSStyleDeclaration_prototype.setProperty = function(name, value, priority) { | ||
return CSSStyleDeclaration_setProperty.call(this, name + "", value == null ? null : value + "", priority == null ? null : priority + ""); | ||
}; | ||
// Set temporary globals to pretend we’re in a browser. | ||
global.window = document.parentWindow; | ||
global.document = document; | ||
|
||
module.exports = require("./d3"); | ||
|
||
// restore globals | ||
if ("window" in globals) global.window = globals.window; | ||
else delete global.window; | ||
if ("document" in globals) global.document = globals.document; | ||
else delete global.document; | ||
// Restore old globals. | ||
if ("d3" in globals) global.d3 = globals.d3; else delete global.d3; | ||
if ("window" in globals) global.window = globals.window; else delete global.window; | ||
if ("document" in globals) global.document = globals.document; else delete global.document; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var vows = require("vows"), | ||
assert = require("./assert"); | ||
|
||
var suite = vows.describe("d3"); | ||
|
||
require("../"); | ||
|
||
suite.addBatch({ | ||
"d3": { | ||
"is not a global when require’d": function() { | ||
assert.equal("d3" in global, false); | ||
} | ||
} | ||
}); | ||
|
||
suite.export(module); |