最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

unit testing - Angular will not run a single test file - Stack Overflow

programmeradmin1浏览0评论

I am trying to run a single spec.ts file, but Angular keeps picking up many other files. Here is what I have tried:

ng test --include src\app\global.service.spec.ts

ng test --main src\app\global.service.spec.ts

ng test --include [FULL PATH]\src\app\global.service.spec.ts

ng test (no params, but with the karma file configured with the following):

    module.exports = function (config) {
    config.set({
    files: [{ pattern: 'src\\app\\global.service.spec.ts', watched: false }],
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage'),
      require('@angular-devkit/build-angular/plugins/karma')    
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    jasmineHtmlReporter: {
      suppressAll: true // removes the duplicated traces
    },
    coverageIstanbulReporter: {
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    coverageReporter: {
      dir: require('path').join(__dirname, 'coverage'),
      subdir: '.',
      reporters: [
        { type: 'html' },
        { type: 'text-summary' },
        { type: 'lcov' }
      ]
    },
    reporters: ['progress', 'kjhtml', 'coverage' ],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    restartOnFileChange: true,

    customLaunchers: {
      MyHeadlessChrome: {
        base: 'ChromeHeadless',
        flags: [
          '--headless',
          '--disable-gpu',
          '--disable-web-security',
          '--disable-translate',
          '--disable-extensions',
          '--no-sandbox',
          '--remote-debugging-port=9222',
        ],
      },
    },
  });
};
发布评论

评论列表(0)

  1. 暂无评论