- Created core modules: `ai-analyzer`, `core-parser`, and `job-search-parser`. - Implemented LinkedIn and job search parsers with integrated AI analysis. - Added CLI tools for AI analysis and job parsing. - Included comprehensive README files for each module detailing usage and features. - Established a `.gitignore` file to exclude unnecessary files. - Introduced sample data for testing and demonstration purposes. - Set up package.json files for dependency management across modules. - Implemented logging and error handling utilities for better debugging and user feedback.
195 lines
6.0 KiB
JavaScript
195 lines
6.0 KiB
JavaScript
/**
|
|
* Test file for logger functionality
|
|
*/
|
|
|
|
const { Logger, logger } = require("../src/logger");
|
|
|
|
describe("Logger", () => {
|
|
let consoleSpy;
|
|
let consoleWarnSpy;
|
|
let consoleErrorSpy;
|
|
|
|
beforeEach(() => {
|
|
consoleSpy = jest.spyOn(console, "log").mockImplementation();
|
|
consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation();
|
|
consoleErrorSpy = jest.spyOn(console, "error").mockImplementation();
|
|
});
|
|
|
|
afterEach(() => {
|
|
consoleSpy.mockRestore();
|
|
consoleWarnSpy.mockRestore();
|
|
consoleErrorSpy.mockRestore();
|
|
});
|
|
|
|
test("should create default logger instance", () => {
|
|
expect(logger).toBeDefined();
|
|
expect(logger).toBeInstanceOf(Logger);
|
|
});
|
|
|
|
test("should log info messages", () => {
|
|
logger.info("Test message");
|
|
expect(consoleSpy).toHaveBeenCalled();
|
|
});
|
|
|
|
test("should create custom logger with disabled levels", () => {
|
|
const customLogger = new Logger({ debug: false });
|
|
customLogger.debug("This should not log");
|
|
expect(consoleSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test("should use emoji prefixes for convenience methods", () => {
|
|
logger.step("Test step");
|
|
logger.ai("Test AI");
|
|
logger.location("Test location");
|
|
expect(consoleSpy).toHaveBeenCalledTimes(3);
|
|
});
|
|
|
|
test("should configure levels at runtime", () => {
|
|
const customLogger = new Logger();
|
|
customLogger.setLevel("debug", false);
|
|
customLogger.debug("This should not log");
|
|
expect(consoleSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test("should go silent when requested", () => {
|
|
const customLogger = new Logger();
|
|
customLogger.silent();
|
|
customLogger.info("This should not log");
|
|
customLogger.error("This should not log");
|
|
expect(consoleSpy).not.toHaveBeenCalled();
|
|
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
// Additional test cases for comprehensive coverage
|
|
|
|
test("should log warning messages", () => {
|
|
logger.warning("Test warning");
|
|
expect(consoleWarnSpy).toHaveBeenCalled();
|
|
});
|
|
|
|
test("should log error messages", () => {
|
|
logger.error("Test error");
|
|
expect(consoleErrorSpy).toHaveBeenCalled();
|
|
});
|
|
|
|
test("should log success messages", () => {
|
|
logger.success("Test success");
|
|
expect(consoleSpy).toHaveBeenCalled();
|
|
});
|
|
|
|
test("should log debug messages", () => {
|
|
logger.debug("Test debug");
|
|
expect(consoleSpy).toHaveBeenCalled();
|
|
});
|
|
|
|
test("should respect disabled warning level", () => {
|
|
const customLogger = new Logger({ warning: false });
|
|
customLogger.warning("This should not log");
|
|
expect(consoleWarnSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test("should respect disabled error level", () => {
|
|
const customLogger = new Logger({ error: false });
|
|
customLogger.error("This should not log");
|
|
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test("should respect disabled success level", () => {
|
|
const customLogger = new Logger({ success: false });
|
|
customLogger.success("This should not log");
|
|
expect(consoleSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test("should respect disabled info level", () => {
|
|
const customLogger = new Logger({ info: false });
|
|
customLogger.info("This should not log");
|
|
expect(consoleSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test("should test all convenience methods", () => {
|
|
logger.step("Test step");
|
|
logger.search("Test search");
|
|
logger.ai("Test AI");
|
|
logger.location("Test location");
|
|
logger.file("Test file");
|
|
expect(consoleSpy).toHaveBeenCalledTimes(5);
|
|
});
|
|
|
|
test("should enable all levels with verbose method", () => {
|
|
const customLogger = new Logger({ debug: false, info: false });
|
|
customLogger.verbose();
|
|
customLogger.debug("This should log");
|
|
customLogger.info("This should log");
|
|
expect(consoleSpy).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
test("should handle setLevel with invalid level gracefully", () => {
|
|
const customLogger = new Logger();
|
|
expect(() => {
|
|
customLogger.setLevel("invalid", false);
|
|
}).not.toThrow();
|
|
});
|
|
|
|
test("should format messages with timestamps", () => {
|
|
logger.info("Test message");
|
|
const loggedMessage = consoleSpy.mock.calls[0][0];
|
|
expect(loggedMessage).toMatch(/\[\d{1,2}:\d{2}:\d{2}\]/);
|
|
});
|
|
|
|
test("should include level in formatted messages", () => {
|
|
logger.info("Test message");
|
|
const loggedMessage = consoleSpy.mock.calls[0][0];
|
|
expect(loggedMessage).toContain("[INFO]");
|
|
});
|
|
|
|
test("should disable colors when colors option is false", () => {
|
|
const customLogger = new Logger({ colors: false });
|
|
customLogger.info("Test message");
|
|
const loggedMessage = consoleSpy.mock.calls[0][0];
|
|
// Should not contain ANSI color codes
|
|
expect(loggedMessage).not.toMatch(/\u001b\[/);
|
|
});
|
|
|
|
test("should enable colors by default", () => {
|
|
logger.info("Test message");
|
|
const loggedMessage = consoleSpy.mock.calls[0][0];
|
|
// Should contain ANSI color codes
|
|
expect(loggedMessage).toMatch(/\u001b\[/);
|
|
});
|
|
|
|
test("should handle multiple level configurations", () => {
|
|
const customLogger = new Logger({
|
|
debug: false,
|
|
info: true,
|
|
warning: false,
|
|
error: true,
|
|
success: false,
|
|
});
|
|
|
|
customLogger.debug("Should not log");
|
|
customLogger.info("Should log");
|
|
customLogger.warning("Should not log");
|
|
customLogger.error("Should log");
|
|
customLogger.success("Should not log");
|
|
|
|
expect(consoleSpy).toHaveBeenCalledTimes(1);
|
|
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
|
|
expect(consoleWarnSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test("should handle empty or undefined messages", () => {
|
|
expect(() => {
|
|
logger.info("");
|
|
logger.info(undefined);
|
|
logger.info(null);
|
|
}).not.toThrow();
|
|
});
|
|
|
|
test("should handle complex message objects", () => {
|
|
const testObj = { key: "value", nested: { data: "test" } };
|
|
expect(() => {
|
|
logger.info(testObj);
|
|
}).not.toThrow();
|
|
});
|
|
});
|