Skip to content

Commit

Permalink
interpolateName.js: fix unreachable code; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
denisx committed Apr 28, 2024
1 parent 50890cd commit a083806
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/interpolateName.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ function interpolateName(loaderContext, name, options = {}) {
directory = resourcePath.replace(/\\/g, "/").replace(/\.\.(\/)?/g, "_$1");
}

if (directory.length === 1) {
if (directory.length <= 1) {
directory = "";
} else if (directory.length > 1) {
} else {
// directory.length > 1
folder = path.basename(directory);
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/interpolateName.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,21 @@ describe("interpolateName()", () => {
"/path/to/",
"should interpolate [path] token",
],
[
[loaderContext, "[path]", { context: "/path/" }],
"to/",
"should interpolate [path] token with context",
],
[
[loaderContext, "[folder]", {}],
"to",
"should interpolate [folder] token",
],
[
[{ resourcePath: "." }, "[folder]", {}],
"",
"should interpolate [folder] token with short resourcePath",
],
]);
});

Expand Down

0 comments on commit a083806

Please sign in to comment.