【问题标题】:Karma does not see spec files under directories with _ (example: _ui)Karma 看不到带有 _ 的目录下的规范文件(例如:_ui)
【发布时间】:2023-04-10 14:31:01
【问题描述】:

当我运行 ng 测试时。 Karma 查找除带有 _ 的文件夹中的文件以外的所有规范文件(例如:_sidebar)

这里是 karma.conf.js 文件:

// 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: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../../../coverage/themes'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    restartOnFileChange: true
  });
};

这里是 test.ts 文件上下文过滤器:

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

【问题讨论】:

    标签: angular karma-jasmine


    【解决方案1】:

    检查tsconfig.spec.json 并注意filesincludeexclude 数组,并确保这些文件夹未被排除。

    test.ts中,有一个context属性,可能是忽略了_开头的文件夹和'./'

    【讨论】:

    • 这是我的上下文过滤器: const context = require.context('./', true, /\.spec\.ts$/);我该如何解决?
    • 尝试const context = require.context('./_', true, /\.spec\.ts$/) 看看单元测试是否在仅包含 _ 的文件夹中运行。如果是,那么我想就是这样。但是,如果可能并且不需要它们,我只会删除文件夹中的 _ 。 stackoverflow.com/questions/47364840/…
    猜你喜欢
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 2014-06-21
    相关资源
    最近更新 更多