Jasmine单元测试未在travis上启动

Jasmine unit-tests not started on travis

本文关键字:启动 travis 单元测试 Jasmine      更新时间:2023-09-26

我想为我的chrome扩展进行持续集成。使用工具:GitHub、Travis、Bower、组件jasmine。在.travis.yml:中

  • 安装
  • bower下载茉莉
  • 在我的SpecRunner.html上更改默认的SpecRunner.html,它包含我的src和spec
  • 在phantomjs中加载我的SpecRunner.html

.travis.yml:

language: node_js
node_js:
  - "0.10"
install:
  - npm install -g bower
  - bower install
  - cd $TRAVIS_BUILD_DIR
script:
  - mv -f ./test/SpecRunner.html ./vendor/components-jasmine
  - phantomjs ./test/runTests.js

runTests.js:

var page = require('webpage').create();
page.open('../vendor/components-jasmine/SpecRunner.html', function(){
    phantom.exit();
});

测试应该失败,但travis-上的状态已通过。为什么我的测试没有运行?

测试结果显示在同一SpecRunner.html.上

为了获得结果,需要打印此加载的页面。如果html本地加载在phantomjs中,则url应遵循经典的url/Uri规则,尤其是对于本地文件(这就是页面未加载的原因):

file:///c:/path/to/the%20file.txt #win
file:///etc/fstab #unix

为了获得测试结果,需要在.travis.ymlafter_script中解析日志,如果测试通过,则返回值-0;如果测试失败,则返回非null。

此外,也许,茉莉花本身也有可能(但我不确定)。

尝试将after_script: echo $?添加到.travis.yml以查看测试的返回值。如果是0,那么Travis的行为是正确的。

我只是猜测,不管结果如何,你的测试都会返回0。根据文档,这段代码只是试图打开文件,并在失败时调用回调——因为没有not-0-退出回调,所以整个脚本正常退出并通过构建。

编辑:

从你写的内容中,我知道Travis运行得很好,phantomjs ./test/runTests.js不会返回非0值。尝试更改:

function(){
  phantom.exit();
}

类似于:

function(status){
  if (status === 'success')
    phantom.exit(0);
  else
    phantom.exit(-1);
}

并说构建失败(我认为页面打开总是失败)。