File tree Expand file tree Collapse file tree 2 files changed +26
-9
lines changed
Expand file tree Collapse file tree 2 files changed +26
-9
lines changed Original file line number Diff line number Diff line change 1- var document = require ( "jsdom" ) . jsdom ( "<html><head></head><body></body></html>" ) ,
2- window = document . parentWindow ,
1+ var document = require ( "jsdom" ) . jsdom ( ) ,
32 globals = { } ;
43
5- // stash globals
4+ // Stash old globals.
5+ if ( "d3" in global ) globals . d3 = global . d3 ;
66if ( "window" in global ) globals . window = global . window ;
7- global . window = window ;
87if ( "document" in global ) globals . document = global . document ;
8+
9+ // Set temporary globals to pretend we’re in a browser.
10+ global . window = document . parentWindow ;
911global . document = document ;
1012
1113module . exports = require ( "./d3" ) ;
1214
13- // restore globals
14- if ( "window" in globals ) global . window = globals . window ;
15- else delete global . window ;
16- if ( "document" in globals ) global . document = globals . document ;
17- else delete global . document ;
15+ // Restore old globals.
16+ if ( "d3" in globals ) global . d3 = globals . d3 ; else delete global . d3 ;
17+ if ( "window" in globals ) global . window = globals . window ; else delete global . window ;
18+ if ( "document" in globals ) global . document = globals . document ; else delete global . document ;
Original file line number Diff line number Diff line change 1+ var vows = require ( "vows" ) ,
2+ assert = require ( "./assert" ) ;
3+
4+ var suite = vows . describe ( "d3" ) ;
5+
6+ require ( "../" ) ;
7+
8+ suite . addBatch ( {
9+ "d3" : {
10+ "is not a global when require’d" : function ( ) {
11+ assert . equal ( "d3" in global , false ) ;
12+ }
13+ }
14+ } ) ;
15+
16+ suite . export ( module ) ;
You can’t perform that action at this time.
0 commit comments