Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8160193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:09:41+00:00 2026-06-06T18:09:41+00:00

I want to write some integration-tests for my connect-middleware and test it with real-http-requests

  • 0

I want to write some integration-tests for my connect-middleware and test it with real-http-requests instead of mocked requests.

The middleware stack behaves differently depending on the configuration passed, that’s why i wanted to run the middleware-server as a subprocess which i can restart with different configuration after each test.

The problem is that the test-server runs without problems (ether started directly or within test-file) and is accessible via browser, but i don’t get a response via http.get(..) because the connection is refused.

Error: connect ECONNREFUSED

Here is my Setup…

//MOCHA TEST FILE: testServer.test.js

function runTestServer(configEnv) {

    var cmd = "node " + path.resolve(__dirname, "runTestServer.js");

    var testSrv = exec(cmd, { "env" : configEnv },
    function (error, stdout, stderr) {
        if (error !== null) {
            console.log('exec error: ' + error);
        }
    });

    return testSrv;
}


describe("onRequest", function(){
    it("should return a response", function (done) {

        this.timeout(100000);

        var serverInstance = runTestServer({
            "appDir" : path.resolve(__dirname, "../../handleHttp/app")
        });

        http.get({host:'localhost', port:9090, path:'/'}, function (res) {
            //error thrown before this callback gets called
        });

    });
});

That’s the content of my testServer.js file which runs as a subprocess.

//Test-Process-File: runTestServer.js
var connect = require("connect"),
handleHttp = require("...")

var server = connect();
handleHttp.init(server); //this methods applies the middleware
console.log("TEST-SERVER listening on 9090");
server.listen(9090);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:09:42+00:00Added an answer on June 6, 2026 at 6:09 pm

    I figured this one out while posting the questions and want to answer it here, in case someone else is having the same kind of problem.

    So what’s the problem?

    The whole thing is async!

    So the server won’t be initialized before the requests are being fired to the server.

    Solution

    Give the subprocess some time to initialize and make the testServer-Loader Async!

    function runTestServer(configEnv, callback) {
    
        var cmd = "node " + path.resolve(__dirname, "../runTestServer.js"),
        testSrv;
    
        testSrv = exec(cmd, { "env" : configEnv },
                     function (error, stdout, stderr) {
                       if (error !== null) {
                         console.log('exec error: ' + error);
                      }
                  });
    
        setTimeout(function() {
            callback(testSrv);
        }, 1000);
    }
    

    My mocha-test-file:

    describe("handleHttp", function() {
      describe("#Basic Requesting", function() {
    
        var serverInstance;
    
        before(function(done) {
            runTestServer({
                "appDir" : path.resolve(__dirname, "...")
            }, function(srvInstance) {
                serverInstance = srvInstance;
                done();
            });
        });
    
        //run your tests here 
    

    The fixed timeout is not really a nice solution. Maybe it’s possible to enable some communication between the main and subprocess in order to find out when the http-server is ready. Suggestions appreciated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write integration tests for my application. I want to test, that
I am using Specflow (http://specflow.org/) to write some integration tests and I would like
I want to write some test cases for my web app, but stuck at
I have some integration tests that test the processing of USB data from a
I want to write integration application test to test the full CRUD operations. I
I want to write some plugin to analysis Java source code. Which part of
I want to write some tel numbers to excel file, some of them start
I want to write some configuration in web.config file, that will make my ASP.Net
I want to write some debugging output to the log to review it with
I want to write some games, but I don't have any game development experience.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.