Skip to content

Commit 0fb6c8c

Browse files
authored
test(utils): add unit tests for stripNodePrefixt (#537)
2 parents 6fdad4a + e536ba3 commit 0fb6c8c

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

.changeset/chubby-peas-sit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nodesecure/js-x-ray": patch
3+
---
4+
5+
Add unit tests for stripNodePrefix utility.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Import Node.js Dependencies
2+
import assert from "node:assert";
3+
import { describe, it } from "node:test";
4+
5+
// Import Internal Dependencies
6+
import { stripNodePrefix } from "../../src/utils/index.ts";
7+
8+
describe("stripNodePrefix", () => {
9+
it("should remove 'node:' prefix from module name", () => {
10+
assert.strictEqual(stripNodePrefix("node:fs"), "fs");
11+
assert.strictEqual(stripNodePrefix("node:path"), "path");
12+
});
13+
14+
it("should return the value unchanged if no prefix is present", () => {
15+
assert.strictEqual(stripNodePrefix("fs"), "fs");
16+
assert.strictEqual(stripNodePrefix("http"), "http");
17+
});
18+
19+
it("should not modify similar but invalid prefixes", () => {
20+
assert.strictEqual(stripNodePrefix("nod:fs"), "nod:fs");
21+
});
22+
23+
it("should only remove prefix at the beginning", () => {
24+
assert.strictEqual(stripNodePrefix("my-node:fs"), "my-node:fs");
25+
});
26+
27+
it("should handle empty string", () => {
28+
assert.strictEqual(stripNodePrefix(""), "");
29+
});
30+
31+
it("should return non-string values unchanged", () => {
32+
assert.strictEqual(stripNodePrefix(123), 123);
33+
assert.strictEqual(stripNodePrefix(null), null);
34+
assert.strictEqual(stripNodePrefix(undefined), undefined);
35+
36+
const obj = { key: "value" };
37+
assert.strictEqual(stripNodePrefix(obj), obj);
38+
});
39+
});

0 commit comments

Comments
 (0)