Export it:
module.exports = getUrlLoader;
then try:
var test = require('tape');
var http = require('http');
var https = require('https');
var subject = require('./yourmodule');
test('check it out', function (t) {
t.equal(subject('https') == https);
t.equal(subject('http') == http);
t.end();
});
This exploits the fact that the return value from require is cached and consistent.
Also, just as a side note, please consider the url.parse method, rather than doing a naive indexOf on the URL for this purpose.
Aria