1
環境:heroku,node.js - 表示,使用mocha進行測試。使用不同的數據庫進行npm測試階段
如何配置heroku以使用NODE_ENV =「test」啓動npm test
並使用NODE_ENV =「production」調用服務器(「node server.js
」)。
這意味着,我需要兩個服務器調用 - 一旦測試(其中我連接到我的測試分貝),一次生產(其中我連接到我的生產DB)
我想使用不同的數據庫「npm test
」階段,因爲我的測試也造成假數據。
這裏是我的測試樣子如何:
var supertest = require("supertest");
var should = require('chai').should();
var config = require('../server/config');
var server = supertest.agent(config.baseUrl);
describe("User controller", function() {
describe("HTTP Verbs", function() {
it("GET", function (done) {
console.log(config.dbUrl);
console.log(config.baseUrl);
server.post("/api/user") {
.send(utils.createMockedUserPlainObject())
.end(function(err, res) {
server.get("/api/user/list")
.expect("Content-type", /json/)
.expect(200) // THis is HTTP response
.end(function (err, res) {
// HTTP status should be 200
res.status.should.equal(200);
res.body.should.have.length(1);
done();
});
})
});
});
});