diff --git a/lib/RequestShortener.js b/lib/RequestShortener.js index fd67f9814..3d9af0002 100644 --- a/lib/RequestShortener.js +++ b/lib/RequestShortener.js @@ -67,7 +67,7 @@ class RequestShortener { result = result.replace(this.currentDirectoryRegExp, "!."); } if (this.parentDirectoryRegExp) { - result = result.replace(this.parentDirectoryRegExp, `!../`); + result = result.replace(this.parentDirectoryRegExp, "!../"); } if (!this.buildinsAsModule && this.buildinsRegExp) { result = result.replace(this.buildinsRegExp, "!(webpack)"); diff --git a/test/RequestShortener.unittest.js b/test/RequestShortener.unittest.js new file mode 100644 index 000000000..f38c36fb8 --- /dev/null +++ b/test/RequestShortener.unittest.js @@ -0,0 +1,22 @@ +"use strict"; + +const RequestShortener = require("../lib/RequestShortener"); + +describe("RequestShortener", () => { + it("should create RequestShortener and shorten with ./ file in directory", () => { + const shortener = new RequestShortener("/foo/bar"); + expect(shortener.shorten("/foo/bar/some.js")).toEqual("./some.js"); + }); + + it("should create RequestShortener and shorten with ../ file in parent directory", () => { + const shortener = new RequestShortener("/foo/bar"); + expect(shortener.shorten("/foo/baz/some.js")).toEqual("../baz/some.js"); + }); + + it("should create RequestShortener and not shorten parent directory neighbor", () => { + const shortener = new RequestShortener("/foo/bar"); + expect(shortener.shorten("/foo_baz/bar/some.js")).toEqual( + "/foo_baz/bar/some.js" + ); + }); +});