如何在节点上运行Jasmine测试。js从命令行

时间:2021-04-05 20:54:02

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 spec directory and get results in the terminal, is this possible?

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

3 个解决方案

#1


21  

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/jasmin -node

then

然后

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

which from my demo does 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

#2


82  

This should get you going quickly:

这应该能让你快速地:

  1. install Node.js (obviously).
  2. 安装节点。js(很明显)。
  3. Next install Jasmine. Open a command prompt and run:

    下一个安装茉莉花。打开命令提示符并运行:

    npm install -g jasmine

    npm安装- g茉莉花

  4. Next, cd to any directory and set up an example 'project':

    接下来,cd到任何目录,并设置一个示例“项目”:

    jasmine init
    jasmine examples

    茉莉花init茉莉花的例子

  5. Now run your unit tests:

    现在运行单元测试:

    jasmine

    茉莉花

If your jasmine.json file is somewhere else besides spec/support/jasmine.json, simply run:

如果你的茉莉花。除了spec/support/jasmine之外,json文件还有其他地方。json,简单地运行:

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

茉莉花JASMINE_CONFIG_PATH =相对路径/ /你/ jasmine.json

For more info see:

更多信息见:

#3


-9  

Try Karma (formerly Testacular), it is a testing library agnostic test runner done by Angular.js team

试一下Karma(以前是Testacular),它是一个用角度来测试库不可知的测试运行器。js的团队

http://karma-runner.github.io/0.12/index.html

http://karma-runner.github.io/0.12/index.html

Jasmine support is well baked.

茉莉花的支持很好。

http://karma-runner.github.io/0.12/intro/how-it-works.html

http://karma-runner.github.io/0.12/intro/how-it-works.html

#1


21  

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/jasmin -node

then

然后

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

which from my demo does 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

#2


82  

This should get you going quickly:

这应该能让你快速地:

  1. install Node.js (obviously).
  2. 安装节点。js(很明显)。
  3. Next install Jasmine. Open a command prompt and run:

    下一个安装茉莉花。打开命令提示符并运行:

    npm install -g jasmine

    npm安装- g茉莉花

  4. Next, cd to any directory and set up an example 'project':

    接下来,cd到任何目录,并设置一个示例“项目”:

    jasmine init
    jasmine examples

    茉莉花init茉莉花的例子

  5. Now run your unit tests:

    现在运行单元测试:

    jasmine

    茉莉花

If your jasmine.json file is somewhere else besides spec/support/jasmine.json, simply run:

如果你的茉莉花。除了spec/support/jasmine之外,json文件还有其他地方。json,简单地运行:

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

茉莉花JASMINE_CONFIG_PATH =相对路径/ /你/ jasmine.json

For more info see:

更多信息见:

#3


-9  

Try Karma (formerly Testacular), it is a testing library agnostic test runner done by Angular.js team

试一下Karma(以前是Testacular),它是一个用角度来测试库不可知的测试运行器。js的团队

http://karma-runner.github.io/0.12/index.html

http://karma-runner.github.io/0.12/index.html

Jasmine support is well baked.

茉莉花的支持很好。

http://karma-runner.github.io/0.12/intro/how-it-works.html

http://karma-runner.github.io/0.12/intro/how-it-works.html