Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ describe("node-version", () => {
expect(typeof v.build).toBe("string");
});

test("object should have exactly 14 properties", () => {
expect(Object.keys(version)).toHaveLength(14);
expect(Object.keys(getVersion())).toHaveLength(14);
test("object should have exactly 15 properties", () => {
expect(Object.keys(version)).toHaveLength(15);
expect(Object.keys(getVersion())).toHaveLength(15);
});

test("original property should start with v", () => {
Expand Down Expand Up @@ -135,6 +135,11 @@ describe("node-version", () => {
expect(version.long).toBe(version.original.slice(1));
});

test("toString should return original version", () => {
expect(version.toString()).toBe(version.original);
expect(String(version)).toBe(version.original);
});

describe("robustness", () => {
test("should handle malformed version string", () => {
mockVersion.node = "10";
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const getVersion = (): NodeVersion => {
isLTS: !!release.lts,
ltsName: String(release.lts || "") || undefined,
isEOL: checkEOL(split[0] || "0"),
toString: () => `v${nodeVersion}`,
};
};

Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ export interface NodeVersion {
* Check if the current version is considered End-of-Life (EOL).
*/
isEOL: boolean;
/**
* Returns the original version string.
*/
toString(): string;
}