diff --git a/.changeset/chubby-peas-sit.md b/.changeset/chubby-peas-sit.md new file mode 100644 index 00000000..8fb7cf45 --- /dev/null +++ b/.changeset/chubby-peas-sit.md @@ -0,0 +1,5 @@ +--- +"@nodesecure/js-x-ray": patch +--- + +Add unit tests for stripNodePrefix utility. diff --git a/workspaces/js-x-ray/test/utils/stripNodePrefix.spec.ts b/workspaces/js-x-ray/test/utils/stripNodePrefix.spec.ts new file mode 100644 index 00000000..271b06b6 --- /dev/null +++ b/workspaces/js-x-ray/test/utils/stripNodePrefix.spec.ts @@ -0,0 +1,39 @@ +// Import Node.js Dependencies +import assert from "node:assert"; +import { describe, it } from "node:test"; + +// Import Internal Dependencies +import { stripNodePrefix } from "../../src/utils/index.ts"; + +describe("stripNodePrefix", () => { + it("should remove 'node:' prefix from module name", () => { + assert.strictEqual(stripNodePrefix("node:fs"), "fs"); + assert.strictEqual(stripNodePrefix("node:path"), "path"); + }); + + it("should return the value unchanged if no prefix is present", () => { + assert.strictEqual(stripNodePrefix("fs"), "fs"); + assert.strictEqual(stripNodePrefix("http"), "http"); + }); + + it("should not modify similar but invalid prefixes", () => { + assert.strictEqual(stripNodePrefix("nod:fs"), "nod:fs"); + }); + + it("should only remove prefix at the beginning", () => { + assert.strictEqual(stripNodePrefix("my-node:fs"), "my-node:fs"); + }); + + it("should handle empty string", () => { + assert.strictEqual(stripNodePrefix(""), ""); + }); + + it("should return non-string values unchanged", () => { + assert.strictEqual(stripNodePrefix(123), 123); + assert.strictEqual(stripNodePrefix(null), null); + assert.strictEqual(stripNodePrefix(undefined), undefined); + + const obj = { key: "value" }; + assert.strictEqual(stripNodePrefix(obj), obj); + }); +});