Karma: Is it possible to load JavaScript files statically before the requirejs framework?

情到浓时终转凉″ 提交于 2019-12-23 03:20:06

问题


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).

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'
        ]
    });
}

回答1:


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.



来源:https://stackoverflow.com/questions/22228399/karma-is-it-possible-to-load-javascript-files-statically-before-the-requirejs-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!