简体   繁体   English

运行ng test时在项目中找不到配置

[英]Configuration could not be found in project when running ng test

I have just upgraded to Angular 6 but now our Jenkins build is failing. 我刚刚升级到Angular 6,但是现在我们的Jenkins构建失败了。

It is running this command: 它正在运行以下命令:

ng test -c karma.conf.cli.js

But the error is: 但是错误是:

Configuration 'karma.conf.cli.js' could not be found in project 'projectname' 在项目“ projectname”中找不到配置“ karma.conf.cli.js”

However, the file in question exists in the root of the project. 但是,相关文件存在于项目的根目录中。 This command was running fine on Angular 5. Any ideas? 该命令在Angular 5上运行良好。 Thanks 谢谢

FYI I can reproduce the error by running the same command on the build server. 仅供参考,我可以通过在生成服务器上运行相同的命令来重现该错误。 We have also just upgraded Node.js to v8.11.2 (latest LTS) 我们还刚刚将Node.js升级到v8.11.2(最新的LTS)

In the version 6 of Angular Cli the options for the commands has changed, instead use -c , you should use --karma-config or --configuration . 在Angular Cli的版本6中,命令的选项已更改,而使用-c ,则应使用--karma-config--configuration You can see all options here . 您可以在此处查看所有选项。

I tried many and the one worked for me is as below. 我尝试了很多,为我工作的一个如下。 In your angular.json file add configuration section under test below. 在您的angular.json文件中,添加下面正在测试的配置部分。

    "test": {
      "builder": "@angular-devkit/build-angular:karma",
      "options": {
         ....
      },
      "configurations": {  // this will hold a different configuration
        "jenkins": {
          "karmaConfig": "./karma.conf.ci.js"
        }
      }
    },

And then while running the test use this configuration with --configuration jenkins options. 然后在运行测试时,将此配置与--configuration jenkins选项一起使用。 So the final command will be 所以最后的命令是

ng test --configuration jenkins

It will pick karma.conf.ci.js as configuration file as it set in the configuration section in angular cli configuration file and run unit test using that configuration file. 它将选择karma.conf.ci.js作为在angular cli配置文件的配置部分中设置的配置文件,并使用该配置文件运行单元测试。

I had the same issue in Jenkins after Angular 6 and I solved by replacing: 在Angular 6之后,我在詹金斯(Jenkins)遇到了同样的问题,我通过替换解决了:

ng test --single-run --browsers ChromeHeadless -cc 

with: 与:

ng test --watch=false --browsers ChromeHeadless --code-coverage

暂无
暂无

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

相关问题 在项目上运行 ng serve 时 92% 挂断 - 92% hang up when running ng serve on project 运行 webdriver.io 测试时出现“错误:未找到:java” - "Error: not found: java" when running webdriver.io test 警告:运行grunt测试时找不到任务“karma” - Warning: Task “karma” not found when running grunt test 茉莉花库“没有发现规格”两次运行相同的测试 - jasmine library “no specs found” when running same test twice 无法为Javascript项目创建“运行配置” - Could not Create “Run Configuration” for a Javascript Project Dynamodb.put 在运行 lambda 测试配置时工作正常,但在通过 API 网关调用 lambda 时却不行 - Dynamodb.put works fine when running a lambda test configuration, but not when invoking the lambda through API gateway 为什么将我的 Angular 项目部署到 Heroku 时出现 ng not found 错误? - Why am I getting an ng not found error when deploying my Angular project to Heroku? 在 Windows 中创建新项目时未找到 ng 命令 angular-cli - ng command not found angular-cli when create new project in windows 使用本机插件将项目复制到服务器计算机时,“无法找到指定的模块。” - “The specified module could not be found.” when copying project with native addon to server machine serve 命令需要在 Angular 项目中运行,但找不到项目定义 - The serve command requires to be run in an Angular project, but a project definition could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM