-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathbuild-cmd.test.ts
More file actions
200 lines (177 loc) · 6.23 KB
/
build-cmd.test.ts
File metadata and controls
200 lines (177 loc) · 6.23 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import { PackageJson, Version, buildJsrConf, getVersion, patchPackageJson } from "./build-cmd.js";
import { expect, it } from "vitest";
const mock = {
readJSON: (): Promise<PackageJson> => {
return Promise.resolve({
name: "@fireproof/core-cli",
version: "0.0.0",
description: "Live ledger for the web.",
type: "module",
keywords: ["ledger", "JSON", "document", "IPLD", "CID", "IPFS"],
contributors: ["J Chris Anderson", "Alan Shaw", "Travis Vachon", "Mikeal Rogers", "Meno Abels"],
author: "J Chris Anderson",
license: "AFL-2.0",
scripts: {
build: "core-cli tsc",
pack: "core-cli build --doPack",
publish: "core-cli build",
},
dependencies: {
"@fireproof/vendor": "workspace:0.0.0",
"cmd-ts": "^0.13.0",
},
devDependencies: {
"@fireproof/core-cli": "workspace:0.0.0",
vitest: "^3.2.4",
},
exports: {
".": "./index.js",
},
});
},
};
it("getVersion emptyString", async () => {
expect(await getVersion("", { xenv: {} })).toContain("0.0.0-smoke");
});
it("should only use prefix version in dependencies", async () => {
const version = new Version("0.0.0-smoke", "^");
const { patchedPackageJson } = await patchPackageJson("package.json", version, undefined, mock);
expect(patchedPackageJson.version).toBe("0.0.0-smoke");
expect(patchedPackageJson.dependencies).toHaveProperty("@fireproof/vendor", "^0.0.0-smoke");
});
it("should only use prefix version in dependencies", async () => {
const version = new Version("0.0.0-smoke", "^");
const { patchedPackageJson } = await patchPackageJson("package.json", version, undefined, mock);
expect(patchedPackageJson.version).toBe("0.0.0-smoke");
expect(patchedPackageJson.dependencies).toHaveProperty("@fireproof/vendor", "^0.0.0-smoke");
});
it("should only use prefix version in dependencies", async () => {
const version = new Version("0.0.0-smoke", "^");
const { patchedPackageJson } = await patchPackageJson("package.json", version, undefined, mock);
const originalPackageJson = await mock.readJSON();
const jsrConf = buildJsrConf({ originalPackageJson, patchedPackageJson }, version.prefixedVersion);
expect(jsrConf.version).toBe("0.0.0-smoke");
expect(jsrConf.imports).toHaveProperty("@fireproof/vendor", "jsr:@fireproof/vendor@^0.0.0-smoke");
});
it("ILLEGAL Version", async () => {
expect(
await getVersion(undefined, {
xenv: { GITHUB_REF: "a/b/cdkdkdkdk" },
}),
).toContain("0.0.0-smoke-");
});
it("ILLEGAL Version with gitref", async () => {
expect(
await getVersion("wo", {
xenv: { GITHUB_REF: "a/b/cdkdkdkdk" },
xfs: {
existsSync: () => false,
readFile: (_x: string, _y = "utf-8") => Promise.resolve(""),
},
}),
).toContain("0.0.0-smoke-");
});
it("GITHUB_REF set and file", async () => {
expect(
await getVersion("wurst", {
xenv: { GITHUB_REF: "a/b/cdkdkdkdk" },
xfs: {
existsSync: () => true,
readFile: (_x: string, _y = "utf-8") => Promise.resolve("v0.0.48-smoke"),
},
}),
).toBe("0.0.48-smoke");
});
it("GITHUB_REF set and not exist file", async () => {
expect(
await getVersion("wurst", {
xenv: { GITHUB_REF: "a/b/c0.0.45-xx" },
xfs: {
existsSync: () => false,
readFile: (_x: string, _y = "utf-8") => Promise.resolve("v0.0.48-smoke"),
},
}),
).toBe("0.0.45-xx");
});
it("getVersion file with v", async () => {
expect(
await getVersion("wurst", {
xfs: {
existsSync: () => true,
readFile: (_x: string, _y = "utf-8") => Promise.resolve("v0.0.48-smoke"),
},
xenv: {},
}),
).toContain("0.0.48-smoke");
});
it("getVersion file without ", async () => {
expect(
await getVersion("wurst", {
xfs: {
existsSync: () => true,
readFile: (_x: string, _y = "utf-8") => Promise.resolve("0.0.48-smoke"),
},
xenv: {},
}),
).toContain("0.0.48-smoke");
});
it("getVersion file with scope", async () => {
expect(
await getVersion("wurst", {
xfs: {
existsSync: () => true,
readFile: (_x: string, _y = "utf-8") => Promise.resolve("wost@0.0.48-smoke"),
},
xenv: {},
}),
).toContain("0.0.48-smoke");
});
it("getVersion file with scope and v", async () => {
expect(
await getVersion("wurst", {
xfs: {
existsSync: () => true,
readFile: (_x: string, _y = "utf-8") => Promise.resolve("wost@v0.0.48-smoke"),
},
xenv: {},
}),
).toContain("0.0.48-smoke");
});
it("getVersion file with ref", async () => {
expect(
await getVersion("wurst", {
xfs: {
existsSync: () => true,
readFile: (_x: string, _y = "utf-8") => Promise.resolve("d/d/wost@0.0.48-smoke"),
},
xenv: {},
}),
).toContain("0.0.48-smoke");
});
it("getVersion with v", async () => {
expect(await getVersion(undefined, { xenv: { GITHUB_REF: "v0.0.8-smoke" } })).toContain("0.0.8-smoke");
});
it("getVersion with scope and v", async () => {
expect(await getVersion(undefined, { xenv: { GITHUB_REF: "blub@v0.0.8-smoke" } })).toContain("0.0.8-smoke");
});
it("getVersion with scope and no v", async () => {
expect(await getVersion(undefined, { xenv: { GITHUB_REF: "blub@0.0.8-smoke" } })).toContain("0.0.8-smoke");
});
it("getVersion without", async () => {
expect(await getVersion(undefined, { xenv: { GITHUB_REF: "0.0.9-smoke" } })).toContain("0.0.9-smoke");
});
it("getVersion ref without", async () => {
expect(await getVersion(undefined, { xenv: { GITHUB_REF: "v0.0.9-smoke" } })).toContain("0.0.9-smoke");
});
it("getVersion ref with v", async () => {
expect(await getVersion(undefined, { xenv: { GITHUB_REF: "a/ref/v0.0.8-smoke" } })).toContain("0.0.8-smoke");
});
it("getVersion ref with scope and v", async () => {
expect(await getVersion(undefined, { xenv: { GITHUB_REF: "a/ref/blub@v0.0.8-smoke" } })).toContain("0.0.8-smoke");
});
it("getVersion ref with scope and no v", async () => {
expect(await getVersion(undefined, { xenv: { GITHUB_REF: "a/ref/blub@0.0.8-smoke" } })).toContain("0.0.8-smoke");
});
it("getVersion ref without", async () => {
expect(await getVersion(undefined, { xenv: { GITHUB_REF: "a/ref/0.0.9-smoke" } })).toContain("0.0.9-smoke");
});