jperezov
jperezov

Reputation: 3171

Running Intern tests using PhantomJS and Travis CI

Context:

I'm running some unit tests using the Intern framework. Since the code I'm testing is a package I published on NPM, I wanted to integrate it with Travis CI.

On my local, all the tests run fine. With Travis CI, however, the tests stall because of starting the PhantomJS webserver.

This is my Travis CI file:

language: node_js
node_js:
  - "4"
env:
  - CXX=g++-4.8
addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - g++-4.8
before_script:
  - bower install
  - npm install grunt-cli -g
  - grunt installation
  - phantomjs --webdriver=4444

Because the phantomjs command starts a webserver, it never runs npm test. It just halts on the webserver.

Question:

How do I make it so that I can run npm test after starting PhantomJS? Is there some way I can move that process to the background, or start another process to run my tests? Or is there some way of calling both phantomjs --webddriver=444 and intern-runner config=tests/intern at the same time?

Upvotes: 1

Views: 302

Answers (1)

C Snover
C Snover

Reputation: 18766

Since Travis CI commands are simply shell commands you should be able to start phantomjs and then continue along by forking it:

- phantomjs --webdriver=4444 &

(Note the ampersand at the end.)

You may also need to add a sleep to give the process time to start, since it doesn’t appear that PhantomJS has a way to daemonize itself or touch a pid-file when it is ready.

There are also plenty of other scripts and/or Grunt tasks you can use to run PhantomJS, but this should be the minimal change necessary to solve your problem.

Upvotes: 2

Related Questions