Skip to content

Commit

Permalink
test: fix and refactor test-http-invalid-urls
Browse files Browse the repository at this point in the history
When the second argument to `assert.throws()` is a string, it is not
treated as the expected error message but rather the message that the
assertion should display if no error is thrown. Ths change fixes that
error in `test-http-invalid-urls.js`.

Instead of skipping the test when there is no crypto, the test is now
run but with `http` only. `https` is skipped.

Logging was fixed. Previously, errors would be written out as being in
the `[object Object]` module rather than `http` or `https`.

PR-URL: #15678
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
Trott authored and BridgeAR committed Oct 1, 2017
1 parent da40050 commit 2e215f1
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions test/parallel/test-http-invalid-urls.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
/* eslint-disable crypto-check */

'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('assert');
const http = require('http');
const https = require('https');
const error = 'Unable to determine the domain name';
const modules = { 'http': http };

if (common.hasCrypto) {
const https = require('https');
modules.https = https;
}

function test(host) {
['get', 'request'].forEach((method) => {
[http, https].forEach((module) => {
assert.throws(() => module[method](host, () => {
throw new Error(`${module}.${method} should not connect to ${host}`);
}), error);
['get', 'request'].forEach((fn) => {
Object.keys(modules).forEach((module) => {
const doNotCall = common.mustNotCall(
`${module}.${fn} should not connect to ${host}`
);
const throws = () => { modules[module][fn](host, doNotCall); };
common.expectsError(throws, { code: 'ERR_INVALID_DOMAIN_NAME' });
});
});
}
Expand Down

0 comments on commit 2e215f1

Please sign in to comment.