File: network-error.js

package info (click to toggle)
node-superagent 9.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,464 kB
  • sloc: javascript: 11,641; makefile: 77
file content (33 lines) | stat: -rw-r--r-- 764 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
const assert = require('assert');
const net = require('net');
const request = require('../support/client');
const express = require('../support/express');

function getFreePort(fn) {
  const server = net.createServer();
  server.listen(0, () => {
    const { port } = server.address();
    server.close(() => {
      fn(port);
    });
  });
}

describe('with network error', () => {
  before(function (done) {
    // connecting to a free port
    // will trigger a connection refused
    getFreePort((port) => {
      this.port = port;
      done();
    });
  });

  it('should error', function (done) {
    request.get(`http://localhost:${this.port}/`).end((error, res) => {
      assert(error, 'expected an error');
      done();
    });
  });
});