Files
node/test/parallel/test-http-dns-error.js
Vse Mozhet Byt 1633f8b243 test: simplify test skipping
* Make common.skip() exit.

  Also add common.printSkipMessage() for partial skips.

* Don't make needless things before skip

Backport-PR-URL: https://github.com/nodejs/node/pull/14838
PR-URL: https://github.com/nodejs/node/pull/14021
Fixes: https://github.com/nodejs/node/issues/14016
Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-09-05 12:49:51 -04:00

44 lines
1023 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
let https;
if (common.hasCrypto) {
https = require('https');
} else {
common.printSkipMessage('missing crypto');
}
const host = '*'.repeat(256);
function do_not_call() {
throw new Error('This function should not have been called.');
}
function test(mod) {
// Bad host name should not throw an uncatchable exception.
// Ensure that there is time to attach an error listener.
const req1 = mod.get({host: host, port: 42}, do_not_call);
req1.on('error', common.mustCall(function(err) {
assert.strictEqual(err.code, 'ENOTFOUND');
}));
// http.get() called req1.end() for us
const req2 = mod.request({method: 'GET', host: host, port: 42}, do_not_call);
req2.on('error', common.mustCall(function(err) {
assert.strictEqual(err.code, 'ENOTFOUND');
}));
req2.end();
}
if (common.hasCrypto) {
test(https);
} else {
common.printSkipMessage('missing crypto');
}
test(http);