简体   繁体   English

grunt“测试命令”对npm init做了什么

[英]what does grunt “test command” do on npm init

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. 当我运行npm init时,我在创建一个请求“测试命令”的package.json文件的过程中得到一个提示 - 我不确定如何利用它,或者它期望的是什么。 It doesn't seem to be well documented. 它似乎没有很好的记录。 If I leave it blank, I get this in the resulting package.json file: 如果我把它留空,我会在生成的package.json文件中得到它:

"scripts": {
    //"test": "echo \"Error: no test specified\" && exit 1"
  },

Can anybody shed some light on how to set up a test script? 任何人都可以了解如何设置测试脚本吗?

at first, the scripts-property in your package.json has nothing to do with grunt itself. 首先,package.json中的scripts-property与grunt本身无关。 its just a cli-command from npm, wich will be run if you run 它只是来自npm的cli-command,如果你跑的话会运行

$ npm test

read more about that here: https://npmjs.org/doc/scripts.html 在这里阅读更多相关信息: https//npmjs.org/doc/scripts.html

eg if you test your application with the grunt & nodeunit you could just add that to the scripts-block 例如,如果使用grunt和nodeunit测试应用程序,则可以将其添加到scripts-block中

"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-task if you need more to be done before and after your tests are run (eg concatenation before, cleanup after) 当然,如果你需要在测试运行之前和之后完成更多工作 ,你可以添加一个别名任务 (例如,之前的连接,之后的清理)

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. 如上面的答案所述,您可以在从cmd创建包json期间或通过手动编辑json文件时指定它来运行测试命令。 Basically as per the npm docs it is used to run the provided package's test script. 基本上按照npm文档,它用于运行提供的包的测试脚本。

npm docs test npm docs test

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 :- 在我的例子中,Iam使用它来测试使用Jasmine(spec.js文件)的角度应用程序,可以在本文中找到示例用法: -

Getting Started with Node.js and Jasmine Node.js和Jasmine入门

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM