如何为node.js应用程序运行mocha测试的make命令

时间:2021-03-25 17:12:40

I have created a folder : MyFirstNodeAppl and within that, I created a test folder which contains all the tests that need to run using the mocha framework.

我创建了一个文件夹:MyFirstNodeAppl,在其中,我创建了一个测试文件夹,其中包含需要使用mocha框架运行的所有测试。

I also created a make file named as MakeFile and the content details as mentioned below:

我还创建了一个名为MakeFile的make文件和内容详细信息,如下所述:

test:
      @./node_modules/.bin/mocha -u tdd

.PHONY: test

package.json is in the same level as test and MakeFile with the content as mentioned below:

package.json与test和MakeFile处于同一级别,其内容如下所述:

{
    "name": "nockmarket", 
    "version": "0.0.1",
    "private": true,
    "dependencies": {
        "jquery" : "1.7.3",
        "mocha": "1.3.0",
        "should": "1.0.0"     
    }
}

After setting up the above things, I ran the npm install command using the node command prompt window. Now as I know that Mocha uses make to run the test harness, And for windows users we need Cygwin so I installed it in my system. But I am not able to run the make command in order to test the unit test cases.

设置完上述内容后,我使用node命令提示符窗口运行了npm install命令。现在我知道Mocha使用make来运行测试工具,而对于Windows用户,我们需要Cygwin,所以我将它安装在我的系统中。但我无法运行make命令来测试单元测试用例。

Can anyone help me to resolve this issue by providing guidance to me in the above.

任何人都可以通过在上面提供指导来帮助我解决这个问题。

Folder structure details : 如何为node.js应用程序运行mocha测试的make命令

文件夹结构细节:

2 个解决方案

#1


7  

The easiest way to run mocha on your tests is to execute:

在测试中运行mocha的最简单方法是执行:

npm install -g mocha

Which should make the mocha binary available on your path. Then, from cygwin, just run mocha from the root directory of your project. That will cause it to execute all the tests in *.js files under the test directory.

哪个应该使你的路径上的mocha二进制文件可用。然后,从cygwin,只需从项目的根目录运行mocha。这将导致它执行测试目录下的* .js文件中的所有测试。

#2


1  

Install Mocha module in your app or globally:

在您的应用中或全局安装Mocha模块:

  npm install --save mocha

its saves mocha dependency in your package.json file.

它在你的package.json文件中保存了mocha依赖项。

npm puts aliases to all the binaries in your dependencies on that special folder. Finally, npm will add node_modules/.bin to the PATH automatically when running an npm script, so in your package.json you can do just:

npm将别名放在该特殊文件夹的依赖项中的所有二进制文件中。最后,npm会在运行npm脚本时自动将node_modules / .bin添加到PATH中,因此在package.json中你可以这样做:

"scripts": {
    "test": "mocha"
 }

and invoke it with

并用它调用它

 npm test

#1


7  

The easiest way to run mocha on your tests is to execute:

在测试中运行mocha的最简单方法是执行:

npm install -g mocha

Which should make the mocha binary available on your path. Then, from cygwin, just run mocha from the root directory of your project. That will cause it to execute all the tests in *.js files under the test directory.

哪个应该使你的路径上的mocha二进制文件可用。然后,从cygwin,只需从项目的根目录运行mocha。这将导致它执行测试目录下的* .js文件中的所有测试。

#2


1  

Install Mocha module in your app or globally:

在您的应用中或全局安装Mocha模块:

  npm install --save mocha

its saves mocha dependency in your package.json file.

它在你的package.json文件中保存了mocha依赖项。

npm puts aliases to all the binaries in your dependencies on that special folder. Finally, npm will add node_modules/.bin to the PATH automatically when running an npm script, so in your package.json you can do just:

npm将别名放在该特殊文件夹的依赖项中的所有二进制文件中。最后,npm会在运行npm脚本时自动将node_modules / .bin添加到PATH中,因此在package.json中你可以这样做:

"scripts": {
    "test": "mocha"
 }

and invoke it with

并用它调用它

 npm test