2016-02-05 37 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); 
相关问题