本文介绍了为什么Karma配置文件的“排除"选项不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的示例Angular应用中有两个规格文件.规格文件名称为src/app/app.component.spec.ts& src/app/app.component-two.spec.ts.我只想运行文件src/app/app.component.spec.ts中的测试.因此,我在karma.conf.js文件中添加了另一个文件作为排除文件(粘贴在下面),仍然在执行exclude选项中提到的测试.任何帮助将不胜感激.

I have two spec files in my sample Angular app. The spec files names aresrc/app/app.component.spec.ts & src/app/app.component-two.spec.ts. I want to run only the tests in file src/app/app.component.spec.ts. So, I added the other file as exclude in the karma.conf.js file (pasted below), still the tests mentioned in the exclude option are being executed.Any help is greatly appreciated.

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: '',
    exclude: [
      'src/app/app.component-two.spec.ts'
    ],
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

推荐答案

您可以在tsconfig.spec.json中排除文件:

{
  "extends": "../tsconfig.json",
  "compilerOptions": { ... },
  "files": [
    "test.ts"
  ],
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ],
  "exclude": [
    "app/app.component-two.spec.ts"    <------------------
  ]

这篇关于为什么Karma配置文件的“排除"选项不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:34