Support tilde paths ("~" prefix) in readConfig/Sync APIs (for "file" parameter and "extends" keys).

This commit is contained in:
David Anson 2022-05-16 22:57:11 -07:00
parent 5505deb1c9
commit ffc4d56918
6 changed files with 132 additions and 31 deletions

View file

@ -2,6 +2,8 @@
"use strict";
const os = require("os");
const path = require("path");
const test = require("ava").default;
const helpers = require("../helpers");
@ -1303,3 +1305,33 @@ test("htmlElementRanges", (t) => {
const actual = helpers.htmlElementRanges(params, lineMetadata);
t.deepEqual(actual, expected);
});
test("expandTildePath", (t) => {
t.plan(16);
const homedir = os.homedir();
t.is(helpers.expandTildePath("", os), "");
t.is(helpers.expandTildePath("", null), "");
t.is(
path.resolve(helpers.expandTildePath("~", os)),
homedir
);
t.is(helpers.expandTildePath("~", null), "~");
t.is(helpers.expandTildePath("file", os), "file");
t.is(helpers.expandTildePath("file", null), "file");
t.is(helpers.expandTildePath("/file", os), "/file");
t.is(helpers.expandTildePath("/file", null), "/file");
t.is(
path.resolve(helpers.expandTildePath("~/file", os)),
path.join(homedir, "/file")
);
t.is(helpers.expandTildePath("~/file", null), "~/file");
t.is(helpers.expandTildePath("dir/file", os), "dir/file");
t.is(helpers.expandTildePath("dir/file", null), "dir/file");
t.is(helpers.expandTildePath("/dir/file", os), "/dir/file");
t.is(helpers.expandTildePath("/dir/file", null), "/dir/file");
t.is(
path.resolve(helpers.expandTildePath("~/dir/file", os)),
path.join(homedir, "/dir/file")
);
t.is(helpers.expandTildePath("~/dir/file", null), "~/dir/file");
});