当前位置: 首页 > 知识库问答 >
问题:

错误&生成失败:使用karma执行测试时

艾焱
2023-03-14
[INFO] --- frontend-maven-plugin:1.7.6:karma (run tests) @ test-ui ---
[INFO] Running 'karma start karma.conf.ci.js' in /Users/codehan/Documents/projects/test-ui
[ERROR]
[ERROR] /Users/codehan/Documents/projects/test-ui/node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts:62
[ERROR] throw new Error(The '@angular-devkit/build-angular/plugins/karma' karma plugin is meant to +
[ERROR] ^
[ERROR] Error: The '@angular-devkit/build-angular/plugins/karma' karma plugin is meant to be used from within Angular CLI and will not work correctly outside of it.

和下面的一些行

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.666 s
[INFO] Finished at: 2019-05-21T14:31:09+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.7.6:karma (run tests) on project test-ui: Failed to run task: 'karma start karma.conf.ci.js' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

我在1.7.6版本中使用了frontend-maven-plugin,并将其插入到pom.xml中。

  <build>
    <plugins>
      <!-- Frontend plugin -->
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>1.7.6</version>
        <configuration>
          <nodeVersion>v11.10.0</nodeVersion>
        </configuration>
        <executions>
        ...

我的karma.conf.js看起来是这样的:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-chrome-launcher'),
      require('karma-phantomjs-launcher')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, 'coverage'), 
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {environment: 'dev'},
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    phantomjsLauncher: {
      // Have phantomjs exit if a ResourceError is encountered (useful if karma
      // exits without killing phantom)
      exitOnResourceError: true
    },    
    singleRun: false
  });
};
var baseConfig = require('./karma.conf.js');

module.exports = function (config) {
  baseConfig(config);
  config.set({
    plugins: [
      require('karma-jasmine'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-chrome-launcher')
    ],
    browsers: ['Chrome'],
    singleRun: true
  });
};
  <execution>
    <id>test</id>
    <goals>
      <goal>npm</goal>
    </goals>
    <configuration>
      <arguments>run test --karma-config karma.conf.js</arguments>
    </configuration>
  </execution>
  <execution>
    <id>run tests</id>
    <goals>
      <goal>karma</goal>
    </goals>
    <configuration>
      <karmaConfPath>karma.conf.ci.js</karmaConfPath>
    </configuration>
  </execution>

我的Package.json:

  "scripts": {
    "ng": "ng",
    "start": "ng serve --base-href=/ui/",
    "start-local-prod": "ng serve --base-href=/ui/",
    "start-traci": "ng serve --configuration=traci-dev --base-href=/ui/",
    "build": "ng build --prod --base-href=/ui/",
    "build-traci": "ng build --prod --configuration=traci --base-href=/ui/",
    "test": "ng test",
    "lint": "ng lint",
...

My Angular.json:

"test": {
  "builder": "@angular-devkit/build-angular:karma",
  "options": {
    "main": "src/test.ts",
    "karmaConfig": "./karma.conf.js",
    "polyfills": "src/polyfills.ts",
    "tsConfig": "src/tsconfig.spec.json",
    "scripts": [
      "node_modules/jquery/dist/jquery.js",
      "node_modules/moment/moment.js",
      "node_modules/bootstrap-daterangepicker/daterangepicker.js"
    ],
...

我使用以下版本的软件包:

"@ angular-devkit / build-angular": "^0.12.4",
"@angular/cli": "^7.3.9",
"@Angle/compiler-cli": "7.2.0",
"@angular/core": "7.2.0",
"@angular-devkit/architect": "^0.13.9",
"@angular-devkit/build-optimizer": "^0.13.9",
"@angular-devkit/build-webpack": "^0.13.9",
"@angular-devkit/core": "^7.3.9",
"karma": "^1.7.1",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.4.3",
"karma-firefox-launcher": "^1.0.1",
"karma-jasmine": "^1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-phantomjs-launcher": "^1.0.4",
"karma mocha reporter": "^2.2.5",
"karma-webpack": "^3.0.5",
"@ types/jasmine": "2.5.45",
"jasmine-core": "^2.99.1",
"jasmine-spec-reporter": "~4.1.0",
Java version: 1.8.0_201
Apache Maven 3.6.1
MacOS Mojave (Version 10.14.5)

IDE

Visual Studio Code

我做错了什么?

共有1个答案

严阳秋
2023-03-14
    <goals>
      <goal>karma</goal>
    </goals>
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "styles": [
              "src/styles/styles.scss"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          },
          "configurations": {
             "ci": {
                "karmaConfig": "src/karma.conf.ci.js"
             },
             "local":{
                "karmaConfig": "src/karma.conf.js"
             }
          } 
   "test:local": "ng test --configuration=local",
   "test:ci": "ng test --configuration=ci"
  <execution>
    <id>test</id>
    <goals>
      <goal>npm</goal>
    </goals>
    <configuration>
      <arguments>run test:ci</arguments>
    </configuration>
  </execution>
 类似资料:
  • 在使用maven运行单元测试时,我遇到了这个异常。我的所有测试都没有执行。我的测试类的格式是 我正在运行以下命令来运行此命令: 使用的surefire插件是: 有人知道为什么我的测试没有执行吗?我用的是jUnit 4.8.2和surefire 2.14.1

  • 在示例空手道测试项目中,我们有一个功能文件和一个runner类。 尝试使用下面的命令通过命令行执行测试 抛出以下错误... [信息]-------------------------------------------------------------[信息]生成失败[信息]-------------------------------------------------------------

  • 我们正在尝试将一堆Docker版本从Windows 2016更新到Windows 2019,以便我们可以将Service Fabric群集从Windows 2016升级到Windows 2019,并且还可以从。NET Core 2.2的生命周期结束。NET Core 3.1支持LTS。 Windows 2016没有提供.NET Core 3.1的Docker映像,这使得升级更加困难。我们当前的问题

  • 应用程序构建错误:'app:checkDebug重复类' 我知道通过删除一个类可以解决此错误,但我不知道如何删除它,或者有任何其他方法可以解决此问题。 谢啦 失败:生成失败,出现异常。问题:任务“:app:checkDebugDuplicateClasss”的执行失败。执行com.android.build.gradle.internal.tasks时出错。检查DuplicatesRunnable

  • 我在我的代码中包括boost,cpprest和openssl,但它给我的错误像follow在android studio使用ndk我给了所有路径的目录和添加到程序它构建成功,但当我运行它时,它给我以下错误 我的cmakelist.txt是 android{compileSdkVersion 28 defaultConfig{applicationId“com.example.dell.cppadd

  • 我们有一套约1100个单元在ng测试中运行,目前在Angular 7.2.5中运行到4分钟内完成,没有故障,在Angular 8.0.0中运行到4分钟前完成,随机故障,减速和断开。 测试在Angular 7中成功运行,无论是在镀铬还是镀铬。 已尝试: 为了消除已知的样式元素内存泄漏,我们在此处实现了“样式清理”: 通过在1100个测试中的每个描述块中运行。 在《角度8》中,我们试图将业力从4.1.