Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 30, 2024
1 parent 2b23e17 commit a85706b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 42 deletions.
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

98 changes: 59 additions & 39 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,17 @@ runTest("normalizeString", normalizeString, {
// './foobar./../a/./': 'a',

// Windows
[normalizeWindowsPath("C:\\temp\\..")]: "C:",
[normalizeWindowsPath("C:\\temp\\..\\.\\Users")]: "C:/Users",
[normalizeWindowsPath("C:\\temp\\..\\.well-known\\Users")]:
[normalizeWindowsPath(String.raw`C:\temp\..`)]: "C:",
[normalizeWindowsPath(String.raw`C:\temp\..\.\Users`)]: "C:/Users",
[normalizeWindowsPath(String.raw`C:\temp\..\.well-known\Users`)]:
"C:/.well-known/Users",
[normalizeWindowsPath("C:\\temp\\..\\..well-known\\Users")]:
[normalizeWindowsPath(String.raw`C:\temp\..\..well-known\Users`)]:
"C:/..well-known/Users",
[normalizeWindowsPath("C:\\a\\..\\")]: "C:",
[normalizeWindowsPath("C:\\temp\\myfile.html")]: "C:/temp/myfile.html",
[normalizeWindowsPath("\\temp\\myfile.html")]: "temp/myfile.html",
[normalizeWindowsPath(".\\myfile.html")]: "myfile.html",
[normalizeWindowsPath(String.raw`C:\temp\myfile.html`)]:
"C:/temp/myfile.html",
[normalizeWindowsPath(String.raw`\temp\myfile.html`)]: "temp/myfile.html",
[normalizeWindowsPath(String.raw`.\myfile.html`)]: "myfile.html",
});

