问题描述
我想知道是否可以配置Karma(0.10.9)在 requirejs 框架?我要问的原因是,如果Knockout在RequireJS之前已包含在RequireJS中,则将其注册为模块,这会破坏另一个模块(不支持RequireJS).
I'm wondering if it's possible to configure Karma (0.10.9) to load certain JavaScript files before its requirejs framework? The reason I'm asking is that Knockout registers as a module with RequireJS if the latter has been included before Knockout, and this breaks another module (which doesn't support RequireJS).
基本上,我们的karma.conf.js如下所示:
Basically, our karma.conf.js looks as below:
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'
]
});
}
推荐答案
显然,可以通过手动包括karma-requirejs文件而不在框架中包括它来完成:
Apparently it can be done by manually including karma-requirejs files and not including it among the frameworks:
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}
]
请参阅此业力问题以供参考.
See this Karma issue for reference.
这篇关于业力:是否可以在requirejs框架之前静态加载JavaScript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!