Karma,空的测试套件

时间:2015-12-14 15:53:25

标签: testing karma-runner karma-jasmine

首先,我知道有类似的问题,但这些问题都不适用于我。

我有一个Angular应用程序,我想用Karma,Jasmin和RequireJs测试它。

我已经安装了我需要的所有内容,并配置了所有内容:http://karma-runner.github.io/0.13/plus/requirejs.html

以下是我的文件的样子

karma.conf.js

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
      basePath: '',

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine', 'requirejs'],


    // list of files / patterns to load in the browser
    files: [
        'src/test/Tests/*.js',
        'src/test/Tests/directives/*.js',

        //source code
        {pattern: 'src/main/webapp/app/*.js', included: false},
        {pattern: 'src/main/webapp/app/**/*.js', included: false},

        {pattern: 'src/test/test-main.js', included: true}
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
        'test/Tests/*.js': 'coverage'
    },

      coverageReporter:{
          type:'html',
          dir:'../coverage/'
      },
    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
      reporters: ['progress', 'coverage'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['PhantomJS'],

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultanous
    concurrency: Infinity
  })
}

测试main.js

var TEST_REGEXP = /(spec|test)\.js$/i;
var allTestFiles = [];

// Get a list of all the test files to include
Object.keys(window.__karma__.files).forEach(function(file) {
    if (TEST_REGEXP.test(file)) {
        // Normalize paths to RequireJS module names.
        // If you require sub-dependencies of test files to be loaded as-is (requiring file extension)
        // then do not normalize the paths
        var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, '');
        allTestFiles.push(normalizedTestModule);
    }
});

require.config({
    // Karma serves files under /base, which is the basePath from your config file
    baseUrl: '/base',

    //dynamically load all test files
    deps: allTestFiles,

    // we have to kickoff jasmine, as it is asynchronous
    callback: window.__karma__.start
});

输出在IntelliJ IDEA 14.1.5

空的测试套件。

处理完成,退出代码为0

服务器正常启动。我也试过命令行。 $ karma start,$ karma run,也什么也没做。根本没有错误消息。路径正确,没有404错误。

你有什么猜测可能是什么问题吗?

1 个答案:

答案 0 :(得分:0)

从测试文件中删除模块名称。

就我而言,这就是解决方案。

根据RequireJS文档(http://requirejs.org/docs/api.html#modulename),您可以包含模块的名称,如下所示:

//Explicitly defines the "foo/title" module:
define("foo/title",
    ["my/cart", "my/inventory"],
    function(cart, inventory) {
        //Define foo/title object in here.
   }
);

但对我来说,如果我删除" foo / title" 名称,Karma只会执行测试。