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
5 changes: 5 additions & 0 deletions .changeset/chubby-peas-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/js-x-ray": patch
---

Add unit tests for stripNodePrefix utility.
39 changes: 39 additions & 0 deletions workspaces/js-x-ray/test/utils/stripNodePrefix.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});