UNPKG

cli-block

Version:
130 lines 7.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lines_1 = require("./lines"); const util_1 = require("../util"); // Mock the logger function jest.mock("../util", () => (Object.assign(Object.assign({}, jest.requireActual("../util")), { logger: jest.fn(), green: (text) => `[green]${text}[/green]`, red: (text) => `[red]${text}[/red]`, yellow: (text) => `[yellow]${text}[/yellow]`, blue: (text) => `[blue]${text}[/blue]`, spaces: jest.requireActual("../util").spaces, breakText: jest.requireActual("../util").breakText }))); describe("Line Module Tests", () => { beforeEach(() => { jest.clearAllMocks(); }); describe("Standard Line Functions", () => { it("success should log message with green checkmark", () => { (0, lines_1.success)("Test success"); expect(util_1.logger).toHaveBeenCalledWith("[green]✔[/green] Test success", {}); }); it("error should log message with red X", () => { (0, lines_1.error)("Test error"); expect(util_1.logger).toHaveBeenCalledWith("[red]×[/red] Test error", {}); }); it("warn should log message with yellow exclamation", () => { (0, lines_1.warn)("Test warning"); expect(util_1.logger).toHaveBeenCalledWith("[yellow]![/yellow] Test warning", {}); }); it("info should log message without prefix", () => { (0, lines_1.info)("Test info"); expect(util_1.logger).toHaveBeenCalledWith("[blue]i[/blue] Test info", {}); }); it("should handle array of messages", () => { (0, lines_1.success)(["Line 1", "Line 2"]); expect(util_1.logger).toHaveBeenCalledWith("[green]✔[/green] Line 1", {}); expect(util_1.logger).toHaveBeenCalledWith(" Line 2", {}); }); }); describe("Block Line Functions", () => { it("blockSuccess should log message with green checkmark in block style", () => { (0, lines_1.blockSuccess)("Test block success"); expect(util_1.logger).toHaveBeenCalledWith("[green]✔[/green] Test block success", { useBlock: true }); }); it("blockError should log message with red X in block style", () => { (0, lines_1.blockError)("Test block error"); expect(util_1.logger).toHaveBeenCalledWith("[red]×[/red] Test block error", { useBlock: true }); }); it("blockWarn should log message with yellow exclamation in block style", () => { (0, lines_1.blockWarn)("Test block warning"); expect(util_1.logger).toHaveBeenCalledWith("[yellow]![/yellow] Test block warning", { useBlock: true }); }); it("blockInfo should log message without prefix in block style", () => { (0, lines_1.blockInfo)("Test block info"); expect(util_1.logger).toHaveBeenCalledWith("[blue]i[/blue] Test block info", { useBlock: true }); }); it("should handle array of messages in block style", () => { (0, lines_1.blockSuccess)(["Block Line 1", "Block Line 2"]); expect(util_1.logger).toHaveBeenCalledWith("[green]✔[/green] Block Line 1", { useBlock: true }); expect(util_1.logger).toHaveBeenCalledWith(" Block Line 2", { useBlock: true }); }); }); describe("File Function", () => { beforeEach(() => { jest.clearAllMocks(); }); it("should handle a single file path with programming language extension", () => { (0, lines_1.file)("test.ts"); expect(util_1.logger).toHaveBeenCalledWith("📜 test.ts", expect.any(Object)); (0, lines_1.file)("script.py"); expect(util_1.logger).toHaveBeenCalledWith("🐍 script.py", expect.any(Object)); (0, lines_1.file)("app.js"); expect(util_1.logger).toHaveBeenCalledWith("📜 app.js", expect.any(Object)); }); it("should handle document file types", () => { (0, lines_1.file)("document.md"); expect(util_1.logger).toHaveBeenCalledWith("📝 document.md", expect.any(Object)); (0, lines_1.file)("report.pdf"); expect(util_1.logger).toHaveBeenCalledWith("📕 report.pdf", expect.any(Object)); (0, lines_1.file)("notes.txt"); expect(util_1.logger).toHaveBeenCalledWith("📄 notes.txt", expect.any(Object)); }); it("should handle media file types", () => { (0, lines_1.file)("image.png"); expect(util_1.logger).toHaveBeenCalledWith("🖼 image.png", expect.any(Object)); (0, lines_1.file)("video.mp4"); expect(util_1.logger).toHaveBeenCalledWith("🎥 video.mp4", expect.any(Object)); (0, lines_1.file)("audio.mp3"); expect(util_1.logger).toHaveBeenCalledWith("🎵 audio.mp3", expect.any(Object)); }); it("should handle archive file types", () => { (0, lines_1.file)("archive.zip"); expect(util_1.logger).toHaveBeenCalledWith("📦 archive.zip", expect.any(Object)); (0, lines_1.file)("backup.tar.gz"); expect(util_1.logger).toHaveBeenCalledWith("📦 backup.tar.gz", expect.any(Object)); }); it("should handle multiple file paths with different extensions", () => { (0, lines_1.file)(["app.js", "doc.pdf", "image.png"]); expect(util_1.logger).toHaveBeenCalledTimes(3); expect(util_1.logger).toHaveBeenNthCalledWith(1, "📜 app.js", expect.any(Object)); expect(util_1.logger).toHaveBeenNthCalledWith(2, "📕 doc.pdf", expect.any(Object)); expect(util_1.logger).toHaveBeenNthCalledWith(3, "🖼 image.png", expect.any(Object)); }); it("should handle files without extension", () => { (0, lines_1.file)("README"); expect(util_1.logger).toHaveBeenCalledWith("📄 README", expect.any(Object)); }); it("should respect pathDepth option", () => { (0, lines_1.file)("path/to/deep/file.ts", { pathDepth: 2 }); expect(util_1.logger).toHaveBeenCalledWith("📜 deep/file.ts", expect.any(Object)); }); it("should not modify path when pathDepth is greater than path segments", () => { (0, lines_1.file)("shallow/file.ts", { pathDepth: 5 }); expect(util_1.logger).toHaveBeenCalledWith("📜 shallow/file.ts", expect.any(Object)); }); it("should handle pathDepth of 0 or undefined", () => { const fullPath = "very/deep/path/structure/file.ts"; (0, lines_1.file)(fullPath, { pathDepth: 0 }); expect(util_1.logger).toHaveBeenCalledWith("📜 very/deep/path/structure/file.ts", expect.any(Object)); (0, lines_1.file)(fullPath); expect(util_1.logger).toHaveBeenCalledWith("📜 very/deep/path/structure/file.ts", expect.any(Object)); }); }); describe("Line Options Handling", () => { it("should respect custom options", () => { const customOptions = { indent: 2, useBlock: false }; (0, lines_1.success)("Test with options", { indent: 2, useBlock: false, }); expect(util_1.logger).toHaveBeenCalledWith(" [green]✔[/green] Test with options", customOptions); }); it("should handle null message", () => { (0, lines_1.info)(null); expect(util_1.logger).toHaveBeenCalledWith("", {}); }); }); }); //# sourceMappingURL=lines.test.js.map