karma-junit-reporter未得到承认

时间:2015-07-02 18:05:04

标签: javascript junit jasmine karma-runner

我正在尝试运行测试并使用业力生成报告。我已经安装了karma-junit-reporter,但在命令行上继续收到以下消息:

Cannot find plugin "karma-junit-reporter"

Can not load "junit", it is not registered

我的karma.config.js:

plugins : [
    'karma-jasmine',
    'karma-junit-reporter',
    'karma-phantomjs-launcher'
]

我的package.json:

"devDependencies": {
  "grunt": "0.4.5",
  "grunt-cli": "0.1.13",
  "grunt-env": "0.4.2",
  "grunt-exec": "0.4.6",
  "grunt-jasmine-node": "0.2.1",
  "grunt-jasmine-node-coverage": "0.1.10",
  "grunt-jscs": "1.8.0",
  "grunt-karma": "0.11.2",
  "jasmine-core": "2.3.4",
  "jasmine-node": "1.14.3",
  "jasmine-reporters": "0.4.1",
  "jscs": "1.13.1",
  "jshint": "2.4.4",
  "karma": "0.12.37",
  "karma-jasmine": "0.3.6",
  "karma-junit-reporter": "0.2.2",
  "karma-phantomjs-launcher": "0.2.0",
  "phantomjs": "1.9.17",
  "supertest": "0.9.0"
}

1 个答案:

答案 0 :(得分:2)

确保您运行npm install并且所有插件依赖项都在您的package.json中,如@ssube提到的那样是一个很好的起点。话虽这么说,这对我有用:

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

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

    browsers: ["PhantomJS"],

    frameworks: ["jasmine-jquery" ,"jasmine"],

    files: [
        {
            pattern: "test/**/*.html",
            included: false,
            served: true,
            watched: true
        },
        "dist/latest/phone.min.js",
        "node_modules/jquery/dist/jquery.js"
        {
            pattern: "test/functional/test/phoneTest.js",
            watched: true
        }
    ], plugins: [
        "karma-jasmine-jquery",
        "karma-phantomjs-launcher",
        "karma-junit-reporter",
        "karma-jasmine"
    ],

    client: {
        "captureConsole": true
    },

    phantomjsLauncher: {
        // Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom) 
        exitOnResourceError: true
    },

    singleRun: true,

    reporters: ['progress', 'junit'],

    junitReporter: {
        outputDir: "testResults",
        outputFile: "FUNCTIONAL-TEST-results.xml"
    }
 });
};