@@ -60,16 +60,6 @@ export class TestBrokerViewModel extends observable.Observable {
60
60
constructor ( ) {
61
61
super ( ) ;
62
62
63
- // used in engine.io-parser
64
- global . navigator = {
65
- userAgent : 'nativescript' ,
66
- } ;
67
- global . document = {
68
- documentElement : {
69
- style : { }
70
- }
71
- } ;
72
-
73
63
global . __karma__ = this ;
74
64
75
65
if ( config . options . debugTransport ) {
@@ -149,6 +139,16 @@ export class TestBrokerViewModel extends observable.Observable {
149
139
this . baseUrl = 'http://' + this . networkConfig . reachableIp + ':' + this . networkConfig . port ;
150
140
console . log ( 'NSUTR: connecting to karma at ' + this . baseUrl ) ;
151
141
142
+ // shims for engine.io-parser
143
+ global . navigator = {
144
+ userAgent : 'nativescript' ,
145
+ } ;
146
+ global . document = {
147
+ documentElement : {
148
+ style : { }
149
+ }
150
+ } ;
151
+
152
152
var io = require ( './socket.io' ) ;
153
153
this . set ( 'serverInfo' , 'connecting to ' + this . baseUrl ) ;
154
154
var socket = this . socket = io . connect ( this . baseUrl , {
@@ -164,6 +164,9 @@ export class TestBrokerViewModel extends observable.Observable {
164
164
socket . on ( 'connect' , err => {
165
165
console . log ( 'NSUTR: successfully connected to karma' ) ;
166
166
167
+ delete global . navigator ;
168
+ delete global . document ;
169
+
167
170
connected ( ) ;
168
171
169
172
this . set ( 'isConnected' , true ) ;
@@ -354,17 +357,10 @@ export class TestBrokerViewModel extends observable.Observable {
354
357
355
358
private loadShim ( url : string ) {
356
359
if ( url . indexOf ( 'mocha' ) !== - 1 ) {
357
- if ( ! global . window ) {
358
- global . window = global ;
359
- }
360
- if ( ! global . location ) {
361
- global . location = { } ;
362
- }
363
- if ( ! global . location . href ) {
364
- global . location . href = '/' ;
365
- }
366
- if ( ! global . document . getElementById ) {
367
- global . document . getElementById = id => null ;
360
+ global . window = global ;
361
+ global . location = { href : '/' } ;
362
+ global . document = {
363
+ getElementById : id => null
368
364
}
369
365
} else if ( url . indexOf ( 'chai' ) !== - 1 ) {
370
366
global . __shim_require = global . require ;
@@ -381,6 +377,11 @@ export class TestBrokerViewModel extends observable.Observable {
381
377
}
382
378
383
379
private completeLoading ( url : string ) {
380
+ if ( url . indexOf ( 'mocha' ) !== - 1 ) {
381
+ delete global . window ;
382
+ //delete global.location;
383
+ delete global . document ;
384
+ }
384
385
if ( url . indexOf ( 'chai' ) !== - 1 ) {
385
386
delete global . window ;
386
387
global . require = global . __shim_require ;
0 commit comments