Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not exactly sure how this is handled here generally but meanwhile I have found the solution to my problem and I post it here in case someone will struggle with the same issue.</p> <p>Now I can tell that the problem has to do with the asynchronous character of node.js, http server and unit testing under these circumstances.</p> <p>Anyways here is my solution:</p> <pre><code>var nodeunit = require('../lib/nodeunit/lib/nodeunit.js'); var http = require('http'); var logfile = require('../src/logfile'); var testmsg = 'this is my first testmessage:-_,.:;öüäß?1234"@€'; var testutil = function (config, envReady) { // simple testutil to provide http server environment for unit testing var logger = logfile.loggerFactory(config); // actually this is the tricky part which ensures that the server // is still available once request/ response are executed process.nextTick(function () { if (envReady &amp;&amp; typeof envReady === 'function') { envReady(logger, logfile.write); } }); }; exports.test_logfile = function (test) { test.expect(4); var options = { host: 'localhost', port: 3000, path: '/simple', method: 'PUT', record_message: function(msg) { test.equal(msg, testmsg); } }; testutil(options, function (logger, write) { var write_ready = function(res) { // called when write is completed test.equal(res.statusCode, 201); test.equal(res.headers['content-type'], 'text/plain'); test.equal(res.body, 'created'); logger.stop(); test.done(); }; write(testmsg, options, write_ready); }); }; </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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