Getting started with Travis

Lupyana Mbembati
ALCwithForLoop
Published in
3 min readJun 14, 2019

Getting started with Travis

What / Who Is Travis? Why do I need it?

Have you ever written code for an app, It works. Then you added more code to do more things. The app gets more complex and bigger as time goes. Imagine you have like 100 functionalities in your app. You want to check them all. How are you gonna do it.?

Meet Travis

Your own personal butler to test your code for you. hehehehe But seriously what is Travis?
Well, Travis is a service that deals with two things continuous integration (CI) and continuous deployment (CD).

We will focus on CI, for now
The idea behind continuous integration is that CI will automatically run your tests ( unit tests, etc ) and other checks for you.

Why should you care?

You are not a caveman. If you have the time and patience to go through all 100 functionalities, knock yourself out.
If you are lazy, smart and a badass, you will use CI.

Travis CI to the rescue

As the name suggests, CI stands for Continuous Integration which is an integrated test that runs continuously on every time when someone pushes a commit (or mostly when opening a Pull Request).
It helps us to automate the testing process. But this doesn’t stop you from doing your tests locally.

Setup

The warm-up
By now you have noticed that I have mentioned tests a couple of times. Yes, tests are a prerequisite to this. You need to have at least a few tests setup to proceed.

- First, sign up at their website
- Link your GitHub account and enable it for the repository you would like to implement this.

Ready set go!
Travis requires instruction to be told what to do. We achieve this using a travis.yml file.
- On the root folder of your repo create a .travis.yml file.
- This is very important if you put it anywhere else it will not work

This is where it gets interesting
The .travis.yml file is a configuration file. it contains key and value pairs that have a certain meaning. Here is how it looks like but not limited to.


language: node_js
node_js:
— “version number”
install: true
script:
— “do something”

This is like the bare minimum you need. More config can be found here

So what does this mean?
- First, you specify the language you are using for your project
- You can also specify the version (optional)
- Install step, is in case you need to install anything if you don’t need to install anything pass true.
- script step this is how you tell Travis to do something. Essentially this is where you tell Travis to run the test script as specified in your package.json file. eg. npm run test.

Moment of truth

  • Save the travis.yml file, commit and push.
    - If you have tests setup and have setup Travis correctly you should notice that builds are triggered once you push to your repo or do a PR.
    - Alternatively, if you visit you will see the details of your build.

--

--