runTest("basename", basename, [
Expand All @@ -81,11 +82,11 @@ runTest("basename", basename, [
["./undefined", undefined, "undefined"],

// Windows
["C:\\temp\\myfile.html", "myfile.html"],
["\\temp\\myfile.html", "myfile.html"],
[".\\myfile.html", "myfile.html"],
[".\\myfile.html", ".html", "myfile"],
[".\\undefined", undefined, "undefined"],
[String.raw`C:\temp\myfile.html`, "myfile.html"],
[String.raw`\temp\myfile.html`, "myfile.html"],
[String.raw`.\myfile.html`, "myfile.html"],
[String.raw`.\myfile.html`, ".html", "myfile"],
[String.raw`.\undefined`, undefined, "undefined"],
]);

runTest("dirname", dirname, {
Expand Down Expand Up @@ -135,7 +136,7 @@ runTest("format", format, [

// Windows
[{ name: "file", base: "file.txt" }, "file.txt"],
[{ dir: "C:\\path\\dir", base: "file.txt" }, "C:/path/dir/file.txt"],
[{ dir: String.raw`C:\path\dir`, base: "file.txt" }, "C:/path/dir/file.txt"],
]);

runTest("join", join, [
Expand All @@ -145,18 +146,29 @@ runTest("join", join, [
["/test//", "//path", "/test/path"],
["some/nodejs/deep", "../path", "some/nodejs/path"],
["./some/local/unix/", "../path", "some/local/path"],
["./some\\current\\mixed", "..\\path", "some/current/path"],
["../some/relative/destination", "..\\path", "../some/relative/path"],
[String.raw`./some\current\mixed`, String.raw`..\path`, "some/current/path"],
[
"../some/relative/destination",
String.raw`..\path`,
"../some/relative/path",
],
["some/nodejs/deep", "../path", "some/nodejs/path"],
["/foo", "bar", "baz/asdf", "quux", "..", "/foo/bar/baz/asdf"],

["C:\\foo", "bar", "baz\\asdf", "quux", "..", "C:/foo/bar/baz/asdf"],
["some/nodejs\\windows", "../path", "some/nodejs/path"],
["some\\windows\\only", "..\\path", "some/windows/path"],
[
String.raw`C:\foo`,
"bar",
String.raw`baz\asdf`,
"quux",
"..",
"C:/foo/bar/baz/asdf",
],
[String.raw`some/nodejs\windows`, "../path", "some/nodejs/path"],
[String.raw`some\windows\only`, String.raw`..\path`, "some/windows/path"],
// UNC paths
["\\\\server\\share\\file", "..\\path", "//server/share/path"],
["\\\\.\\c:\\temp\\file", "..\\path", "//./c:/temp/path"],
["\\\\server/share/file", "../path", "//server/share/path"],
[String.raw`\\server\share\file`, String.raw`..\path`, "//server/share/path"],
[String.raw`\\.\c:\temp\file`, String.raw`..\path`, "//./c:/temp/path"],
[String.raw`\\server/share/file`, "../path", "//server/share/path"],
]);

runTest("normalize", normalize, {
Expand Down Expand Up @@ -216,14 +228,14 @@ it("parse", () => {
});

// Windows
expect(parse("C:\\path\\dir\\file.txt")).to.deep.equal({
expect(parse(String.raw`C:\path\dir\file.txt`)).to.deep.equal({
root: "C:",
dir: "C:/path/dir",
base: "file.txt",
ext: ".txt",
name: "file",
});
expect(parse(".\\dir\\file")).to.deep.equal({
expect(parse(String.raw`.\dir\file`)).to.deep.equal({
root: ".",
dir: "./dir",
base: "file",
Expand All @@ -244,11 +256,19 @@ runTest("relative", relative, [
],

// Windows
["C:\\orandea\\test\\aaa", "C:\\orandea\\impl\\bbb", "../../impl/bbb"],
["C:\\orandea\\test\\aaa", "c:\\orandea\\impl\\bbb", "../../impl/bbb"],
["C:\\", "C:\\foo\\bar", "foo/bar"],
["C:\\foo", "C:\\", ".."],
["C:\\foo", "d:\\bar", "D:/bar"],
[
String.raw`C:\orandea\test\aaa`,
String.raw`C:\orandea\impl\bbb`,
"../../impl/bbb",
],
[
String.raw`C:\orandea\test\aaa`,
String.raw`c:\orandea\impl\bbb`,
"../../impl/bbb",
],
["C:\\", String.raw`C:\foo\bar`, "foo/bar"],
[String.raw`C:\foo`, "C:\\", ".."],
[String.raw`C:\foo`, String.raw`d:\bar`, "D:/bar"],
[
() => process.cwd().replace(/\\/g, "/"),
"./dist/client/b-scroll.d.ts",
Expand Down Expand Up @@ -278,13 +298,13 @@ runTest("resolve", resolve, [
],

// Windows
["C:\\foo\\bar", ".\\baz", "C:/foo/bar/baz"],
["\\foo\\bar", ".\\baz", "/foo/bar/baz"],
["\\foo\\bar", "..", ".", ".\\baz", "/foo/baz"],
["\\foo\\bar", "\\tmp\\file\\", "/tmp/file"],
["\\foo\\bar", undefined, null, "", "\\tmp\\file\\", "/tmp/file"],
[String.raw`C:\foo\bar`, String.raw`.\baz`, "C:/foo/bar/baz"],
[String.raw`\foo\bar`, String.raw`.\baz`, "/foo/bar/baz"],
[String.raw`\foo\bar`, "..", ".", String.raw`.\baz`, "/foo/baz"],
[String.raw`\foo\bar`, "\\tmp\\file\\", "/tmp/file"],
[String.raw`\foo\bar`, undefined, null, "", "\\tmp\\file\\", "/tmp/file"],
[
"\\foo\\bar",
String.raw`\foo\bar`,
undefined,
null,
"",
Expand All @@ -297,15 +317,15 @@ runTest("resolve", resolve, [
[
"wwwroot",
"static_files\\png\\",
"..\\gif\\image.gif",
String.raw`..\gif\image.gif`,
() =>
`${process.cwd().replace(/\\/g, "/")}/wwwroot/static_files/gif/image.gif`,
],
["C:\\Windows\\path\\only", "../../reports", "C:/Windows/reports"],
[String.raw`C:\Windows\path\only`, "../../reports", "C:/Windows/reports"],
[
"C:\\Windows\\long\\path\\mixed/with/unix",
String.raw`C:\Windows\long\path\mixed/with/unix`,
"../..",
"..\\../reports",
String.raw`..\../reports`,
"C:/Windows/long/reports",
],
]);
Expand Down Expand Up @@ -367,7 +387,7 @@ export function runTest(name, function_, items) {
expected,
)} on Windows`, () => {
cwd = process.cwd;
process.cwd = vi.fn(() => "C:\\Windows\\path\\only");
process.cwd = vi.fn(() => String.raw`C:\Windows\path\only`);
expect(function_(...arguments_.map((i) => _r(i)))).to.equal(
_r(expected),
);
Expand Down

0 comments on commit a85706b

Please sign in to comment.