如何使用Mocha配置TeamCity构建?

时间:2022-02-07 04:12:47

I have a project that I am setting up through teamcity for CI. The project itself is a nodejs application and it includes test written in mocha, which we cover through jscoverage. In the build configuration I'm setting up I have 3 build steps which occur on checkin.

我有一个项目,我通过teamcity为CI设置。项目本身是一个nodejs应用程序,它包括用mocha编写的测试,我们通过jscoverage覆盖。在我正在设置的构建配置中,我在checkin上发生了3个构建步骤。

  1. call jscoverage.exe against the folders in my project that I'm covering.

    调用jscoverage.exe对我正在覆盖的项目中的文件夹。

  2. call mocha to run the test against the jscovered files from step 1 and output to the html-cov reporter

    调用mocha对步骤1中的jscovered文件运行测试并输出到html-cov报告器

  3. move the generated coverage.html report into a public web directory to browse later.

    将生成的coverage.html报告移动到公共Web目录中以便稍后浏览。

The build currently fails on step 2: mocha" is not present in directory C:\NodeJS\MeasuresAPI

构建当前在步骤2中失败:目录C:\ NodeJS \ MeasuresAPI中不存在mocha“

I've made sure to include mocha and all my node packages in the system environment paths and I am able to access them in the command prompt, but TeamCity doesnt appear to see them.

我确保在系统环境路径中包含mocha和我的所有节点包,并且我能够在命令提示符中访问它们,但TeamCity似乎没有看到它们。

for the jscoverage.exe, I had to include the full path. With mocha, I tried including the path to my node global installation where mocha installed to but it gives me an error:

对于jscoverage.exe,我必须包含完整路径。使用mocha,我尝试将路径添加到我的节点全局安装中,其中安装了mocha,但它给了我一个错误:

"..\node_modules\mocha\bin\mocha" (in directory "C:\NodeJS\MeasuresAPI"): CreateProcess error=193, %1 is not a valid Win32 application

“.. \ node_modules \ mocha \ bin \ mocha”(在目录“C:\ NodeJS \ MeasuresAPI”中):CreateProcess error = 193,%1不是有效的Win32应用程序

Anyone had any experience with Teamcity and Mocha and how to get them to play nice? or any ideas for continuous integration with a nodejs, mocha stack?

任何人都有Teamcity和Mocha的经验,以及如何让他们玩得很好?或任何与nodejs,mocha堆栈持续集成的想法?

1 个解决方案

#1


6  

Yes , this happened to me too, when I was setting up TeamCity to run mocha on Windows Server. The solution was to call mocha by specifying path to the mocha.cmd bat file. For example , if you have folder C:\mocha and you have executed npm install mocha

是的,当我设置TeamCity在Windows Server上运行mocha时,这也发生在我身上。解决方案是通过指定mocha.cmd bat文件的路径来调用mocha。例如,如果你有文件夹C:\ mocha,你已经执行了npm install mocha

in that directory , than path to the bat file will be

在该目录中,将比bat文件的路径

C:\mocha\node_modules.bin\mocha.cmd

C:\摩卡\ node_modules.bin \ mocha.cmd

And you can tell Teamcity to execute mocha command by giving it next instruction :

你可以通过给它下一条指令告诉Teamcity执行mocha命令:

C:\mocha\node_modules.bin\mocha --ui tdd --reporter html-cov test\measureDBTests.js > coverage.html

C:\ mocha \ node_modules.bin \ mocha --ui tdd --reporter html-cov test \ measureDBTests.js> coverage.html

#1


6  

Yes , this happened to me too, when I was setting up TeamCity to run mocha on Windows Server. The solution was to call mocha by specifying path to the mocha.cmd bat file. For example , if you have folder C:\mocha and you have executed npm install mocha

是的,当我设置TeamCity在Windows Server上运行mocha时,这也发生在我身上。解决方案是通过指定mocha.cmd bat文件的路径来调用mocha。例如,如果你有文件夹C:\ mocha,你已经执行了npm install mocha

in that directory , than path to the bat file will be

在该目录中,将比bat文件的路径

C:\mocha\node_modules.bin\mocha.cmd

C:\摩卡\ node_modules.bin \ mocha.cmd

And you can tell Teamcity to execute mocha command by giving it next instruction :

你可以通过给它下一条指令告诉Teamcity执行mocha命令:

C:\mocha\node_modules.bin\mocha --ui tdd --reporter html-cov test\measureDBTests.js > coverage.html

C:\ mocha \ node_modules.bin \ mocha --ui tdd --reporter html-cov test \ measureDBTests.js> coverage.html