node.js - Use different database for the npm test phase -
environment: heroku, node.js - express, testing mocha.
how can configure heroku launch npm test
node_env="test" , invoke server ("node server.js
") node_env="production" .
this means need 2 server invocations - once testing (where connect test db) , once production (where connect production db)
i want use different db in "npm test
" phase since tests create fake data.
here how test like:
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) // http response .end(function (err, res) { // http status should 200 res.status.should.equal(200); res.body.should.have.length(1); done(); }); }) }); }); });
well,
its seems magic lies inside supertest.
replace:
var server = supertest.agent(config.baseurl);
with:
var app = require('../server'); var server = supertest.agent(app);
Comments
Post a Comment