2014-12-02 92 views
0

我一直試圖讓Karma幾乎整天工作。出於某種原因,我無法讓Karma實際運行測試。相反,它似乎無限期地閒置,沒有任何跡象表明成功或失敗。Karma + Jasmine + RequireJS未運行規格

我注意到當Karma在Chrome中執行時單擊調試按鈕時,打開的Debug Runner不會呈現任何東西。我也注意到調試確實會加載項目庫,但非調試模式只加載karma.js和socketio。

下面是運行karma start後的調試日誌:

karma.conf.js

// Karma configuration 
// Generated on Tue Dec 02 2014 11:07:40 GMT-0500 (EST) 

module.exports = function(config) { 
    config.set({ 

    // base path that will be used to resolve all patterns (eg. files, exclude) 
    basePath: '', 


    // frameworks to use 
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 
    frameworks: ['jasmine', 'requirejs'], 


    // list of files/patterns to load in the browser 
    files: [ 
     {pattern: 'lib/jquery/dist/jquery.js', included: false}, 
     {pattern: 'lib/dynatable/jquery.dynatable.js', included: false}, 
     {pattern: 'app/**/*.js', included: false}, 
     {pattern: 'test/**/*Spec.js', included: false}, 
    ], 


    // list of files to exclude 
    exclude: ['app.js' 
    ], 


    // preprocess matching files before serving them to the browser 
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 
    preprocessors: { 
    }, 


    // test results reporter to use 
    // possible values: 'dots', 'progress' 
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter 
    reporters: ['progress'], 


    // web server port 
    port: 9876, 


    // enable/disable colors in the output (reporters and logs) 
    colors: true, 


    // level of logging 
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 
    //logLevel: config.LOG_INFO, 
     logLevel: config.LOG_DEBUG, 


    // enable/disable watching file and executing tests whenever any file changes 
    autoWatch: true, 


    // start these browsers 
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 
    browsers: ['Chrome'], 


    // Continuous Integration mode 
    // if true, Karma captures browsers, runs the tests and exits 
    singleRun: false 
    }); 
}; 

