如何从命令行在 Node.js 上运行 Jasmine 测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21392370/
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
How to run Jasmine tests on Node.js from command line
提问by PaolaJ.
How do I run Jasmine tests on Node.js from command line? I have installed jasmine-node via npm and written some tests. I want to run tests inside the specdirectory and get results in the terminal, is this possible?
如何从命令行在 Node.js 上运行 Jasmine 测试?我已经通过 npm 安装了 jasmine-node 并编写了一些测试。我想在spec目录内运行测试并在终端中获得结果,这可能吗?
采纳答案by KeepCalmAndCarryOn
EDIT
编辑
It seems this is no longer the current best answer as the package is unmaintained. Please see the answer below
由于软件包未维护,这似乎不再是当前的最佳答案。请看下面的答案
You can do this
你可以这样做
from your test directory
从你的测试目录
sudo npm install jasmine-node
This installs jasmine into ../node_modules/jasmine-node
这会将 jasmine 安装到 ../node_modules/jasmine-node
then
然后
../node_modules/jasmine-node/bin/jasmine-node --verbose --junitreport --noColor spec
which from my demodoes this
从我的演示中可以做到这一点
Player - 5 ms
should be able to play a Song - 2 ms
when song has been paused - 1 ms
should indicate that the song is currently paused - 0 ms
should be possible to resume - 0 ms
tells the current song if the user has made it a favorite - 1 ms
#resume - 0 ms
should throw an exception if song is already playing - 0 ms
Player - 5 ms
should be able to play a Song - 2 ms
when song has been paused - 1 ms
should indicate that the song is currently paused - 0 ms
should be possible to resume - 0 ms
tells the current song if the user has made it a favorite - 1 ms
#resume - 0 ms
should throw an exception if song is already playing - 0 ms
Finished in 0.01 seconds
5 tests, 8 assertions, 0 failures, 0 skipped
回答by user64141
This should get you going quickly:
这应该能让你快速上手:
- install Node.js (obviously).
Next install Jasmine. Open a command prompt and run:
npm install -g jasmineNext, cd to any directory and set up an example 'project':
jasmine initjasmine examplesNow run your unit tests:
jasmine
- 安装 Node.js(显然)。
接下来安装茉莉花。打开命令提示符并运行:
npm install -g jasmine接下来, cd 到任何目录并设置一个示例“项目”:
jasmine initjasmine examples现在运行你的单元测试:
jasmine
If your jasmine.json file is somewhere else besides spec/support/jasmine.json, simply run:
如果您的 jasmine.json 文件位于除 spec/support/jasmine.json 之外的其他位置,只需运行:
jasmine JASMINE_CONFIG_PATH=relative/path/to/your/jasmine.json
jasmine JASMINE_CONFIG_PATH=relative/path/to/your/jasmine.json
For more info see:
有关更多信息,请参阅:
回答by Alexey Prokhorov
The easiest way is to run the command in your project root:
最简单的方法是在项目根目录中运行命令:
$ npx humile
$ npx humile
It founds all your specs which name ends with .spec.js.
它会找到您所有名称以.spec.js.
If you think humile is fine for your project, just install it as dev dependency. It speeds up the command.
如果您认为 humile 适合您的项目,只需将其安装为开发依赖项。它加快了命令。
$ npm install -D humile
$ npm install -D humile
回答by imsaar
Try Karma (formerly Testacular), it is a testing library agnostic test runner done by Angular.js team
试试 Karma(原 Testacular),它是一个由 Angular.js 团队完成的与测试库无关的测试运行器
http://karma-runner.github.io/0.12/index.html
http://karma-runner.github.io/0.12/index.html
Jasmine support is well baked.
茉莉花支持烤得很好。

