jeudi 7 janvier 2016

Mocha test passes locally, but fails on Travis CI

I am trying to add testing to the website I'm building. I'm using Mocha as my testing framework and Chai and expect as my assertion library. I made a simple test just to make sure things work and then I created a Gruntfile to run my tests. The test is a simple test that just verifies that true === true and it worked both locally and on Travis CI. Now, even though I haven't changed anything in the test, it only works locally, but fails on Travis CI. It was passing before and it still passes locally, so I'm not sure what to change.

My simple test code looks like this:

'use strict';

var chai = require('chai');
var expect = chai.expect;

describe('Test that tests run', function(done) {
  it('should run a test', function(done) {
    expect(true).to.eql(true);
    done();
  });
});

My Gruntfile looks like this:

'use strict';

module.exports = function(grunt) {
  grunt.loadNpmTasks('grunt-simple-mocha');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-jscs');

  // initialize Grunt
  grunt.initConfig({
    // create jshint task
    jshint: {
      dev: {
        // tell jshint what check
        src: ['Gruntfile.js', 'server.js', 'js/**/*.js', 'models/**/*.js', 'routes/**/*.js', '!build/**', '!tests/client/bundle.js', '!tests/karma_tests/bundle.js', '!js/imageMapResizer.min.js', '!js/kickstart.js', '!js/form-validator.js'],
        options: {
          node: true,
          globals: {
            describe: true,
            it: true,
            before: true,
            after: true,
            beforeEach: true,
            afterEach: true,
            res: true
          }
        }
      },

      mocha: {
        // tell mocha where test files are
        src: ['tests/**/*.js', '!tests/client/bundle.js', '!tests/karma_tests/bundle.js'],
        options: {
          node: true,
          globals: {
            describe: true,
            it: true,
            before: true,
            after: true,
            beforeEach: true,
            afterEach: true,
            res: true,
            expect: true
          }
        }
      },
      // create jscs task
      jscs: {
        dev: {
          // tell jscs to test the same files as jshint
          src: ['<%= jshint.dev.src %>', '<%= jshint.mocha.src %>']
        }
      }
    },

    // create simplemocha task
    simplemocha: {
      dev: {
        src: ['tests/test_entry.js']
      }
    }
  });

  // register linting task
  grunt.registerTask('lint', ['jshint:dev', 'jshint:mocha' /*, 'jshint:jasmine'*/ ]);
  // register mocha test task
  grunt.registerTask('test', ['simplemocha:dev']);
  grunt.registerTask('default', ['test']);
};

And .travis.yml looks like this:

language: node_js
node_js:
  - "4.1"
  - "4.0"
  - "0.12"
  - "0.11"
  - "0.10"
  - "0.8"
  - "0.6"
  - "iojs"
before_install:
  - npm install -g grunt-cli
script: grunt test

Let me know if you have questions or want to see more code. Thanks in advance for all your help!

Aucun commentaire:

Enregistrer un commentaire