DEBUG [plugin]: Loading karma-* from /usr/local/lib/node_modules 
DEBUG [plugin]: Loading plugin /usr/local/lib/node_modules/karma-chrome-launcher. 
DEBUG [plugin]: Loading plugin /usr/local/lib/node_modules/karma-jasmine. 
DEBUG [plugin]: Loading plugin /usr/local/lib/node_modules/karma-requirejs. 
INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/ 
INFO [launcher]: Starting browser Chrome 
DEBUG [temp-dir]: Creating temp dir at /var/folders/1y/g2l4xc656ds_0_grl0pz3fnm0000gn/T/karma-14051726 
DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/1y/g2l4xc656ds_0_grl0pz3fnm0000gn/T/karma-14051726 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate http://localhost:9876/?id=14051726 
DEBUG [watcher]: Resolved files: 
/usr/local/lib/node_modules/requirejs/require.js 
/usr/local/lib/node_modules/karma-requirejs/lib/adapter.js 
/usr/local/lib/node_modules/jasmine-core/lib/jasmine-core/jasmine.js 
/usr/local/lib/node_modules/karma-jasmine/lib/boot.js 
/usr/local/lib/node_modules/karma-jasmine/lib/adapter.js 
/Users/christopherdrane/chrome/js/lib/jquery/dist/jquery.js 
/Users/christopherdrane/chrome/js/lib/dynatable/jquery.dynatable.js 
/Users/csd/chrome/js/app/main.js 
/Users/csd/chrome/js/test/appSpec.js 
DEBUG [watcher]: Watching "/Users/csd/chrome/js/lib/jquery/dist/jquery.js" 
DEBUG [watcher]: Watching "/Users/csd/chrome/js/lib/dynatable/jquery.dynatable.js" 
DEBUG [watcher]: Watching "/Users/csd/chrome/js/app" 
DEBUG [watcher]: Watching "/Users/csd/chrome/js/test" 
DEBUG [watcher]: Add file "/Users/csd/chrome/js/lib/dynatable/jquery.dynatable.js" ignored. Already in the list. 
DEBUG [watcher]: Add file "/Users/csd/chrome/js/app/main.js" ignored. Already in the list. 
DEBUG [watcher]: Add file "/Users/csd/chrome/js/test/appSpec.js" ignored. Already in the list. 
DEBUG [web-server]: serving: /usr/local/lib/node_modules/karma/static/client.html 
DEBUG [web-server]: serving: /usr/local/lib/node_modules/karma/static/karma.js 
DEBUG [web-server]: upgrade /socket.io/1/websocket/PuC65cs3e7EVlDAU1p00 
DEBUG [karma]: A browser has connected on socket PuC65cs3e7EVlDAU1p00 
INFO [Chrome 39.0.2171 (Mac OS X 10.8.5)]: Connected on socket PuC65cs3e7EVlDAU1p00 with id 14051726 
DEBUG [launcher]: Chrome (id 14051726) captured in 4.614 secs 
DEBUG [karma]: All browsers are ready, executing 
DEBUG [web-server]: serving: /usr/local/lib/node_modules/karma/static/context.html 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/requirejs/require.js 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/karma-requirejs/lib/adapter.js 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/jasmine-core/lib/jasmine-core/jasmine.js 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/karma-jasmine/lib/boot.js 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/karma-jasmine/lib/adapter.js 
DEBUG [Chrome 39.0.2171 (Mac OS X 10.8.5)]: Disconnected during run, waiting 2000ms for reconnecting. 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/karma/static/client.html 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/karma/static/karma.js 
DEBUG [web-server]: upgrade /socket.io/1/websocket/BSX21Oc05-qDhfgn1p01 
DEBUG [karma]: A browser has connected on socket BSX21Oc05-qDhfgn1p01 
DEBUG [Chrome 39.0.2171 (Mac OS X 10.8.5)]: Reconnected on BSX21Oc05-qDhfgn1p01. 
DEBUG [web-server]: serving: /usr/local/lib/node_modules/karma/static/debug.html 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/requirejs/require.js 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/karma-requirejs/lib/adapter.js 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/jasmine-core/lib/jasmine-core/jasmine.js 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/karma-jasmine/lib/adapter.js 
DEBUG [web-server]: serving (cached): /usr/local/lib/node_modules/karma-jasmine/lib/boot.js 
WARN [Chrome 39.0.2171 (Mac OS X 10.8.5)]: Disconnected (1 times), because no message in 10000 ms. 

該項目相關的結構爲

/js 
-> app.js (require.config) 
-> karma.conf.js 
-> /app 
---> main.js 
-> /lib 
---> /dynatable 
---> /jasmine 
---> /jquery 
---> /requirejs 
-> /test 
-> appSpec.js 
-> test-main.js 

而且

測試main.js

var allTestFiles = []; 
var TEST_REGEXP = /(spec|test)\.js$/i; 

var pathToModule = function(path) { 
    return path.replace(/^\/base\//, '').replace(/\.js$/, ''); 
}; 

Object.keys(window.__karma__.files).forEach(function(file) { 
    if (TEST_REGEXP.test(file)) { 
    // Normalize paths to RequireJS module names. 
    allTestFiles.push(pathToModule(file)); 
    } 
}); 

require.config({ 
    // Karma serves files under /base, which is the basePath from your config file 
    baseUrl: '/base', 

    paths: { 
    jquery: 'lib/jquery/dist/jquery', 
    dynatable: 'lib/dynatable/jquery.dynatable'}, 

    shim: { 
    dynatable: { 
     deps: ['jquery'] 
     } 
    }, 

    // dynamically load all test files 
    deps: allTestFiles, 

    // we have to kickoff jasmine, as it is asynchronous 
    callback: window.__karma__.start 
}); 

回答

0

事實證明,我正在一個小錯誤:我忘了,包括在文件test-main.js。我試圖修復與「缺少時間戳」有關的另一個錯誤時,我無意中刪除了對test-main的引用。

我的/ lib /目錄包含了使用git clone <jquery>所得到的全部內容,最初我寫了我的files以包含{pattern: 'lib/**/*.js', included: false}。 Karma不喜歡這一點,但不幸的是,由於糟糕的錯誤消息,我花了一段時間來診斷問題。

希望這將有助於未來的其他人。

相關問題