<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>server &amp;mdash; Simple Engineering</title>
    <link>https://getsimple.works/tag:server</link>
    <description></description>
    <pubDate>Wed, 15 Apr 2026 06:09:28 +0000</pubDate>
    <item>
      <title>Testing expressjs routes without spinning up a server.</title>
      <link>https://getsimple.works/testing-expressjs-routes-without-spinning-up-a-server-y33d?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[In most integration and end-to-end routes testing, a live server may be deemed critical to make reasonable test assertions. A live server is not always a good idea, especially in a sandboxed environment such as a CI environment where opening server ports may be restricted, if not outright prohibited. In this article, we explore the combination of mocking HTTP requests/responses to make use of an actual server obsolete. &#xA;&#xA;In this article we will talk about: &#xA;&#xA;Mocking the Server instance  &#xA;Mocking Route&#39;s Request/Response objects&#xA;Modularization of routes and revealing server instance&#xA;Auto reload(hot reload) using:nodemon, supervisor or forever&#xA;&#xA;  Even though this blog post was designed to offer complementary materials to those who bought my Testing nodejs Applications book, the content can help any software developer to tuneup working environment. You use this link to buy the book.  Testing nodejs Applications Book Cover&#xA;&#xA;Show me the code&#xA;&#xA;//&#xA;var User = require(&#39;./models&#39;).User; &#xA;module.exports = function getProfile(req, res, next){&#xA;  User.findById(req.params.id, function(error, user){&#xA;    if(error) return next(error);&#xA;    return res.status(200).json(user);&#xA;  });&#xA;};&#xA;&#xA;//Router that Authentication Middleware&#xA;var router = require(&#39;express&#39;).Router();&#xA;var authenticated = require(&#39;./middleware/authenticated&#39;);&#xA;var getUsers = require(&#39;./users/get-user&#39;);&#xA;router.get(&#39;/users/:id&#39;, authenticated, getUser);&#xA;module.exports = router;&#xA;&#xA;What can possibly go wrong?&#xA;&#xA;When trying to figure out how to approach testing expressjs routes, the driving force behind falling into the integration testing trap is the need to start a server. the following points may be a challenge:&#xA;&#xA;Routes should be served at any time while testing &#xA;Testing in a sandboxed environments restricts server to use(open new ports, serving requests, etc) &#xA;Mocking request/response objects to wipe need of a server out of the picture&#xA;&#xA;Testing routes without spinning up a server&#xA;&#xA;The key is mocking request/response objects. A typical REST integration testing shares similarities with the following snippet. &#xA;&#xA;var app = require(&#39;express&#39;).express(),&#xA;  request = require(&#39;./support/http&#39;);&#xA;&#xA;describe(&#39;req .route&#39;, function(){&#xA;  it(&#39;should serve on route /user/:id/edit&#39;, function(done){&#xA;    app.get(&#39;/user/:id/edit&#39;, function(req, res){&#xA;      expect(req.route.path).to.equal(&#39;/user/:id/edit&#39;);&#xA;      res.end();&#xA;    });&#xA;&#xA;    request(app)&#xA;      .get(&#39;/user/12/edit&#39;)&#xA;      .expect(200, done);&#xA;  });&#xA;  it(&#39;should serve get requests&#39;, function(done){&#xA;    app.get(&#39;/user/:id/edit&#39;, function(req, res){&#xA;      expect(req.route.method).to.equal(&#39;get&#39;);&#xA;      res.end();&#xA;    });&#xA;&#xA;    request(app)&#xA;    .get(&#39;/user/12/edit&#39;)&#xA;    .expect(200, done);&#xA;  });&#xA;});&#xA;Example:&#xA;&#xA;  example from so and supertest. supertest spins up a server if necessary. In case we don&#39;t want to have a server, then an alternative dupertest can be a reasonable alternative. request = require(&#39;./support/http&#39;) is the utility that may use either of those two libraries to provide a request. &#xA;&#xA;Choosing tools &#xA;&#xA;  If you haven&#39;t already, reading &#34;How to choose the right tools&#34; blog post gives insights on a framework we used to choose the tools we suggest in this blog. &#xA;&#xA;Following our own Choosing the right tools framework, we suggest adopting the following tools, when testing expressjs routes by mocking out the server: &#xA;&#xA;There exists well respected such as jasmine(jasmine-node), ava, jest in the wild. mocha can just do fine for example sakes. &#xA;There is also code instrumentation tools in the wild. mocha integrates well with istanbul test coverage and reporting library.&#xA;supertest,  nock and dupertest are framework for mocking mocking HTTP, whereas nock intercepts requests. dupertest responds better to our demands(not spinning up a server).  &#xA;&#xA;Workflow&#xA;&#xA;  If you haven&#39;t already, read the &#34;How to write test cases developers will love&#34;&#xA;&#xA;In package.json at &#34;test&#34; - add next line&#xA;  &#34;istanbul test mocha -- --color --reporter mocha-lcov-reporter specs&#34;&#xA;OR &#34;nyc test mocha -- --color --reporter mocha-lcov-reporter specs&#34;&#xA;&#xA;Then run the tests using &#xA;$ npm test --coverage &#xA;Example: istanbul generates reports as tests progress&#xA;&#xA;Conclusion&#xA;&#xA;To sum up, it pays off to spend extra time writing some tests. Effective tests can be written before, as well as after writing code. The balance should be at the discretion of the developer. &#xA;&#xA;Testing nodejs routes are quite intimidating on the first encounter. This article contributed to shifting fear into opportunities. &#xA;&#xA;Removing the server dependency makes it easy to validate the most common use cases at a lower cost. Writing a good meaningful message is pure art. There are additional complimentary materials in the &#34;Testing nodejs applications&#34; book. &#xA;&#xA;References&#xA;&#xA;Testing nodejs Applications book&#xA;A TDD Approach to Building a Todo API Using nodejs and mongodb ~ SemaphoreCI Community Tutorials&#xA;&#34;How to build and test REST with nodejs Express Mocha&#34; ~  The Way of Code&#xA;&#xA;#tdd #testing #nodejs #expressjs #server]]&gt;</description>
      <content:encoded><![CDATA[<p>In most integration and <em>end-to-end</em> routes testing, a live server may be deemed critical to make reasonable test assertions. A live server is not always a good idea, especially in a sandboxed environment such as a CI environment where opening server ports may be restricted, if not outright prohibited. In this article, we explore the combination of mocking HTTP requests/responses to make use of an actual server obsolete.</p>

<p><strong><em>In this article we will talk about:</em></strong></p>
<ul><li>Mocking the Server instance<br/></li>
<li>Mocking Route&#39;s Request/Response objects</li>
<li>Modularization of routes and revealing server instance</li>
<li>Auto reload(hot reload) using:<code>nodemon</code>, <code>supervisor</code> or <code>forever</code></li></ul>

<blockquote><p>Even though this blog post was designed to offer complementary materials to those who bought my <strong><em><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></em></strong>, the content can help any software developer to tuneup working environment. <strong><em><a href="https://bit.ly/2ZFJytb">You use this link to buy the book</a></em></strong>.  <a href="https://bit.ly/2ZFJytb"><img src="https://snap.as/a/42OS2vs.png" alt="Testing nodejs Applications Book Cover"/></a></p></blockquote>

<h2 id="show-me-the-code" id="show-me-the-code">Show me the code</h2>

<pre><code class="language-JavaScript">//
var User = require(&#39;./models&#39;).User; 
module.exports = function getProfile(req, res, next){
  User.findById(req.params.id, function(error, user){
    if(error) return next(error);
    return res.status(200).json(user);
  });
};

//Router that Authentication Middleware
var router = require(&#39;express&#39;).Router();
var authenticated = require(&#39;./middleware/authenticated&#39;);
var getUsers = require(&#39;./users/get-user&#39;);
router.get(&#39;/users/:id&#39;, authenticated, getUser);
module.exports = router;

</code></pre>

<h2 id="what-can-possibly-go-wrong" id="what-can-possibly-go-wrong">What can possibly go wrong?</h2>

<p>When trying to figure out how to approach testing <code>expressjs</code> routes, the driving force behind falling into the integration testing trap is the need to start a server. the following points may be a challenge:</p>
<ul><li>Routes should be served at any time while testing</li>
<li>Testing in a sandboxed environments restricts server to use(open new ports, serving requests, etc)</li>
<li>Mocking request/response objects to wipe need of a server out of the picture</li></ul>

<h2 id="testing-routes-without-spinning-up-a-server" id="testing-routes-without-spinning-up-a-server">Testing routes without spinning up a server</h2>

<p>The key is mocking request/response objects. A typical REST integration testing shares similarities with the following snippet.</p>

<pre><code class="language-JavaScript">
var app = require(&#39;express&#39;).express(),
  request = require(&#39;./support/http&#39;);

describe(&#39;req .route&#39;, function(){
  it(&#39;should serve on route /user/:id/edit&#39;, function(done){
    app.get(&#39;/user/:id/edit&#39;, function(req, res){
      expect(req.route.path).to.equal(&#39;/user/:id/edit&#39;);
      res.end();
    });

    request(app)
      .get(&#39;/user/12/edit&#39;)
      .expect(200, done);
  });
  it(&#39;should serve get requests&#39;, function(done){
    app.get(&#39;/user/:id/edit&#39;, function(req, res){
      expect(req.route.method).to.equal(&#39;get&#39;);
      res.end();
    });

    request(app)
    .get(&#39;/user/12/edit&#39;)
    .expect(200, done);
  });
});
</code></pre>

<p><em><em>Example</em>:</em></p>

<blockquote><p>example from <a href="https://stackoverflow.com/a/14703801/132610">so</a> and <a href="https://github.com/visionmedia/express/tree/master/test"><code>supertest</code></a>. <code>supertest</code> spins up a server if necessary. In case we don&#39;t want to have a server, then an alternative <a href="https://www.npmjs.com/package/dupertest"><code>dupertest</code></a> can be a reasonable alternative. <code>request = require(&#39;./support/http&#39;)</code> is the utility that may use either of those two libraries to provide a request.</p></blockquote>

<h2 id="choosing-tools" id="choosing-tools">Choosing tools</h2>

<blockquote><p>If you haven&#39;t already, reading <a href="./how-to-choose-the-right-tools.md">“How to choose the right tools”</a> blog post gives insights on a framework we used to choose the tools we suggest in this blog.</p></blockquote>

<p>Following our own <em>Choosing the right tools</em> framework, we suggest adopting the following tools, when testing <code>expressjs</code> routes by mocking out the server:</p>
<ul><li>There exists well respected such as <code>jasmine</code>(<code>jasmine-node</code>), <code>ava</code>, <code>jest</code> in the wild. <code>mocha</code> can just do fine for example sakes.</li>
<li>There is also code instrumentation tools in the wild. <code>mocha</code> integrates well with <code>istanbul</code> test coverage and reporting library.</li>
<li><code>supertest</code>,  <code>nock</code> and <code>dupertest</code> are framework for mocking mocking HTTP, whereas <code>nock</code> intercepts requests. <code>dupertest</code> responds better to our demands(not spinning up a server).<br/></li></ul>

<h2 id="workflow" id="workflow">Workflow</h2>

<blockquote><p>If you haven&#39;t already, read the <a href="./how-to-write-test-cases-developers-will-love.md">“How to write test cases developers will love”</a></p></blockquote>

<pre><code class="language-shell"># In package.json at &#34;test&#34; - add next line
&gt; &#34;istanbul test mocha -- --color --reporter mocha-lcov-reporter specs&#34;
# OR &#34;nyc test mocha -- --color --reporter mocha-lcov-reporter specs&#34;

# Then run the tests using 
$ npm test --coverage 
</code></pre>

<p><em><em>Example</em>: <code>istanbul</code> generates reports as tests progress</em></p>

<h2 id="conclusion" id="conclusion">Conclusion</h2>

<p>To sum up, it pays off to spend extra time writing some tests. Effective tests can be written before, as well as after writing code. The balance should be at the discretion of the developer.</p>

<p>Testing <code>nodejs</code> routes are quite intimidating on the first encounter. This article contributed to shifting fear into opportunities.</p>

<p>Removing the server dependency makes it easy to validate the most common use cases at a lower cost. Writing a good meaningful message is pure art. There are additional complimentary materials in the <strong>“Testing <code>nodejs</code> applications”</strong> book.</p>

<h3 id="references" id="references">References</h3>
<ul><li><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></li>
<li>A TDD Approach to Building a Todo API Using <code>nodejs</code> and <code>mongodb</code> ~ <a href="https://semaphoreci.com/community/tutorials/a-tdd-approach-to-building-a-todo-api-using-node-js-and-mongodb">SemaphoreCI Community Tutorials</a></li>
<li><em>“How to build and test REST with <code>nodejs</code> Express Mocha”</em> ~  <a href="https://thewayofcode.wordpress.com/2013/04/21/how-to-build-and-test-rest-api-with-nodejs-express-mocha/">The Way of Code</a></li></ul>

<p><a href="https://getsimple.works/tag:tdd" class="hashtag"><span>#</span><span class="p-category">tdd</span></a> <a href="https://getsimple.works/tag:testing" class="hashtag"><span>#</span><span class="p-category">testing</span></a> <a href="https://getsimple.works/tag:nodejs" class="hashtag"><span>#</span><span class="p-category">nodejs</span></a> <a href="https://getsimple.works/tag:expressjs" class="hashtag"><span>#</span><span class="p-category">expressjs</span></a> <a href="https://getsimple.works/tag:server" class="hashtag"><span>#</span><span class="p-category">server</span></a></p>
]]></content:encoded>
      <guid>https://getsimple.works/testing-expressjs-routes-without-spinning-up-a-server-y33d</guid>
      <pubDate>Thu, 17 Jun 2021 04:13:53 +0000</pubDate>
    </item>
    <item>
      <title>Testing expressjs routes without spinning up a server.</title>
      <link>https://getsimple.works/testing-expressjs-routes-without-spinning-up-a-server?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[In most integration and end-to-end routes testing, a live server may be deemed critical to make reasonable test assertions. A live server is not always a good idea, especially in a sandboxed environment such as a CI environment where opening server ports may be restricted, if not outright prohibited. In this article, we explore the combination of mocking HTTP requests/responses to make use of an actual server obsolete. &#xA;&#xA;In this article we will talk about: &#xA;&#xA;Mocking the Server instance  &#xA;Mocking Route&#39;s Request/Response objects&#xA;Modularization of routes and revealing server instance&#xA;Auto reload(hot reload) using:nodemon, supervisor or forever&#xA;&#xA;  Even though this blog post was designed to offer complementary materials to those who bought my Testing nodejs Applications book, the content can help any software developer to tuneup working environment. You use this link to buy the book.  Testing nodejs Applications Book Cover&#xA;&#xA;Show me the code&#xA;&#xA;//&#xA;var User = require(&#39;./models&#39;).User; &#xA;module.exports = function getProfile(req, res, next){&#xA;  User.findById(req.params.id, function(error, user){&#xA;    if(error) return next(error);&#xA;    return res.status(200).json(user);&#xA;  });&#xA;};&#xA;&#xA;//Router that Authentication Middleware&#xA;var router = require(&#39;express&#39;).Router();&#xA;var authenticated = require(&#39;./middleware/authenticated&#39;);&#xA;var getUsers = require(&#39;./users/get-user&#39;);&#xA;router.get(&#39;/users/:id&#39;, authenticated, getUser);&#xA;module.exports = router;&#xA;&#xA;What can possibly go wrong?&#xA;&#xA;When trying to figure out how to approach testing expressjs routes, the driving force behind falling into the integration testing trap is the need to start a server. the following points may be a challenge:&#xA;&#xA;Routes should be served at any time while testing &#xA;Testing in a sandboxed environments restricts server to use(open new ports, serving requests, etc) &#xA;Mocking request/response objects to wipe need of a server out of the picture&#xA;&#xA;Testing routes without spinning up a server&#xA;&#xA;The key is mocking request/response objects. A typical REST integration testing shares similarities with the following snippet. &#xA;&#xA;var app = require(&#39;express&#39;).express(),&#xA;  request = require(&#39;./support/http&#39;);&#xA;&#xA;describe(&#39;req .route&#39;, function(){&#xA;  it(&#39;should serve on route /user/:id/edit&#39;, function(done){&#xA;    app.get(&#39;/user/:id/edit&#39;, function(req, res){&#xA;      expect(req.route.path).to.equal(&#39;/user/:id/edit&#39;);&#xA;      res.end();&#xA;    });&#xA;&#xA;    request(app)&#xA;      .get(&#39;/user/12/edit&#39;)&#xA;      .expect(200, done);&#xA;  });&#xA;  it(&#39;should serve get requests&#39;, function(done){&#xA;    app.get(&#39;/user/:id/edit&#39;, function(req, res){&#xA;      expect(req.route.method).to.equal(&#39;get&#39;);&#xA;      res.end();&#xA;    });&#xA;&#xA;    request(app)&#xA;    .get(&#39;/user/12/edit&#39;)&#xA;    .expect(200, done);&#xA;  });&#xA;});&#xA;Example:&#xA;&#xA;  example from so and supertest. supertest spins up a server if necessary. In case we don&#39;t want to have a server, then an alternative dupertest can be a reasonable alternative. request = require(&#39;./support/http&#39;) is the utility that may use either of those two libraries to provide a request. &#xA;&#xA;Choosing tools &#xA;&#xA;  If you haven&#39;t already, reading &#34;How to choose the right tools&#34; blog post gives insights on a framework we used to choose the tools we suggest in this blog. &#xA;&#xA;Following our own Choosing the right tools framework, we suggest adopting the following tools, when testing expressjs routes by mocking out the server: &#xA;&#xA;There exists well respected such as jasmine(jasmine-node), ava, jest in the wild. mocha can just do fine for example sakes. &#xA;There is also code instrumentation tools in the wild. mocha integrates well with istanbul test coverage and reporting library.&#xA;supertest,  nock and dupertest are framework for mocking mocking HTTP, whereas nock intercepts requests. dupertest responds better to our demands(not spinning up a server).  &#xA;&#xA;Workflow&#xA;&#xA;  If you haven&#39;t already, read the &#34;How to write test cases developers will love&#34;&#xA;&#xA;In package.json at &#34;test&#34; - add next line&#xA;  &#34;istanbul test mocha -- --color --reporter mocha-lcov-reporter specs&#34;&#xA;OR &#34;nyc test mocha -- --color --reporter mocha-lcov-reporter specs&#34;&#xA;&#xA;Then run the tests using &#xA;$ npm test --coverage &#xA;Example: istanbul generates reports as tests progress&#xA;&#xA;Conclusion&#xA;&#xA;To sum up, it pays off to spend extra time writing some tests. Effective tests can be written before, as well as after writing code. The balance should be at the discretion of the developer. &#xA;&#xA;Testing nodejs routes are quite intimidating on the first encounter. This article contributed to shifting fear into opportunities. &#xA;&#xA;Removing the server dependency makes it easy to validate the most common use cases at a lower cost. Writing a good meaningful message is pure art. There are additional complimentary materials in the &#34;Testing nodejs applications&#34; book. &#xA;&#xA;References&#xA;&#xA;Testing nodejs Applications book&#xA;A TDD Approach to Building a Todo API Using nodejs and mongodb ~ SemaphoreCI Community Tutorials&#xA;&#34;How to build and test REST with nodejs Express Mocha&#34; ~  The Way of Code&#xA;&#xA;#tdd #testing #nodejs #expressjs #server]]&gt;</description>
      <content:encoded><![CDATA[<p>In most integration and <em>end-to-end</em> routes testing, a live server may be deemed critical to make reasonable test assertions. A live server is not always a good idea, especially in a sandboxed environment such as a CI environment where opening server ports may be restricted, if not outright prohibited. In this article, we explore the combination of mocking HTTP requests/responses to make use of an actual server obsolete.</p>

<p><strong><em>In this article we will talk about:</em></strong></p>
<ul><li>Mocking the Server instance<br/></li>
<li>Mocking Route&#39;s Request/Response objects</li>
<li>Modularization of routes and revealing server instance</li>
<li>Auto reload(hot reload) using:<code>nodemon</code>, <code>supervisor</code> or <code>forever</code></li></ul>

<blockquote><p>Even though this blog post was designed to offer complementary materials to those who bought my <strong><em><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></em></strong>, the content can help any software developer to tuneup working environment. <strong><em><a href="https://bit.ly/2ZFJytb">You use this link to buy the book</a></em></strong>.  <a href="https://bit.ly/2ZFJytb"><img src="https://snap.as/a/42OS2vs.png" alt="Testing nodejs Applications Book Cover"/></a></p></blockquote>

<h2 id="show-me-the-code" id="show-me-the-code">Show me the code</h2>

<pre><code class="language-JavaScript">//
var User = require(&#39;./models&#39;).User; 
module.exports = function getProfile(req, res, next){
  User.findById(req.params.id, function(error, user){
    if(error) return next(error);
    return res.status(200).json(user);
  });
};

//Router that Authentication Middleware
var router = require(&#39;express&#39;).Router();
var authenticated = require(&#39;./middleware/authenticated&#39;);
var getUsers = require(&#39;./users/get-user&#39;);
router.get(&#39;/users/:id&#39;, authenticated, getUser);
module.exports = router;

</code></pre>

<h2 id="what-can-possibly-go-wrong" id="what-can-possibly-go-wrong">What can possibly go wrong?</h2>

<p>When trying to figure out how to approach testing <code>expressjs</code> routes, the driving force behind falling into the integration testing trap is the need to start a server. the following points may be a challenge:</p>
<ul><li>Routes should be served at any time while testing</li>
<li>Testing in a sandboxed environments restricts server to use(open new ports, serving requests, etc)</li>
<li>Mocking request/response objects to wipe need of a server out of the picture</li></ul>

<h2 id="testing-routes-without-spinning-up-a-server" id="testing-routes-without-spinning-up-a-server">Testing routes without spinning up a server</h2>

<p>The key is mocking request/response objects. A typical REST integration testing shares similarities with the following snippet.</p>

<pre><code class="language-JavaScript">
var app = require(&#39;express&#39;).express(),
  request = require(&#39;./support/http&#39;);

describe(&#39;req .route&#39;, function(){
  it(&#39;should serve on route /user/:id/edit&#39;, function(done){
    app.get(&#39;/user/:id/edit&#39;, function(req, res){
      expect(req.route.path).to.equal(&#39;/user/:id/edit&#39;);
      res.end();
    });

    request(app)
      .get(&#39;/user/12/edit&#39;)
      .expect(200, done);
  });
  it(&#39;should serve get requests&#39;, function(done){
    app.get(&#39;/user/:id/edit&#39;, function(req, res){
      expect(req.route.method).to.equal(&#39;get&#39;);
      res.end();
    });

    request(app)
    .get(&#39;/user/12/edit&#39;)
    .expect(200, done);
  });
});
</code></pre>

<p><em><em>Example</em>:</em></p>

<blockquote><p>example from <a href="https://stackoverflow.com/a/14703801/132610">so</a> and <a href="https://github.com/visionmedia/express/tree/master/test"><code>supertest</code></a>. <code>supertest</code> spins up a server if necessary. In case we don&#39;t want to have a server, then an alternative <a href="https://www.npmjs.com/package/dupertest"><code>dupertest</code></a> can be a reasonable alternative. <code>request = require(&#39;./support/http&#39;)</code> is the utility that may use either of those two libraries to provide a request.</p></blockquote>

<h2 id="choosing-tools" id="choosing-tools">Choosing tools</h2>

<blockquote><p>If you haven&#39;t already, reading <a href="./how-to-choose-the-right-tools.md">“How to choose the right tools”</a> blog post gives insights on a framework we used to choose the tools we suggest in this blog.</p></blockquote>

<p>Following our own <em>Choosing the right tools</em> framework, we suggest adopting the following tools, when testing <code>expressjs</code> routes by mocking out the server:</p>
<ul><li>There exists well respected such as <code>jasmine</code>(<code>jasmine-node</code>), <code>ava</code>, <code>jest</code> in the wild. <code>mocha</code> can just do fine for example sakes.</li>
<li>There is also code instrumentation tools in the wild. <code>mocha</code> integrates well with <code>istanbul</code> test coverage and reporting library.</li>
<li><code>supertest</code>,  <code>nock</code> and <code>dupertest</code> are framework for mocking mocking HTTP, whereas <code>nock</code> intercepts requests. <code>dupertest</code> responds better to our demands(not spinning up a server).<br/></li></ul>

<h2 id="workflow" id="workflow">Workflow</h2>

<blockquote><p>If you haven&#39;t already, read the <a href="./how-to-write-test-cases-developers-will-love.md">“How to write test cases developers will love”</a></p></blockquote>

<pre><code class="language-shell"># In package.json at &#34;test&#34; - add next line
&gt; &#34;istanbul test mocha -- --color --reporter mocha-lcov-reporter specs&#34;
# OR &#34;nyc test mocha -- --color --reporter mocha-lcov-reporter specs&#34;

# Then run the tests using 
$ npm test --coverage 
</code></pre>

<p><em><em>Example</em>: <code>istanbul</code> generates reports as tests progress</em></p>

<h2 id="conclusion" id="conclusion">Conclusion</h2>

<p>To sum up, it pays off to spend extra time writing some tests. Effective tests can be written before, as well as after writing code. The balance should be at the discretion of the developer.</p>

<p>Testing <code>nodejs</code> routes are quite intimidating on the first encounter. This article contributed to shifting fear into opportunities.</p>

<p>Removing the server dependency makes it easy to validate the most common use cases at a lower cost. Writing a good meaningful message is pure art. There are additional complimentary materials in the <strong>“Testing <code>nodejs</code> applications”</strong> book.</p>

<h3 id="references" id="references">References</h3>
<ul><li><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></li>
<li>A TDD Approach to Building a Todo API Using <code>nodejs</code> and <code>mongodb</code> ~ <a href="https://semaphoreci.com/community/tutorials/a-tdd-approach-to-building-a-todo-api-using-node-js-and-mongodb">SemaphoreCI Community Tutorials</a></li>
<li><em>“How to build and test REST with <code>nodejs</code> Express Mocha”</em> ~  <a href="https://thewayofcode.wordpress.com/2013/04/21/how-to-build-and-test-rest-api-with-nodejs-express-mocha/">The Way of Code</a></li></ul>

<p><a href="https://getsimple.works/tag:tdd" class="hashtag"><span>#</span><span class="p-category">tdd</span></a> <a href="https://getsimple.works/tag:testing" class="hashtag"><span>#</span><span class="p-category">testing</span></a> <a href="https://getsimple.works/tag:nodejs" class="hashtag"><span>#</span><span class="p-category">nodejs</span></a> <a href="https://getsimple.works/tag:expressjs" class="hashtag"><span>#</span><span class="p-category">expressjs</span></a> <a href="https://getsimple.works/tag:server" class="hashtag"><span>#</span><span class="p-category">server</span></a></p>
]]></content:encoded>
      <guid>https://getsimple.works/testing-expressjs-routes-without-spinning-up-a-server</guid>
      <pubDate>Thu, 17 Jun 2021 00:33:29 +0000</pubDate>
    </item>
  </channel>
</rss>