Karma:是否有可能在requirejs框架之前静态加载JavaScript文件?

时间:2014-03-06 15:10:26

标签: javascript testing knockout.js requirejs karma-runner

我想知道是否可以配置Karma(0.10.9)在requirejs框架之前加载某些JavaScript文件?我问的原因是Knockout注册为具有RequireJS的模块,如果后者在Knockout之前被包含,则会打破另一个模块(不支持RequireJS)。

基本上,我们的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 个答案:

答案 0 :(得分:3)

显然可以通过手动包含karma-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以供参考。