angular - 如何摆脱警告将原始 CLI 选项传递给 `new Server(config, done)` 已弃用

标签 angular karma-jasmine karma-runner angular-test

我最近将我的 Angular 应用程序中的 Karma 升级到了 v6.3.2。我正在运行 Angular v11。
当我开始测试时,我不断收到消息

Passing raw CLI options to new Server(config, done) is deprecated. Use parseConfig(configFilePath, cliOptions, {promiseConfig: true, throwErrors: true}) to prepare a processed Config instance and pass that as the config argument instead.


测试运行成功
下面是我的 karma 配置
// Karma.conf.js
const 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' ),
  require( 'karma-verbose-reporter')
];
const ChromeHeadlessNoSandbox = {
  base: 'ChromeHeadless',
  flags: [ '--no-sandbox' ]
};
// 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,
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, './coverage'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml', 'verbose'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_WARN,
    autoWatch: true,
    browsers: [ 'Chrome', 'ChromeHeadless', 'ChromeHeadlessNoSandbox'],
    customLaunchers: {
      ChromeHeadlessNoSandbox
    },
    singleRun: false,
    restartOnFileChange: true
  });
};

如何删除被警告的已弃用功能?

最佳答案

这个问题已经reportedfixed ,但不幸的是仅适用于 Angular 12。

关于angular - 如何摆脱警告将原始 CLI 选项传递给 `new Server(config, done)` 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67380402/

相关文章:

javascript - Angular 6 : How to set response type as text while making http call

Angular 2 不仅仅是文本区域中的空格

javascript - Karma/Jasmine 没有找到 AngularJS Controller (说它是未定义的)

javascript - Angular2 + karma 测试 : “Illegal state: Could not load the summary for directive Foo.”

Angular 4单元测试错误 `TypeError: ctor is not a constructor`

javascript - 如果测试有错误,Karma 不会失败

jquery - Angular 2 从 Jquery 调用 Typescript 函数导致未捕获的 TypeError

javascript - 如何测试 $rootScope.$emit 事件?

node.js - 如何在 tfs 构建日志控制台中获取带有颜色的 npm 测试输出

angular - 运行 jasmine 测试用例后出现错误 :- TypeError: this. snackBarRef.dismiss 不是一个函数