@@ -80,7 +80,6 @@ define(function (require, exports, module) {
8080 var selectedSuites ,
8181 params = new UrlParams ( ) ,
8282 reporter ,
83- _nodeConnectionDeferred = new $ . Deferred ( ) ,
8483 reporterView ,
8584 _writeResults = new $ . Deferred ( ) ,
8685 _writeResultsPromise = _writeResults . promise ( ) ,
@@ -275,39 +274,6 @@ define(function (require, exports, module) {
275274 }
276275
277276 function init ( ) {
278- // Start up the node connection, which is held in the
279- // _nodeConnectionDeferred module variable. (Use
280- // _nodeConnectionDeferred.done() to access it.
281-
282- // This is in SpecRunner rather than SpecRunnerUtils because the hope
283- // is to hook up jasmine-node tests in this test runner.
284-
285- // TODO: duplicates code from StaticServer
286- // TODO: can this be done lazily?
287-
288- var connectionTimeout = setTimeout ( function ( ) {
289- console . error ( "[SpecRunner] Timed out while trying to connect to node" ) ;
290- _nodeConnectionDeferred . reject ( ) ;
291- } , NODE_CONNECTION_TIMEOUT ) ;
292-
293- var _nodeConnection = new NodeConnection ( ) ;
294- _nodeConnection . connect ( true ) . then ( function ( ) {
295- var domainPath = FileUtils . getNativeBracketsDirectoryPath ( ) + "/" + FileUtils . getNativeModuleDirectoryPath ( module ) + "/../test/node/TestingDomain" ;
296-
297- _nodeConnection . loadDomains ( domainPath , true )
298- . then (
299- function ( ) {
300- clearTimeout ( connectionTimeout ) ;
301- _nodeConnectionDeferred . resolve ( _nodeConnection ) ;
302- } ,
303- function ( ) { // Failed to connect
304- console . error ( "[SpecRunner] Failed to connect to node" , arguments ) ;
305- clearTimeout ( connectionTimeout ) ;
306- _nodeConnectionDeferred . reject ( ) ;
307- }
308- ) ;
309- } ) ;
310-
311277 selectedSuites = ( params . get ( "suite" ) || localStorage . getItem ( "SpecRunner.suite" ) || "unit" ) . split ( "," ) ;
312278
313279 // Create a top-level filter to show/hide performance and extensions tests
@@ -410,19 +376,29 @@ define(function (require, exports, module) {
410376 } , true ) ;
411377 }
412378
413- /**
414- * Allows access to the deferred that manages the node connection for tests.
415- *
416- * @return {jQuery.Deferred } The deferred that manages the node connection
417- */
418- function getNodeConnectionDeferred ( ) {
419- return _nodeConnectionDeferred ;
379+ function connectToTestDomain ( ) {
380+ var _nodeConnectionDeferred = new $ . Deferred ( ) ,
381+ _nodeConnection = new NodeConnection ( ) ;
382+
383+ _nodeConnection . connect ( true ) . then ( function ( ) {
384+ var domainPath = FileUtils . getNativeBracketsDirectoryPath ( ) + "/" + FileUtils . getNativeModuleDirectoryPath ( module ) + "/../test/node/TestingDomain" ;
385+
386+ _nodeConnection . loadDomains ( domainPath , true )
387+ . then ( init , function ( ) {
388+ // Failed to connect
389+ console . error ( "[SpecRunner] Failed to connect to node" , arguments ) ;
390+
391+ var container = $ ( '<div class="container-fluid">' ) ;
392+ container . append ( '<div class="alert alert-error">Failed to connect to Node</div>' ) ;
393+
394+ $ ( window . document . body ) . append ( container ) ;
395+ } ) ;
396+ } ) ;
397+
398+ Async . withTimeout ( _nodeConnectionDeferred . promise ( ) , NODE_CONNECTION_TIMEOUT ) ;
399+
400+ brackets . testing = { nodeConnection : _nodeConnection } ;
420401 }
421402
422- // this is used by SpecRunnerUtils
423- brackets . testing = {
424- getNodeConnectionDeferred : getNodeConnectionDeferred
425- } ;
426-
427- init ( ) ;
403+ connectToTestDomain ( ) ;
428404} ) ;
0 commit comments