karma-jasmine没有在浏览器中显示测试结果

时间:2018-03-12 09:23:14

标签: angular jasmine karma-runner karma-jasmine

我正在尝试单位测试我的角度应用程序。我是新karama测试我正在尝试业力,jasmine.i ve下载和所有业力依赖。我在视觉工作室2017使用角webpack版本。我正面临一些像

这样的问题

1.karma html loader没有加载,只有我能看到karma v1.7.0已经连接

2.如何在webpack版本中配置karma以获取html视图

的package.json

 {
 "name": "WebApp",
  "private": true,
  "version": "0.0.0",
  "scripts": {
  "test": "karma start ClientApp/test/karma.conf.js"
   },
   "dependencies": {

   "webpack": "2.5.1",
   "webpack-hot-middleware": "2.18.2",
   "webpack-merge": "4.1.0",
   "zone.js": "0.8.12"
   },
  "devDependencies": {

   "jasmine-core": "2.6.4",
    "karma": "1.7.0",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.2.0",
   "karma-cli": "1.0.1",
   "karma-html-reporter": "^0.2.7",
   "karma-htmlfile-reporter": "^0.3.5",
   "karma-jasmine-html-reporter": "~0.1",
    "karma-webpack": "2.0.3",
    "karma-jasmine": "^1.0.2",

   }

karma.config.js

    module.exports = function (config) {
     config.set({
     basePath: '.',
     frameworks: ['jasmine'],
     files: [
        '../../wwwroot/dist/vendor.js',
        './boot-tests.ts'
        ],
    preprocessors: {
        './boot-tests.ts': ['webpack']
    },

    reporters: ['progress', 'html'],
    htmlReporter: {
        outputFile: 'tests/units.html'
    },
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    mime: { 'application/javascript': ['ts', 'tsx'] },
    singleRun: false,
    webpack: require('../../webpack.config.js')().filter(config => config.target !== 'node'), // Test against client bundle, because tests run in a browser
    webpackMiddleware: { stats: 'errors-only' }
   });
   };

1 个答案:

答案 0 :(得分:0)

我有同样的方案需要克服,我在我的架构中使用了webpack和requirejs,但配置仍有帮助。

首先安装karma-jasmine-html-reporter-livereload插件,PFB链接

https://www.npmjs.com/package/karma-jasmine-html-reporter-livereload

Karma.conf更改(提供相关更改)

var webpackConfig = require('./webpack.config.js');

webpackConfig.entry = function(){return {}};

module.exports = function(config) {

            config.set({

                client: {
                    clearContext: false    // will show the results in browser once all the testcases are loaded
                },

            frameworks: ['jasmine','requirejs'],


            // list of files / patterns to load in the browser
            files: [
               'node_modules/jasmine-core/lib/jasmine-core/jasmine.css',
               'node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js',
               'node_modules/jasmine-core/lib/jasmine-core/boot.js',
               'node_modules/angular/angular.js',
               'node_modules/angular-mocks/angular-mocks.js',
               'tests/**/*Spec.js'
            ],
        webpack: webpackConfig,

        webpackMiddleware : {
           noInfo : true,
           stats : 'errors-only'
        },

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



            })
}