我已經使用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
上的失敗測試請讓我知道您是否需要更多信息。在此先感謝您的幫助!