2017-09-21 20 views
1

我正在使用karmaangular-cli使用jasminejavascript来运行测试用例。karma-htmlfile-reporter关于业力开始没有给出html输出

在我的karma.config文件中,我添加了这些行。

reporters: ['progress','html'], 


htmlReporter: { 
    outputFile: 'test/units.html' 
}, 

,我在命令提示符下

karma start --reporters html 

而是获得测试用例结果我只有这些得到运行此命令。

enter image description here

编辑: 新增karma.conf.js

// Karma configuration 
// Generated on Tue Sep 26 2017 18:46:51 GMT+0530 (India Standard Time) 

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'], 


    // list of files/patterns to load in the browser 
    files: [ 
     'test-main.js', 
     'js/*.js', 
     'test/*.js' 
    ], 


    // 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 results reporter to use 
    // possible values: 'dots', 'progress' 
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter 

    client: { 
     clearContext: false 
    }, 
    reporters: ['kjhtml','html'], 

    plugins: ['karma-chrome-launcher', 
     'karma-firefox-launcher', 
     'karma-jasmine', 
     'karma-jasmine-html-reporter'], 

    // 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: ['Chrome'], 


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

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

新增的package.json

{ 
    "name": "test", 
    "version": "1.0.0", 
    "description": "", 
    "main": "karma.conf.js", 
    "directories": { 
    "test": "test" 
    }, 
    "dependencies": { 
    "jasmine": "^2.7.0", 
    "karma": "^1.7.0", 
    "karma-chrome-launcher": "^2.2.0", 
    "karma-firefox-launcher": "^1.0.1", 
    "karma-ie-launcher": "^1.0.0", 
    "karma-jasmine": "^1.1.0", 
    "karma-requirejs": "^1.1.0" 
    }, 
    "devDependencies": { 
    "jasmine": "^2.8.0", 
    "jasmine-core": "^2.8.0", 
    "karma": "^1.7.1", 
    "karma-chrome-launcher": "^2.2.0", 
    "karma-htmlfile-reporter": "~0.3", 
    "karma-jasmine": "^1.1.0", 
    "karma-jasmine-html-reporter": "^0.1.8", 
    "karma-requirejs": "^1.1.0", 
    "karma-spec-reporter": "0.0.31" 
    }, 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "author": "", 
    "license": "ISC" 
} 

而且我得到的结果是enter image description here 谁能帮助如何产生的测试用例结果在html中?

+0

你正在使用什么单元测试框架? (Qunit,Jasmine ??),htmlReporter应该将测试结果转储到html文件中。 – Raj

+0

我正在使用茉莉花框架 –

+0

我认为原因,你没有看到在业力横幅下的规格,是因果可能不会加载jasmine.css文件,你可以通过之前的karma.conf.js文件加载它测试和源文件,请在您的karma-core node_modules中查找jasmine.css。 – Raj

回答

0

使用karma-jasmine-html-reporter在业力横幅下面打印茉莉花格式报告。

卡玛 - 茉莉HTML-记者: https://github.com/taras42/karma-jasmine-html-reporter

添加下面你karma.conf.js文件

module.exports = function(config) { 
    config.set({ 
    client: { 
     clearContext: false 
    }, 
    reporters: ['kjhtml'], 

    plugins: ['karma-jasmine-html-reporter'] 

    }); 
}; 

以上述方式将产生如下结果配置因缘: enter image description here

+0

对不起,这是不同的插件。我正在使用karma-html reporter.https://www.npmjs.com/package/karma-html-reporter。仍然我尝试了以上插件仍然无法看到规格文件。 –

+0

Karma-html-reporter将输出存储在磁盘中,但karma-jasmine -html-记者将在karma上下文页面中显示测试结果。确保你的client.clearContext设置为false,如上所示,并通过在你的业力中添加singleRun:false来验证你的结果Conf文件 – Raj

+0

没有我还没有得到。我在给出业力开始时出错。 28 09 2017 11:04:50.892:错误[插件]:无法找到插件“karma-phantomjs-launcher”。 你忘了安装它吗? npm安装karma-phantomjs-launcher --save-dev 28 09 2017 11:04:50.926:错误[插件]:加载“karma-requirejs”插件时出错: 找不到模块'requirejs' –