node.js grunt "test command" 在 npm init 上做了什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17127964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what does grunt "test command" do on npm init
提问by mheavers
I'm trying to learn grunt. When I run npm init, I get a prompt in the process of creating a package.json file that asks for "test command" - I'm not sure how to utilize this, or what it's expecting. It doesn't seem to be well documented. If I leave it blank, I get this in the resulting package.json file:
我正在努力学习咕噜声。当我运行 npm init 时,我在创建 package.json 文件的过程中收到一个提示,该文件要求“测试命令”——我不确定如何利用它,或者它期待什么。它似乎没有很好的记录。如果我把它留空,我会在生成的 package.json 文件中得到它:
"scripts": {
//"test": "echo \"Error: no test specified\" && exit 1"
},
Can anybody shed some light on how to set up a test script?
任何人都可以对如何设置测试脚本有所了解吗?
采纳答案by hereandnow78
at first, the scripts-property in your package.json has nothing to do with grunt itself. its just a cli-command from npm, wich will be run if you run
首先,package.json 中的 scripts-property 与 grunt 本身无关。它只是来自 npm 的 cli 命令,如果您运行,它将运行
$ npm test
read more about that here: https://npmjs.org/doc/scripts.html
在此处阅读更多相关信息:https: //npmjs.org/doc/scripts.html
e.g. if you test your application with the grunt & nodeunityou could just add that to the scripts-block
例如,如果您使用grunt 和 nodeunit测试您的应用程序,您可以将其添加到脚本块中
"scripts": {
"test": "grunt nodeunit"
}
and your nodeunit-task is run if you run 'npm test'
如果你运行'npm test',你的nodeunit-task就会运行
this basically makes it easier for continuous integration and so on, if you change your underlying testframework.
如果您更改底层测试框架,这基本上可以更轻松地进行持续集成等。
of course you could add an alias-taskif you need more to be done before and after your tests are run (e.g. concatenation before, cleanup after)
当然,如果您需要在运行测试之前和之后完成更多工作(例如之前的串联,之后的清理),您可以添加一个别名任务
回答by Vibhu
As mentioned in the answer above you can run your test command when you specify it during creation of package json from cmd or by editing the json file manually. Basically as per the npm docs it is used to run the provided package's test script.
正如上面的答案中提到的,您可以在从 cmd 创建包 json 期间或通过手动编辑 json 文件指定它时运行您的测试命令。基本上根据 npm 文档,它用于运行提供的包的测试脚本。
In my case , Iam using it to test an angular application using Jasmine(spec.js files) a sample usage can be found in this article :-
就我而言,我使用它来测试使用 Jasmine(spec.js 文件)的 Angular 应用程序,可以在本文中找到示例用法:-

