繁体   English   中英

Angular CLI /使用ng test运行两类测试

[英]Angular CLI / Run two categories of test with ng test

我有两种不同类型的测试:

  • 单元测试(标准cli.spec.ts角文件)
  • 功能测试(我特定的.func.spec.ts文件,与.spec.ts文件的工作方式相同,但未进行模拟并在我的数据库中插入数据,因此无需一直运行它们)

我在尝试着 :

  • ng test命令中排除.func.spec.ts文件,仅运行.spec.ts测试文件
  • 调用测试命令仅运行.func.spec.ts

因此,我的功能测试不会在常规ng test上下文中执行,而是可以单独运行。

换句话说,解决方案可以是...

  • npm run test运行.spec.ts文件
  • npm run test:func运行.func.spec.ts文件

我试图创建一个不同的业力配置文件,该文件排除了我不想要的文件,但是它不起作用。

您对如何执行此操作有任何想法吗?

您可以做的是添加特定的Karama配置karma.func.conf.js

module.exports = function (config) {
  config.set({
    basePath: '',
    files: ['src/app/**/**.func.ts'] // Not 100% sure about the pattern
    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' //you could change to use prod
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

添加到您的package.json

"scripts": {
  "ng": "ng",
  "start": "ng serve",
  "build": "ng build --prod",
  "test": "ng test",
  "test:func": "ng test --config karma.func.conf.js"
  "lint": "ng lint",
  "e2e": "ng e2e"
}

也许还有另一种解决方案可以避免维护两个配置文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM