Mocha 测试在本地通过,但在 Travis 上失败 CI

Mocha test passes locally, but fails on Travis CI

我正在尝试向我正在构建的网站添加测试。我使用 Mocha 作为我的测试框架,使用 Chai 和 expect 作为我的断言库。我做了一个简单的测试以确保一切正常,然后我为 运行 我的测试创建了一个 G运行tfile。该测试是一个简单的测试,仅验证 true === true 并且它在本地和 Travis CI 上都有效。现在,即使我没有在测试中更改任何内容,它也只能在本地工作,但在 Travis CI 上会失败。它之前通过了,它仍然在本地通过,所以我不确定要更改什么。

我的简单测试代码如下所示:

'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();
  });
});

我的 G运行t 文件如下所示:

'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']);
};

而 .travis.yml 看起来像这样:

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

如果您有任何问题或想查看更多代码,请告诉我。在此先感谢您的帮助!

在与 Travis CI 进一步挖掘之后,我发现有 2 个问题。首先是 node.js 版本 0.6 和 0.8 与我的许多节点包不兼容。另一个问题是我包含的 2 个节点包与 linux 不兼容,这是 OS Travis CI 用于 运行 测试的。这些包是 node-sqlserver-unofficialmsnodesqlv8

我真的不需要在 node.js 版本 0.6 或 0.8 上工作,我可以在没有 2 节点包的情况下工作,所以一旦我删除了旧节点版本和包,我的测试就通过了表现出色。