@tkeron/commands 0.4.0 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -1,3 +1,17 @@
1
+ # v0.4.3
2
+
3
+ - fix: restore NODE_AUTH_TOKEN requirement for npm publish
4
+
5
+ # v0.4.2
6
+
7
+ - test: validate trusted publishing without NODE_AUTH_TOKEN
8
+ - fix: use correct repository format in package.json (type + HTTPS URL)
9
+
10
+ # v0.4.1
11
+
12
+ - add comprehensive test coverage for version command
13
+ - add publishConfig to package.json for npm publishing
14
+
1
15
  # v0.4.0
2
16
 
3
17
  - add standard CLI syntax support (`--flag`, `-f`, `--opt value`, `--opt=value`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tkeron/commands",
3
- "version": "0.4.0",
3
+ "version": "0.4.3",
4
4
  "description": "library for handling command line arguments",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -26,6 +26,7 @@
26
26
  "access": "public"
27
27
  },
28
28
  "repository": {
29
- "url": "git@github.com:tkeron/commands.git"
29
+ "type": "git",
30
+ "url": "https://github.com/tkeron/commands.git"
30
31
  }
31
32
  }
@@ -0,0 +1,292 @@
1
+ import {
2
+ describe,
3
+ it,
4
+ expect,
5
+ spyOn,
6
+ mock,
7
+ beforeEach,
8
+ afterEach,
9
+ } from "bun:test";
10
+ import { getCommands } from "../src/getCommandsFuncs.js";
11
+
12
+ describe("Version Command - Configuration", () => {
13
+ let logMock: any;
14
+ let logs: string[];
15
+
16
+ beforeEach(() => {
17
+ logs = [];
18
+ logMock = spyOn(console, "log").mockImplementation((...args: any[]) => {
19
+ logs.push(args.join(" "));
20
+ });
21
+ });
22
+
23
+ afterEach(() => {
24
+ logMock.mockRestore();
25
+ });
26
+
27
+ it("should display version when explicitly configured", () => {
28
+ const commands = getCommands("mycli", "1.2.3");
29
+ commands.start(["node", "app", "version"]);
30
+
31
+ expect(logs.length).toBeGreaterThan(0);
32
+ expect(logs.join("\n")).toContain("1.2.3");
33
+ });
34
+
35
+ it("should display version using -v alias", () => {
36
+ const commands = getCommands("mycli", "2.5.0");
37
+ commands.start(["node", "app", "-v"]);
38
+
39
+ expect(logs.length).toBeGreaterThan(0);
40
+ expect(logs.join("\n")).toContain("2.5.0");
41
+ });
42
+
43
+ it("should display version using --version alias", () => {
44
+ const commands = getCommands("mycli", "3.0.1");
45
+ commands.start(["node", "app", "--version"]);
46
+
47
+ expect(logs.length).toBeGreaterThan(0);
48
+ expect(logs.join("\n")).toContain("3.0.1");
49
+ });
50
+
51
+ it("should use default version 0.0.1 when version not provided", () => {
52
+ const commands = getCommands("mycli");
53
+ commands.start(["node", "app", "version"]);
54
+
55
+ expect(logs.length).toBeGreaterThan(0);
56
+ expect(logs.join("\n")).toContain("0.0.1");
57
+ });
58
+
59
+ it("should use default version when only programName provided", () => {
60
+ const commands = getCommands("myapp");
61
+ commands.start(["node", "app", "-v"]);
62
+
63
+ expect(logs.length).toBeGreaterThan(0);
64
+ expect(logs.join("\n")).toContain("0.0.1");
65
+ });
66
+
67
+ it("should use default version when no parameters provided", () => {
68
+ const commands = getCommands();
69
+ commands.start(["node", "app", "version"]);
70
+
71
+ expect(logs.length).toBeGreaterThan(0);
72
+ expect(logs.join("\n")).toContain("0.0.1");
73
+ });
74
+ });
75
+
76
+ describe("Version Command - Display Format", () => {
77
+ let logMock: any;
78
+ let logs: string[];
79
+
80
+ beforeEach(() => {
81
+ logs = [];
82
+ logMock = spyOn(console, "log").mockImplementation((...args: any[]) => {
83
+ logs.push(args.join(" "));
84
+ });
85
+ });
86
+
87
+ afterEach(() => {
88
+ logMock.mockRestore();
89
+ });
90
+
91
+ it("should display version with header text when configured", () => {
92
+ const commands = getCommands("mycli", "1.0.0");
93
+ commands.addHeaderText("My CLI Tool v1.0.0");
94
+ commands.start(["node", "app", "version"]);
95
+
96
+ const output = logs.join("\n");
97
+ expect(output).toContain("My CLI Tool v1.0.0");
98
+ expect(output).toContain("1.0.0");
99
+ });
100
+
101
+ it("should display version with footer text when configured", () => {
102
+ const commands = getCommands("mycli", "2.0.0");
103
+ commands.addFooterText("For more info: https://example.com");
104
+ commands.start(["node", "app", "version"]);
105
+
106
+ const output = logs.join("\n");
107
+ expect(output).toContain("2.0.0");
108
+ expect(output).toContain("For more info: https://example.com");
109
+ });
110
+
111
+ it("should display version with both header and footer", () => {
112
+ const commands = getCommands("mycli", "3.5.2");
113
+ commands.addHeaderText("Welcome to MyCLI");
114
+ commands.addFooterText("Documentation: docs.example.com");
115
+ commands.start(["node", "app", "version"]);
116
+
117
+ const output = logs.join("\n");
118
+ expect(output).toContain("Welcome to MyCLI");
119
+ expect(output).toContain("3.5.2");
120
+ expect(output).toContain("Documentation: docs.example.com");
121
+ });
122
+
123
+ it("should display only version when no header or footer", () => {
124
+ const commands = getCommands("mycli", "1.5.0");
125
+ commands.start(["node", "app", "version"]);
126
+
127
+ const output = logs.join("\n");
128
+ expect(output).toContain("1.5.0");
129
+ });
130
+ });
131
+
132
+ describe("Version Command - Edge Cases", () => {
133
+ let logMock: any;
134
+ let logs: string[];
135
+
136
+ beforeEach(() => {
137
+ logs = [];
138
+ logMock = spyOn(console, "log").mockImplementation((...args: any[]) => {
139
+ logs.push(args.join(" "));
140
+ });
141
+ });
142
+
143
+ afterEach(() => {
144
+ logMock.mockRestore();
145
+ });
146
+
147
+ it("should handle empty string version", () => {
148
+ const commands = getCommands("mycli", "");
149
+ commands.start(["node", "app", "version"]);
150
+
151
+ expect(logs.length).toBeGreaterThan(0);
152
+ });
153
+
154
+ it("should handle pre-release versions", () => {
155
+ const commands = getCommands("mycli", "1.0.0-alpha.1");
156
+ commands.start(["node", "app", "version"]);
157
+
158
+ expect(logs.join("\n")).toContain("1.0.0-alpha.1");
159
+ });
160
+
161
+ it("should handle beta versions", () => {
162
+ const commands = getCommands("mycli", "2.0.0-beta.5");
163
+ commands.start(["node", "app", "version"]);
164
+
165
+ expect(logs.join("\n")).toContain("2.0.0-beta.5");
166
+ });
167
+
168
+ it("should handle release candidate versions", () => {
169
+ const commands = getCommands("mycli", "1.5.0-rc.2");
170
+ commands.start(["node", "app", "version"]);
171
+
172
+ expect(logs.join("\n")).toContain("1.5.0-rc.2");
173
+ });
174
+
175
+ it("should handle non-semver version strings", () => {
176
+ const commands = getCommands("mycli", "v1.0");
177
+ commands.start(["node", "app", "version"]);
178
+
179
+ expect(logs.join("\n")).toContain("v1.0");
180
+ });
181
+
182
+ it("should handle very long version strings", () => {
183
+ const longVersion = "1.0.0-alpha.beta.gamma.delta.epsilon.1234567890";
184
+ const commands = getCommands("mycli", longVersion);
185
+ commands.start(["node", "app", "version"]);
186
+
187
+ expect(logs.join("\n")).toContain(longVersion);
188
+ });
189
+
190
+ it("should handle version with build metadata", () => {
191
+ const commands = getCommands("mycli", "1.0.0+build.2024.02.14");
192
+ commands.start(["node", "app", "version"]);
193
+
194
+ expect(logs.join("\n")).toContain("1.0.0+build.2024.02.14");
195
+ });
196
+ });
197
+
198
+ describe("Version Command - Multiple Invocations", () => {
199
+ let logMock: any;
200
+ let logs: string[];
201
+
202
+ beforeEach(() => {
203
+ logs = [];
204
+ logMock = spyOn(console, "log").mockImplementation((...args: any[]) => {
205
+ logs.push(args.join(" "));
206
+ });
207
+ });
208
+
209
+ afterEach(() => {
210
+ logMock.mockRestore();
211
+ logs = [];
212
+ });
213
+
214
+ it("should display correct version on multiple calls with version command", () => {
215
+ const commands = getCommands("mycli", "1.2.3");
216
+
217
+ commands.start(["node", "app", "version"]);
218
+ const firstOutput = logs.join("\n");
219
+ logs = [];
220
+
221
+ commands.start(["node", "app", "version"]);
222
+ const secondOutput = logs.join("\n");
223
+
224
+ expect(firstOutput).toContain("1.2.3");
225
+ expect(secondOutput).toContain("1.2.3");
226
+ });
227
+
228
+ it("should display correct version with different aliases", () => {
229
+ const commands = getCommands("mycli", "2.0.0");
230
+
231
+ commands.start(["node", "app", "version"]);
232
+ const versionOutput = logs.join("\n");
233
+ logs = [];
234
+
235
+ commands.start(["node", "app", "-v"]);
236
+ const dashVOutput = logs.join("\n");
237
+ logs = [];
238
+
239
+ commands.start(["node", "app", "--version"]);
240
+ const doubleDashOutput = logs.join("\n");
241
+
242
+ expect(versionOutput).toContain("2.0.0");
243
+ expect(dashVOutput).toContain("2.0.0");
244
+ expect(doubleDashOutput).toContain("2.0.0");
245
+ });
246
+ });
247
+
248
+ describe("Version Command - Integration with Commands", () => {
249
+ let logMock: any;
250
+ let logs: string[];
251
+
252
+ beforeEach(() => {
253
+ logs = [];
254
+ logMock = spyOn(console, "log").mockImplementation((...args: any[]) => {
255
+ logs.push(args.join(" "));
256
+ });
257
+ });
258
+
259
+ afterEach(() => {
260
+ logMock.mockRestore();
261
+ });
262
+
263
+ it("should not interfere with other commands", () => {
264
+ const callback = mock(() => {});
265
+ const commands = getCommands("mycli", "1.0.0");
266
+
267
+ commands
268
+ .addCommand("build")
269
+ .addDescription("Build the project")
270
+ .setCallback(callback);
271
+
272
+ commands.start(["node", "app", "build"]);
273
+ expect(callback).toBeCalledTimes(1);
274
+
275
+ commands.start(["node", "app", "version"]);
276
+ expect(logs.join("\n")).toContain("1.0.0");
277
+ });
278
+
279
+ it("should work alongside commands with -v flag", () => {
280
+ const callback = mock(() => {});
281
+ const commands = getCommands("mycli", "2.0.0");
282
+
283
+ commands
284
+ .addCommand("test")
285
+ .addFlag("verbose", "v", "Verbose output")
286
+ .setCallback(callback);
287
+
288
+ commands.start(["node", "app", "-v"]);
289
+ expect(logs.join("\n")).toContain("2.0.0");
290
+ expect(callback).not.toBeCalled();
291
+ });
292
+ });