Testing with server that's already running.

Skip to first unread message

Jef Harkay

Sep 30, 2014, 5:41:50 PM9/30/14
to compo...@googlegroups.com
I'm curious to know if there's a way to run npm test by using a server that's already running.  The init.js file that's created by default creates a new server and uses that instance with supertest's request, but I'd like to essentially use my running instance or somehow call the server.js file to create my server.  The reason being that I have some global variables that get created in server.js, and I'd rather not reproduce the logic in there.

Jef Harkay

Oct 3, 2014, 5:44:06 PM10/3/14
to compo...@googlegroups.com
I figured out how to do this, and here's my init.js file:

var request = require('supertest');

global.getApp = function(done) {
if (!process.env.UNIT_TEST_HOST) {
.env.UNIT_TEST_HOST = '';
var app = request(process.env.UNIT_TEST_HOST);
return {
: app,
: {
Cookie: 'myCookie=blah'

And then in each unit test, I call getApp(), set my local request var to getApp().app, and use it like I normally would (without having to specify the app in parens when using request).
Reply all
Reply to author
0 new messages