Skip to content

Instantly share code, notes, and snippets.

@aflatter
Created February 23, 2011 14:13
Show Gist options
  • Save aflatter/feabb0152d953ed7ef51 to your computer and use it in GitHub Desktop.
Save aflatter/feabb0152d953ed7ef51 to your computer and use it in GitHub Desktop.
// Run from jsdom root
require.paths.unshift('lib');
var assert = function(expected, result) {
if (expected == result) return;
console.log("I expected '" + expected + "' but got '" + result + "'");
throw "fail";
}
var fakeDoc = function(uri, base) {
var fake = {'URL': uri};
fake.length = base ? 1 : 0;
fake.getElementsByTagName = function() { return this; }
fake.item = function() { return {'href': base}; }
return fake;
}
var html = require('jsdom/level2/html').dom.level2.html,
loader = html.resourceLoader;
// Document got URI.
var doc = fakeDoc('http://foo.bar/');
assert("http://example.com/foo.js", loader.resolve(doc, 'http://example.com/foo.js'));
assert("file://hello/world", loader.resolve(doc, 'file://hello/world'));
assert("http://foo.bar/foo", loader.resolve(doc, '/foo'));
// Document without URI and base
var doc = fakeDoc();
assert("http://foo/bar.js", loader.resolve(doc, 'http://foo/bar.js'));
assert("file://foo/bar.js", loader.resolve(doc, 'file://foo/bar.js'));
// What to do here?
// assert(expected, loader.resolve(doc, 'foo.js'));
// assert(expected, loader.resolve(doc, '/foo.js'));
// https://github.com/tmpvar/jsdom/issues#issue/87
assert("http://foo/bar.js", loader.resolve(doc, '//foo/bar.js'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment