如何从命令行在Node.js上运行Jasmine测试

如何从命令行在Node.js上运行Jasmine测试? 我已经通过npm安装了jasmine-node并编写了一些测试。 我想在spec目录中运行测试并在终端中获取结果,这可能吗?

PaolaJ. asked 2020-06-25T00:26:51Z
3个解决方案
91 votes

这应该使您快速入门:

  1. 安装Node.js(显然)。
  2. 接下来安装Jasmine。 打开命令提示符并运行:

    jasmine JASMINE_CONFIG_PATH=relative/path/to/your/jasmine.json

  3. 接下来,使用cd进入任何目录并设置示例“ project”:

    jasmine JASMINE_CONFIG_PATH=relative/path/to/your/jasmine.json
    jasmine examples

  4. 现在运行您的单元测试:

    jasmine JASMINE_CONFIG_PATH=relative/path/to/your/jasmine.json

如果您的jasmine.json文件位于spec / support / jasmine.json之外的其他位置,则只需运行:

jasmine JASMINE_CONFIG_PATH=relative/path/to/your/jasmine.json

有关更多信息,请参见:

  • [HTTPS://呜呜呜.那匹马加上.com/package/Jasmine]
  • [HTTP://Jasmine.GitHub.IO/2.2/node.HTML]
user64141 answered 2020-06-25T00:28:48Z
24 votes

编辑

由于不再维护该软件包,因此这似乎不再是当前的最佳答案。 请参阅下面的答案


你可以这样做

从您的测试目录

sudo npm install jasmine-node

这会将茉莉花安装到../node_modules/jasmine-node

然后

../node_modules/jasmine-node/bin/jasmine-node --verbose --junitreport --noColor spec

从我的演示中做到了

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
KeepCalmAndCarryOn answered 2020-06-25T00:27:32Z
-9 votes

尝试Karma(以前称为Testacular),它是Angular.js小组完成的与测试库无关的测试运行器

[HTTP://karma-runner.GitHub.IO/0.12/index.HTML]

茉莉花的烘烤效果很好。

[HTTP://karma-runner.GitHub.IO/0.12/intro/how-IT-works.HTML]

imsaar answered 2020-06-25T00:29:21Z
translate from https://stackoverflow.com:/questions/21392370/how-to-run-jasmine-tests-on-node-js-from-command-line