2016-01-20 132 views
0

我已经使用SQL Server和Node.js构建了一个站点,并且我使用了Mocha和Chai来进行测试。这一切都在本地正常工作,并且任何不需要访问数据库的测试都可以在Travis CI上正确运行,但是因为我的密码,用户名,db路径等存储在我的.env文件中,这是gitignored Travis可以'访问数据库进行测试。如何访问Travis CI中的环境变量

我试图根据these instructions from the Travis docs设置环境变量,但登录失败。我知道找到了环境变量,因为错误消息是:Unhandled rejection SequelizeConnectionError: Login failed for user 'EventAdmin'.,'EventAdmin'是环境变量的用户名,但由于某种原因,密码未被接受。我知道密码是正确的,因为我直接从我的.env文件复制它。

我.travis.yml文件看起来像这样:

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

我的测试(其中本地工作)看起来是这样的:

'use strict'; 
 

 
var chai = require('chai'); 
 
var expect = chai.expect; 
 
var assert = chai.assert; 
 
var chaihttp = require('chai-http'); 
 

 

 
chai.use(chaihttp); 
 

 
require('../server.js'); 
 

 
describe('Test /showfullteam route', function() { 
 
    it('should load all MS contacts from /showfullteam', function(done) { 
 
    chai.request('localhost:3000') 
 
     .get('/showfullteam') 
 
     .end(function(err, res) { 
 
     expect(err).to.eql(null); 
 
     for (var i = 0; i < res.body.length; i++) { 
 
      expect(res.body[i]).to.include.keys('firstName', 'lastName', 'email', 'newsletterSubscription', 'contactDescription', 'msTeamMember', 'msTeamTitle', 'showOnHomePage', 'headShot', 'company', 'address', 'country', 'interestId', 'allowNotifications', 'allowPersonalInfoSharing'); 
 
      expect(res.body[i].msTeamMember).to.eql(true); 
 
      expect(typeof res.body[i].firstName).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); 
 
      expect(typeof res.body[i].lastName).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); 
 
      expect(typeof res.body[i].email).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); 
 
      if (res.body[i].newsletterSubscription) { 
 
      assert.typeOf(res.body[i].newsletterSubscription, 'boolean'); 
 
      } 
 
      if (res.body[i].msTeamMember) { 
 
      assert.typeOf(res.body[i].msTeamMember, 'boolean'); 
 
      } 
 
      if (res.body[i].showOnHomePage) { 
 
      assert.typeOf(res.body[i].showOnHomePage, 'boolean'); 
 
      } 
 
      if (res.body[i].allowNotifications) { 
 
      assert.typeOf(res.body[i].allowNotifications, 'boolean'); 
 
      } 
 
      if (res.body[i].interestId) { 
 
      assert.isNumber(res.body[i].interestId); 
 
      } 
 
      expect(typeof res.body[i].contactDescription).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); 
 
      expect(typeof res.body[i].headShot).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); 
 
      expect(typeof res.body[i].company).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); 
 
      expect(typeof res.body[i].address).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); 
 
      expect(typeof res.body[i].country).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); 
 
      expect(typeof res.body[i].allowPersonalInfoSharing).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); 
 
     }; 
 
     done(); 
 
     }); 
 
    }); 
 
});

您可以在我的GitHub repo上看到完整的项目以及Travis CI

上的失败测试请让我知道您是否需要更多信息。在此先感谢您的帮助!

回答

1

我想出了如何设置环境变量,但那不是问题。问题在于SQL Server与travis不兼容。我切换到mariadb,测试通过:-)