最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

testing - Karma: Is it possible to load JavaScript files statically before the requirejs framework? - Stack Overflow

programmeradmin0浏览0评论

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

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'
        ]
    });
}
Share Improve this question asked Mar 6, 2014 at 15:10 aknuds1aknuds1 68.2k69 gold badges206 silver badges320 bronze badges 2
  • 1 See github./karma-runner/karma/issues/699 – Vojta Commented Mar 7, 2014 at 23:04
  • This presentation will give you a quick look at how it could be done: believeblog.azurewebsites/post/… – Believe2014 Commented Jun 13, 2014 at 21:06
Add a ment  | 

1 Answer 1

Reset to default 5

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论