How to exclude Folder (components) for unit testin

2019-06-27 09:46发布

I am using angular cli version 1.4.5 and below is the karma.conf.ts file

module.exports = function (config) {
  config.set({
  basePath: '',
  exclude: [
     "src/app/components/panel/panel.component.spec.ts",
     "src/app/components/accordion/accordion.component.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 
   },
   coverageIstanbulReporter: {
     reports: [ 'html', 'lcovonly' ],
     fixWebpackSourcePaths: true
   },
   angularCli: {
     environment: 'dev'
   },
   reporters: ['progress', 'kjhtml'],
   port: 9876,
   colors: true,
   logLevel: config.DEBUG,
   autoWatch: true,
   browsers: ['Chrome'],
   singleRun: false
 });
};

and I even added the exclude in the tsconfig.spec.json file to exclude to pick those files for test.

{
 .....,
 "include": [
 "**/*.spec.ts",
 "**/*.d.ts"
 ],
 "exclude": [
     "app/components/panel/panel.component.spec.ts",
     "app/components/accordion/accordion.component.spec.ts"
 ]
}

is that am missing something to add for exclusion ?

1条回答
够拽才男人
2楼-- · 2019-06-27 10:01

Change the config in the src/test.ts.

const context = require.context('./', true, /\.spec\.ts$/);

https://github.com/angular/angular-cli/issues/9026#issuecomment-354475734

查看更多
登录 后发表回答