2013-11-05 30 views
0

當使用我現有的角度應用程序設置E2E測試時,由於我在我的應用程序中使用了socket.io,因此無法啓動。量角器無法找到通常由節點模塊提供的socket.io文件,因爲它不是我個人代碼的一部分。AngularJS量角器和Socket.IO

我收到錯誤:

UnknownError: Error Message => 'Can't find variable: io' 

在角側:

angular.module('socket.io', []).factory(function($rootScope) { 
    var socket = io.connect(); // I believe the error is being thrown from here 
    return { 
    on: function (eventName, callback) { 
     socket.on(eventName, function() {...}); 
    }, 
    emit: function (eventName, data, callback) { 
     socket.emit(eventName, data, function() {...}); 
    } 
    }; 
}); 

我相信,這是因爲它通常是由節點模塊提供服務:

<script type="text/javascript" src='/socket.io/socket.io.js'></script> 

VS我上面顯示的socket.io工廠

<script type="text/javascript" src='js/services/socket-service.js'></script> 

有沒有辦法解決這個問題,而無需將socket.io.js文件複製到客戶端代碼庫?

回答

0

確保在socket-service.js之前包含文件socket.io.js。你可以這樣做手動或使用模塊加載器,如requirejs(http://www.requirejs.org

+0

這是一個好點,但我不認爲這是問題。在我的socket-service.js引用它之前,我確實要加載socket.io.js文件。如果我將socket.io.js文件從node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js複製到我的客戶端文件存儲位置(並適當引用它),則所有內容作品。我只是不想做這一步。 – nathasm