webpack/test/identifier.unittest.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

"use strict";
2017-04-06 19:33:57 +08:00
const identifierUtil = require("../lib/util/identifier");
2017-04-06 19:33:57 +08:00
describe("util/identifier", () => {
describe("makePathsRelative", () => {
describe("given a context and a pathConstruct", () => {
it("computes the correct relative results for the path construct", () => {
2018-12-23 20:22:07 +08:00
[
[
"/some/dir/",
"/some/dir/to/somewhere|some/other/dir!../more/dir",
"./to/somewhere|some/other/dir!../more/dir"
],
[
"/dir/",
"/dir/to/somewhere|some/other/dir!../more/dir",
"./to/somewhere|some/other/dir!../more/dir"
],
[
"/",
"/dir/to/somewhere|some/other/dir!../more/dir",
"./dir/to/somewhere|some/other/dir!../more/dir"
],
[
"c:\\some\\dir\\",
"c:\\some\\dir\\to\\somewhere|some/other/dir!../more/dir",
2018-12-25 18:34:48 +08:00
"./to/somewhere|some/other/dir!../more/dir"
2018-12-23 20:22:07 +08:00
],
[
"c:\\some\\dir\\",
"C:\\some\\dir\\to\\somewhere|some/other/dir!../more/dir",
2018-12-25 18:34:48 +08:00
"./to/somewhere|some/other/dir!../more/dir"
],
[
"C:\\some\\dir",
"C:\\some\\dir\\to\\somewhere|some/other/dir!../more/dir",
"./to/somewhere|some/other/dir!../more/dir"
],
[
"C:\\\\some\\dir",
"c:\\some\\\\dir\\to\\\\somewhere|some/other/dir!../more/dir",
"./to/somewhere|some/other/dir!../more/dir"
],
2019-02-19 15:58:46 +08:00
["/dir", "/dir/to/somewhere??ref-123", "./to/somewhere??ref-123"]
2018-12-23 20:22:07 +08:00
].forEach(([context, pathConstruct, expected]) => {
2019-02-19 15:58:46 +08:00
expect(identifierUtil.makePathsRelative(context, pathConstruct)).toBe(
expected
);
2018-12-23 20:22:07 +08:00
});
});
});
});
});