|
1 | 1 | import assert from "node:assert";
|
2 |
| -import {isPathImport, parseRelativeUrl, relativePath, resolveLocalPath, resolvePath} from "../src/path.js"; |
| 2 | +import {isPathImport, parseRelativeUrl, relativePath, resolveLocalPath, resolvePath, within} from "../src/path.js"; |
3 | 3 |
|
4 | 4 | describe("resolvePath(source, target)", () => {
|
5 | 5 | it("returns the path to the specified target within the source root", () => {
|
@@ -151,3 +151,21 @@ describe("parseRelativeUrl(url)", () => {
|
151 | 151 | assert.deepStrictEqual(parseRelativeUrl("foo?bar#baz"), {pathname: "foo", search: "?bar", hash: "#baz"});
|
152 | 152 | });
|
153 | 153 | });
|
| 154 | + |
| 155 | +describe("within(root, path)", () => { |
| 156 | + it("returns true for paths within the current working directory", () => { |
| 157 | + assert.strictEqual(within(process.cwd(), "dist"), true, "dist"); |
| 158 | + assert.strictEqual(within(process.cwd(), "./dist"), true, "./dist"); |
| 159 | + assert.strictEqual(within(process.cwd(), "dist/"), true, "dist/"); |
| 160 | + assert.strictEqual(within(process.cwd(), "./dist/"), true, "./dist/"); |
| 161 | + assert.strictEqual(within(process.cwd(), "foo/../dist"), true, "foo/../dist"); |
| 162 | + assert.strictEqual(within(process.cwd(), "foo/../dist/"), true, "foo/../dist/"); |
| 163 | + assert.strictEqual(within(process.cwd(), "./foo/../dist/"), true, "./foo/../dist/"); |
| 164 | + assert.strictEqual(within(process.cwd(), "foo/bar"), true, "foo/bar"); |
| 165 | + assert.strictEqual(within(process.cwd(), "foo/bar"), true, "foo/bar"); |
| 166 | + assert.strictEqual(within(process.cwd(), "../framework/dist"), true, "../framework/dist"); |
| 167 | + assert.strictEqual(within(process.cwd(), "../framework2/dist"), false, "../framework2/dist"); |
| 168 | + assert.strictEqual(within(process.cwd(), "../dist"), false, "../dist"); |
| 169 | + assert.strictEqual(within(process.cwd(), "/dist"), false, "/dist"); |
| 170 | + }); |
| 171 | +}); |
0 commit comments