Integration: Travis CI

Integrate Ghost Inspector with Travis CI

Search our documentation:

Toggle Documentation Menu

Integration: Travis CI

Ghost Inspector tests can be run inside your Travis CI builds. Below we've provided two examples. The first is a simple setup that triggers a suite of tests on their default URLs during the testing stage. The second is a more advanced setup that will launch your application, create a private tunnel to it's interface, then trigger a suite of Ghost Inspector tests using that tunnel URL.

 

Example #1 (Simple)

For our simple Travis CI configuration example, we'll be triggering a Ghost Inspector test suite (which default settings) using their webhooks feature after the build is complete. Add the snippet below to the .travis.yml file in your repo.

In the example below, you will need to swap in your own values for [suite-id] and [api-key].

notifications:
  webhooks:
    urls:
      - https://api.ghostinspector.com/v1/suites/[suite-id]/execute/?apiKey=[api-key]
    on_success: always
    on_failure: never

 

Example #2 (Advanced)

For our more advanced Travis CI configuration example, we'll be starting our application, creating an ngrok tunnel, then triggering a Ghost Inspector test suite (using that tunnel) during our build. This example follows a similar route to our CircleCI blog post which walks through this process in slightly more detail.

First, we'll setup environmental variables for our API key ($GHOST_API_KEY) and suite ID ($GHOST_SUITE_ID). Travis CI's encryption capabilities can be used here, if you'd like. We'll also need to setup an ngrok.io account and add a $NGROK_TOKEN variable with our ngrok.io token.

env:
- GHOST_API_KEY=[customize] GHOST_SUITE_ID=[customize] NGROK_TOKEN=[customize]

Now that our variables are setup, we need to add commands to download a couple of programs that we'll use for tunneling and json parsing:

install:
  # Download ngrok
  - curl -sO https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
  - unzip $PWD/ngrok-stable-linux-amd64.zip
  - chmod +x $PWD/ngrok
  # Download json parser for determining ngrok tunnel
  - curl -sO http://stedolan.github.io/jq/download/linux64/jq
  - chmod +x $PWD/jq

With those programs available we can now add the commands to start the application, create the ngrok tunnel, and trigger the Ghost Inspector suite. We're doing this in the script section, though you could do this elsewhere, like in the before_deploy, if you choose. Note that the commands that deal with launching your application and creating a tunnel to it's port must be customized.

script:
  # Start our application
  - node server.js &
  # Open ngrok tunnel
  - $PWD/ngrok authtoken $NGROK_TOKEN
  - $PWD/ngrok http 3000 > /dev/null &
  # Execute Ghost Inspector tests using the ngrok tunnel
  - curl "https://api.ghostinspector.com/v1/suites/$GHOST_SUITE_ID/execute/?apiKey=$GHOST_API_KEY&startUrl=$(curl 'http://localhost:4040/api/tunnels' | $PWD/jq -r '.tunnels[1].public_url')" > $PWD/ghostinspector.json
  # Exit with a fail status if any tests have failed
  - if [ $(grep -c '"passing":false' $PWD/ghostinspector.json) -ne 0 ]; then exit 1; fi

 

Note: These examples assume that you want to execute a suite after your project has been built. For other options, please see our API.