title: Failed test is hanging Jenkins pipeline
body: <p>I am making a pipeline on Jenkins to test and deploy my node.js application using Docker containers. But I am getting my pipeline stuck because a test is failing. The behaviour I would expect is pipeline finishes without executing next stages but it will not get stuck.</p>
  
  <p><strong>Jenkinsfile</strong>:</p>
  
  <pre><code>pipeline {
    agent any
    stages {
      stage('Build') {
        steps {
          sh '''docker build --tag my-web:$BUILD_NUMBER .
  docker stop my-web&amp;&amp; docker rm my-web
  echo "Build step finished"'''
        }
      }
      stage('Unit test') {
        steps {
          sh '''docker build -t my-web-test -f Dockerfile.test .
  docker run --rm my-web-test
  '''
        }
      }
      stage('Run') {
        steps {
          sh '''docker run --name my-web -p 3000:3000 my-web:$BUILD_NUMBER node /var/www/index.js &amp;
  '''
          echo 'RUNNING'
        }
      }
      stage('End') {
        steps {
          echo 'End of pipeline'
        }
      }
    }
  }
  </code></pre>
  
  <p><strong>Dockerfile.test</strong>:</p>
  
  <pre><code>FROM node:alpine
  
  RUN mkdir /var/test
  WORKDIR /var/test
  COPY package.json /var/test/
  RUN npm install &amp;&amp; npm install -g mocha
  COPY src/ /var/test/
  CMD ["mocha", "tests/", "--recursive"]
  </code></pre>
  
  <p><strong>When I trigger the pipeline:</strong></p>
  
  <ul>
  <li>If I remove <code>Unit test</code> stage from pipeline everything works <strong>OK</strong> and application begins running.</li>
  <li>If I <strong>do not</strong> remove <code>Unit test</code> stage, testing stage begins and I get a result of 14 test passed and 1 failed but the pipeline hangs in this step so <code>Run</code> step never triggers and the pipeline keeps in <code>Running</code> status.</li>
  </ul>
  
  <blockquote>
    <p><strong>14 passing (2s)</strong></p>
    
    <p><strong>1 failing</strong></p>
    
    <p><strong>1</strong>) Checking user first-time-login</p>
  
  <pre><code>   Should redirect to change-password page:
  
   Error: expected "Location" of "/dashboard/change-password", got "/dashboard"
  
    at Test._assertHeader (node_modules/supertest/lib/test.js:249:12)
  
    at Test._assertFunction (node_modules/supertest/lib/test.js:283:11)
  
    at Test.assert (node_modules/supertest/lib/test.js:173:18)
  
    at localAssert (node_modules/supertest/lib/test.js:131:12)
  
    at /var/test/node_modules/supertest/lib/test.js:128:5
  
    at Test.Request.callback (node_modules/superagent/lib/node/index.js:728:3)
  
    at IncomingMessage.&lt;anonymous&gt; (node_modules/superagent/lib/node/index.js:916:18)
  
    at endReadableNT (_stream_readable.js:1154:12)
  
    at processTicksAndRejections (internal/process/task_queues.js:77:11)
  </code></pre>
  </blockquote>