From 1b7c8f67095ca56cf26a986c8981a2f9bc94e570 Mon Sep 17 00:00:00 2001 From: bashlor <39790502+bashlor@users.noreply.github.com> Date: Wed, 18 Feb 2026 15:54:49 +0100 Subject: [PATCH 1/3] test(utils): add unit tests for isMinifiedCode --- .../test/utils/isMinifiedCode.spec.ts | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 workspaces/js-x-ray/test/utils/isMinifiedCode.spec.ts diff --git a/workspaces/js-x-ray/test/utils/isMinifiedCode.spec.ts b/workspaces/js-x-ray/test/utils/isMinifiedCode.spec.ts new file mode 100644 index 00000000..1bfbc770 --- /dev/null +++ b/workspaces/js-x-ray/test/utils/isMinifiedCode.spec.ts @@ -0,0 +1,62 @@ +// Import Node.js Dependencies +import assert from "node:assert"; +import { describe, it } from "node:test"; + +// Import Internal Dependencies +import { isMinifiedCode } from "../../src/utils/index.ts"; +describe("isMinifiedCode", () => { + it("should return false for formatted multi-line code", () => { + const formattedCode = ` + function add(a, b) { + return a + b; + } + `; + assert.strictEqual(isMinifiedCode(formattedCode), false); + }); + + it("should return true for a single line code", () => { + const minifiedCode = "function add(a,b){return a+b;}"; + assert.strictEqual(isMinifiedCode(minifiedCode), true); + }); + + it("should return true when median line length exceeds 200", () => { + const longString = "a".repeat(250); + const code = ` +${longString} +${longString} +`; + assert.strictEqual(isMinifiedCode(code), true); + }); + + it("should ignore comments when evaluating minification", () => { + const code = ` + // this is a comment + function test() { + return 1; + } + `; + assert.strictEqual(isMinifiedCode(code), false); + }); + + it("should handle empty code as minified", () => { + assert.strictEqual(isMinifiedCode(""), true); + }); + + it("should treat comment-only code as minified", () => { + const code = ` +// comment +/* block comment */ +`; + assert.strictEqual(isMinifiedCode(code), true); + }); + + it("should not be affected by a single long line", () => { + const longLine = "a".repeat(250); + const code = ` +short line +${longLine} +short line +`; + assert.strictEqual(isMinifiedCode(code), false); + }); +}); From 1f17f7b7f3e54c0a41885f76e0b107a2226df8ba Mon Sep 17 00:00:00 2001 From: bashlor <39790502+bashlor@users.noreply.github.com> Date: Thu, 19 Feb 2026 12:00:48 +0100 Subject: [PATCH 2/3] chore: add changeset for isMinifiedCode tests --- .changeset/sunny-kiwis-fix.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sunny-kiwis-fix.md diff --git a/.changeset/sunny-kiwis-fix.md b/.changeset/sunny-kiwis-fix.md new file mode 100644 index 00000000..188ec725 --- /dev/null +++ b/.changeset/sunny-kiwis-fix.md @@ -0,0 +1,5 @@ +--- +"@nodesecure/js-x-ray": patch +--- + +Add unit tests for isMinifiedCode utility. From 12fad888eba757254d8fe5dc8c8ab2d810405866 Mon Sep 17 00:00:00 2001 From: Elie Patrice <39790502+bashlor@users.noreply.github.com> Date: Thu, 19 Feb 2026 12:16:37 +0100 Subject: [PATCH 3/3] style: Update workspaces/js-x-ray/test/utils/isMinifiedCode.spec.ts Co-authored-by: PierreDemailly <39910767+PierreDemailly@users.noreply.github.com> --- workspaces/js-x-ray/test/utils/isMinifiedCode.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/workspaces/js-x-ray/test/utils/isMinifiedCode.spec.ts b/workspaces/js-x-ray/test/utils/isMinifiedCode.spec.ts index 1bfbc770..13742c19 100644 --- a/workspaces/js-x-ray/test/utils/isMinifiedCode.spec.ts +++ b/workspaces/js-x-ray/test/utils/isMinifiedCode.spec.ts @@ -4,6 +4,7 @@ import { describe, it } from "node:test"; // Import Internal Dependencies import { isMinifiedCode } from "../../src/utils/index.ts"; + describe("isMinifiedCode", () => { it("should return false for formatted multi-line code", () => { const formattedCode = `