webpack/test/identifier.unittest.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-02-06 22:37:11 +08:00
/* globals describe it */
"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"
],
[
"/dir",
"/dir/to/somewhere??ref-123",
"./to/somewhere??ref-123"
2018-12-23 20:22:07 +08:00
]
].forEach(([context, pathConstruct, expected]) => {
2018-12-23 20:22:07 +08:00
expect(identifierUtil.makePathsRelative(context, pathConstruct)).toBe(
expected
);
});
});
});
});
});