Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix assert.throws in test-http-invalid-urls #15678

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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