Travis-CI with jasmine-node
Asked Answered
G

3

10

I'm trying to get travis-ci to test my nodejs module with jasmine-node. When I run the tests from the commandline, they all pass, but for whatever reason, Travis always reports my build as failing. My .travis.yml looks like this:

language: node_js
node_js:
    - 0.6
    - 0.8

and my package.json looks like this:

"scripts": {
    "test": "jasmine-node tests/*.spec.js"
}

I've tried adding a before_script to my travis.yml

language: node_js
node_js:
    - 0.6
    - 0.8
before_script:
    - "sudo npm i -g jasmine-node"

Any ideas?

Galangal answered 9/9, 2012 at 4:44 Comment(7)
Do you have jasmine-node as a dev dependency? What is the output from the failed Travis-CI test? You should just post a link to the test since it's public.Folberth
I actually just got running. I'm posting my answer now.Galangal
Also note you can add development dependencies to your package.json with the --save-dev flag. Example: npm install --save-dev jasmine-nodeSingularity
@Noah, I could do it that way instead of using the before script, but then I would have to change the test command to something like node_modules/jasmine-node/bin/jasmine-node tests/*.spec.js. I'm not sure which is preferred. And I'm not aware that you can specify to install a dep globally in package.json.Galangal
It is up to you if you want to use the global or the local dev dependcy. I like to keep things contained whenever possible. Therefor in my projects I like to use the local binary in the node_modules. I use a makefile to run the tests and specify the path to the local binary as a variable in the makefile. Then in the package.json specify make test as the scripts: test command. This allows someone else to install your module and execute npm test without having any vague global requirementsSingularity
That does seem like a cleaner way to do things. I'll have to try that. Thanks for the tip!Galangal
You can check with npm run test. Btw by me I did not need the before_script in the travis.yml... It automatically run the test script... Was there an upgrade by travis since 2012 or what? :-)Laise
G
10

After spending some time with the travis-ci lint web app, it looks like it just came down to a matter of formatting in my .travis.yml file. My text editor was inserting tabs, where it appears that yaml requires you only use spaces. I also added quotes around everything for good measure.

It now looks like this, after making sure I was only using single spaces and newlines:

language: node_js
node_js:
    - "0.6"
    - "0.8"
before_script:
    - "npm i -g jasmine-node"
Galangal answered 10/9, 2012 at 5:7 Comment(1)
Updated to remove sudo from before_script as suggested by @dan-taoGalangal
S
1

Here is a repository with a working exemple of a travis build launching jasmine-node tests: https://github.com/yosethegame/yosethegame.

Note that the package.json declares the jasmine-node dependency that travis will install in its npm install phase.

Stillman answered 17/10, 2014 at 19:17 Comment(0)
V
0

I had a similar problem some time ago, I was using at the time jasmine-node -g and since it was a simple kata I thought there was no need for adding a package.json in the folder, but when I moved onto integrating that same project with travis-ci, I went through hell to be able to configure it.

With time I've learnt that it is better to keep things nice and tight and use your friendly package.json instead of global installations (There is a good post talking about it here for example: Why to avoid global test runners )

My advice would be for you to add jasmine-node to the package.json, something as short as this

{
    "name" : "XXX",
    "version" : "1.0.0",
    "devDependencies" : {
        "jasmine-node" : "latest"
    },
    "scripts" : {
        "test" : "jasmine-node specs/*spec.js"
    }  
}

Will surely save you a headache and tons of configuring time not only with travis-ci integration, and it may as well save someone else's time in case someone wants to reuse what you've done. ;)

Vlada answered 12/10, 2014 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.