2014-03-06 63 views
1

我想知道是否可以配置Karma(0.10.9)在其requirejs框架之前加載某些JavaScript文件?我要問的原因是Knockout註冊爲RequireJS模塊,如果後者已經包含在Knockout之前,並且這打破了另一個模塊(它不支持RequireJS)。Karma:是否可以在requirejs框架之前靜態加載JavaScript文件?

基本上,我們karma.conf.js看起來如下:

module.exports = function (config) { 
    config.set({ 
     basePath: "Scripts", 
     frameworks: ['mocha', 'requirejs'], 
     files: [ 
      "knockout-2.2.1.debug.js", 
      "knockout.viewmodel.2.0.3.js", 
      {pattern: "test/**/*.js", included: false}, 
      {pattern: "shared/**/*.js", included: false}, 
      {pattern: "app/**/*.js", included: false}, 
     ], 
     reporters: ['progress', 'growl'], 
     // web server port 
     // CLI --port 9876 
     port: 9876, 
     // cli runner port 
     // CLI --runner-port 9100 
     runnerPort: 9100, 
     autoWatch: true, 
     browsers: ["PhantomJS"], 
     // If browser does not capture in given timeout [ms], kill it 
     // CLI --capture-timeout 5000 
     captureTimeout: 5000, 
     // Auto run tests on start (when browsers are captured) and exit 
     // CLI --single-run --no-single-run 
     singleRun: false, 
     // report which specs are slower than 500ms 
     // CLI --report-slower-than 500 
     reportSlowerThan: 500, 
     plugins: [ 
      'karma-mocha', 
      'karma-phantomjs-launcher', 
      'karma-growl-reporter', 
      'karma-requirejs' 
     ] 
    }); 
} 
+1

查看https://github.com/karma-runner/karma/issues/699 – Vojta

+0

@Vojta謝謝! – aknuds1

+0

本演示文稿將簡要介紹如何完成此項工作:http://believeblog.azurewebsites.net/post/learn-knockoutjs-with-its-father – Believe2014

回答

3

顯然,它可以通過手動包括卡瑪requirejs文件,而不是包括它的框架中來完成:

frameworks: ['mocha'], 
files: [  
    "knockout-2.2.1.debug.js", 
    "knockout.viewmodel.2.0.3.js", 
    'node_modules/requirejs/require.js', 
    'node_modules/karma-requirejs/lib/adapter.js', 
    {pattern: "test/**/*.js", included: false}, 
    {pattern: "shared/**/*.js", included: false}, 
    {pattern: "app/**/*.js", included: false} 
] 

請參閱此Karma issue以供參考。

相關問題