1 // Copyright 2014 Simon Lydell
\r
2 // X11 (“MIT”) Licensed. (See LICENSE.)
\r
4 var test = require("tape")
\r
6 var resolveUrl = require("../")
\r
10 test("resolveUrl", function(t) {
\r
14 t.equal(typeof resolveUrl, "function", "is a function")
\r
17 resolveUrl("https://example.com/"),
\r
18 "https://example.com/"
\r
21 var loc = "https://example.com/articles/resolving-urls/edit"
\r
24 resolveUrl(loc, "remove"),
\r
25 "https://example.com/articles/resolving-urls/remove"
\r
29 resolveUrl(loc, "/static/scripts/app.js"),
\r
30 "https://example.com/static/scripts/app.js"
\r
34 resolveUrl(loc, "/static/scripts/app.js", "../source-maps/app.js.map"),
\r
35 "https://example.com/static/source-maps/app.js.map"
\r
39 resolveUrl(loc, "/static/scripts/app.js", "../source-maps/app.js.map", "../coffee/app.coffee"),
\r
40 "https://example.com/static/coffee/app.coffee"
\r
44 resolveUrl(loc, "//cdn.example.com/jquery.js"),
\r
45 "https://cdn.example.com/jquery.js"
\r
50 test("edge cases", function(t) {
\r
54 t["throws"](resolveUrl, /at least one argument/, "throws with no arguments")
\r
56 var accidentallyUndefined
\r
59 function() { result = resolveUrl(accidentallyUndefined) },
\r
60 "undefined is still an argument"
\r
62 t.ok(result.match(/\/undefined$/), "undefined is stringified")
\r
65 resolveUrl("http://foo.org/test", undefined, {}, ["a/b"], null),
\r
66 "http://foo.org/a/null",
\r
67 "arguments are stringified"
\r