سؤال

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?

هل كانت مفيدة؟

المحلول

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"

نصائح أخرى

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.

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. ;)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top