2016-02-05 67 views
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(); 
        }); 
       }) 
      }); 
    }); 
}); 

回答

0

好,

它似乎神奇之處就在於裏面supertest。

取代:

var server = supertest.agent(config.baseUrl); 

有:

var app = require('../server'); 

var server = supertest.agent(app); 
相關問題