因果覆盖的代码覆盖率始终为空

时间:2018-08-30 07:38:22

标签: karma-jasmine code-coverage karma-coverage

我正在使用业力和茉莉花进行单元测试。我的测试运行正常,但是覆盖范围始终是空的。下面是我的karma.config.js

// Karma configuration
// Generated on Mon Jul 16 2018 13:34:32 GMT+0800 (Malay Peninsula 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: [
      'src/test.ts'
    ],

    // list of files / patterns to exclude
    exclude: [
      'node_modules',
      './src/tsconfig.spec.json'
    ],
    plugins: [
      require('karma-jasmine'),
      require("karma-coverage"),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-webpack'),
      require('karma-sourcemap-loader'),
      require('ts-loader')
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      'src/components/**/*.ts?(x)': 'coverage',
      'src/test.ts': ['webpack', 'sourcemap'],
    },

    webpack: require('./webpack.test.config'),


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

    mime: {
      'text/x-typescript': ['ts', 'tsx']
    },
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageReporter: {
      type: 'html',
      dir: '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: ['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
  })
}

请问我在想什么。我已经阅读了很多,尝试了很多东西,但似乎没有任何效果。任何帮助,将不胜感激。

我的test.ts文件是

// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import "zone.js/dist/zone";
import "core-js/es7/reflect";

import "zone.js/dist/zone-testing";
import { getTestBed } from "@angular/core/testing";
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from "@angular/platform-browser-dynamic/testing";

declare const require: any;

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting()
);

// Then we find all the tests.
const context = require.context("./", true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

0 个答案:

没有答案