LoginSignup
7

More than 5 years have passed since last update.

Travis Ci上でReact.jsのプロジェクトをPhantomJSでテストした場合にFailする現象

Posted at

React.jsを使用しているSinatraプロジェクトでPoltergeistを使用したテストを実施した場合に、
自環境では成功するのに Travis CI上で失敗するという事象に出会いました。

Travis上でのエラーログ

  Capybara::Poltergeist::JavascriptError:
       One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).

    TypeError: 'undefined' is not a function (evaluating 'ReactElementValidator.createElement.bind(
             null,
             type
           )')
    TypeError: 'undefined' is not a function (evaluating 'ReactElementValidator.createElement.bind(
             null,
             type
           )')
...

phantomjsバージョンを確認した所、
Travisは1.9.8(2015/03/11 時点)で、自環境は2.0.0でした。

ここに原因があると推測し、
Travis側のphantomjsのバージョンを上げる方法はないのかと調査した所、以下のような記事を見つけました。

以下の設定を追加する事で無事にテストを実施することができました。

.travis.yml
before_install:
  - wget https://s3.amazonaws.com/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2
  - tar -xjf phantomjs-2.0.0-ubuntu-12.04.tar.bz2
  - sudo rm -rf /usr/local/phantomjs/bin/phantomjs
  - sudo mv phantomjs /usr/local/phantomjs/bin/phantomjs

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7