@@ -60,16 +60,6 @@ export class TestBrokerViewModel extends observable.Observable {
6060 constructor ( ) {
6161 super ( ) ;
6262
63- // used in engine.io-parser
64- global . navigator = {
65- userAgent : 'nativescript' ,
66- } ;
67- global . document = {
68- documentElement : {
69- style : { }
70- }
71- } ;
72-
7363 global . __karma__ = this ;
7464
7565 if ( config . options . debugTransport ) {
@@ -149,6 +139,16 @@ export class TestBrokerViewModel extends observable.Observable {
149139 this . baseUrl = 'http://' + this . networkConfig . reachableIp + ':' + this . networkConfig . port ;
150140 console . log ( 'NSUTR: connecting to karma at ' + this . baseUrl ) ;
151141
142+ // shims for engine.io-parser
143+ global . navigator = {
144+ userAgent : 'nativescript' ,
145+ } ;
146+ global . document = {
147+ documentElement : {
148+ style : { }
149+ }
150+ } ;
151+
152152 var io = require ( './socket.io' ) ;
153153 this . set ( 'serverInfo' , 'connecting to ' + this . baseUrl ) ;
154154 var socket = this . socket = io . connect ( this . baseUrl , {
@@ -164,6 +164,9 @@ export class TestBrokerViewModel extends observable.Observable {
164164 socket . on ( 'connect' , err => {
165165 console . log ( 'NSUTR: successfully connected to karma' ) ;
166166
167+ delete global . navigator ;
168+ delete global . document ;
169+
167170 connected ( ) ;
168171
169172 this . set ( 'isConnected' , true ) ;
@@ -354,17 +357,10 @@ export class TestBrokerViewModel extends observable.Observable {
354357
355358 private loadShim ( url : string ) {
356359 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
368364 }
369365 } else if ( url . indexOf ( 'chai' ) !== - 1 ) {
370366 global . __shim_require = global . require ;
@@ -381,6 +377,11 @@ export class TestBrokerViewModel extends observable.Observable {
381377 }
382378
383379 private completeLoading ( url : string ) {
380+ if ( url . indexOf ( 'mocha' ) !== - 1 ) {
381+ delete global . window ;
382+ //delete global.location;
383+ delete global . document ;
384+ }
384385 if ( url . indexOf ( 'chai' ) !== - 1 ) {
385386 delete global . window ;
386387 global . require = global . __shim_require ;
0 commit comments