-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathutils.test.ts
112 lines (99 loc) · 3.66 KB
/
utils.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import * as assert from "assert/strict";
import * as path from "node:path";
import { runInTempDir } from "./test_utils";
import {
findProjectDir,
JsrPackage,
PkgJson,
writeJson,
writeTextFile,
} from "../src/utils";
describe("findProjectDir", () => {
it("should return npm if package-lock.json is found", async () => {
await runInTempDir(async (tempDir) => {
await writeTextFile(path.join(tempDir, "package-lock.json"), "{}");
const result = await findProjectDir(tempDir);
assert.strictEqual(result.pkgManagerName, "npm");
});
});
it("should return yarn if yarn.lock is found", async () => {
await runInTempDir(async (tempDir) => {
await writeTextFile(path.join(tempDir, "yarn.lock"), "");
const result = await findProjectDir(tempDir);
assert.strictEqual(result.pkgManagerName, "yarn");
});
});
it("should return pnpm if pnpm-lock.yaml is found", async () => {
await runInTempDir(async (tempDir) => {
await writeTextFile(path.join(tempDir, "pnpm-lock.yaml"), "");
const result = await findProjectDir(tempDir);
assert.strictEqual(result.pkgManagerName, "pnpm");
});
});
it("should return bun if bun.lockb is found", async () => {
await runInTempDir(async (tempDir) => {
await writeTextFile(path.join(tempDir, "bun.lockb"), "");
const result = await findProjectDir(tempDir);
assert.strictEqual(result.pkgManagerName, "bun");
});
});
it("should return bun if bun.lock is found", async () => {
await runInTempDir(async (tempDir) => {
await writeTextFile(path.join(tempDir, "bun.lock"), "");
const result = await findProjectDir(tempDir);
assert.strictEqual(result.pkgManagerName, "bun");
});
});
it("should return bun if bun.lockb and yarn.lock are found", async () => {
// bun allow to save bun.lockb and yarn.lock
// https://bun.sh/docs/install/lockfile
await runInTempDir(async (tempDir) => {
await writeTextFile(path.join(tempDir, "bun.lockb"), "");
await writeTextFile(path.join(tempDir, "yarn.lock"), "");
const result = await findProjectDir(tempDir);
assert.strictEqual(result.pkgManagerName, "bun");
});
});
it("should set project dir to nearest package.json", async () => {
await runInTempDir(async (tempDir) => {
const sub = path.join(tempDir, "sub");
await writeJson(path.join(tempDir, "package.json"), {});
await writeJson(path.join(sub, "package.json"), {});
const result = await findProjectDir(sub);
assert.strictEqual(result.projectDir, sub);
});
});
it("should find workspace root folder", async () => {
await runInTempDir(async (tempDir) => {
const sub = path.join(tempDir, "sub");
await writeJson<PkgJson>(path.join(tempDir, "package.json"), {
workspaces: ["sub"],
});
await writeJson(path.join(sub, "package.json"), {});
const result = await findProjectDir(sub);
assert.strictEqual(
result.root,
tempDir,
);
});
});
it("should find workspace root folder with pnpm workspaces", async () => {
await runInTempDir(async (tempDir) => {
const sub = path.join(tempDir, "sub");
await writeJson<PkgJson>(path.join(tempDir, "package.json"), {});
await writeJson(path.join(sub, "package.json"), {});
await writeTextFile(path.join(tempDir, "pnpm-workspace.yaml"), "");
const result = await findProjectDir(sub);
assert.strictEqual(
result.root,
tempDir,
);
});
});
});
describe("JsrPackage", () => {
it("should allow scopes starting with a number", () => {
JsrPackage.from("@0abc/foo");
JsrPackage.from("@jsr/0abc__foo");
});
});