Note that there are some explanatory texts on larger screens.

plurals
  1. POhttp-request testing of nodejs (connect) apps with mocha?
    primarykey
    data
    text
    <p>I want to write some integration-tests for my connect-middleware and test it with real-http-requests instead of mocked requests. </p> <p>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. </p> <p>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. </p> <pre><code>Error: connect ECONNREFUSED </code></pre> <p>Here is my Setup... </p> <pre class="lang-js prettyprint-override"><code>//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 }); }); }); </code></pre> <p>That's the content of my testServer.js file which runs as a subprocess. </p> <pre class="lang-js prettyprint-override"><code>//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); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload