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

Pao*_*aJ. 46 node.js jasmine jasmine-node

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

use*_*141 91

这应该可以让你快速前进:

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

    npm install -g jasmine

  3. 接下来,cd到任何目录并设置一个示例'project':

    jasmine init
    jasmine examples

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

    jasmine

如果你的jasmine.json文件在spec/support/jasmine.json之外的其他地方,只需运行:

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

有关详情,请参阅:

  • 这个信息肯定会更加突出地包含在茉莉花主页上.目前你只知道你是否去了github项目. (3认同)
  • 在空白的"npm init"项目中完成此操作仍然不会给我带来任何结果. (3认同)
  • 这不会产生任何输出. (3认同)

Kee*_*yOn 23

编辑

似乎这不再是目前最好的答案,因为包没有维护.请参阅下面的答案


你可以这样做

从您的测试目录

sudo npm install jasmine-node
Run Code Online (Sandbox Code Playgroud)

这会将jasmine安装到../node_modules/jasmine-node中

然后

../node_modules/jasmine-node/bin/jasmine-node --verbose --junitreport --noColor spec
Run Code Online (Sandbox Code Playgroud)

从我的演示中做到这一点

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
Run Code Online (Sandbox Code Playgroud)

  • 对于那些通过谷歌到达的人:`jasmine-node`自2014年以来没有新的提交,只运行jasmine 1.3,似乎已被放弃.user64141下面的答案中的官方`jasmine` CLI是更新的. (17认同)
  • OP应该在这个上重新分配正确的刻度 (2认同)
  • 避免使用`sudo`安装NPM软件包.只有在真的有必要时才会发生. (2认同)