compose-action/src/services/logger.service.test.ts
dependabot[bot] 2ab47e7e09 chore(deps): bump the npm-actions-dependencies group with 3 updates
Bumps the npm-actions-dependencies group with 3 updates:
- [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core)
- [@actions/github](https://github.com/actions/toolkit/tree/HEAD/packages/github)
- [@actions/tool-cache](https://github.com/actions/toolkit/tree/HEAD/packages/tool-cache)

Updates `@actions/core` from 2.0.2 to 3.0.0
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Updates `@actions/github` from 7.0.0 to 9.0.0
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/github/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/github)

Updates `@actions/tool-cache` from 3.0.0 to 4.0.0
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/tool-cache/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/@actions/cache@4.0.0/packages/tool-cache)

---
updated-dependencies:
- dependency-name: "@actions/core"
  dependency-version: 3.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: npm-actions-dependencies
- dependency-name: "@actions/github"
  dependency-version: 9.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: npm-actions-dependencies
- dependency-name: "@actions/tool-cache"
  dependency-version: 4.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: npm-actions-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
2026-01-31 15:27:34 +01:00

69 lines
2.1 KiB
TypeScript

import { jest, describe, it, expect, beforeEach } from "@jest/globals";
// Import types directly from the module
import type { LogLevel as LogLevelType } from "./logger.service.js";
// Mock @actions/core before importing the module under test
const warningMock = jest.fn();
const infoMock = jest.fn();
const debugMock = jest.fn();
jest.unstable_mockModule("@actions/core", () => ({
warning: warningMock,
info: infoMock,
debug: debugMock,
}));
// Dynamic import after mock setup
const { LoggerService, LogLevel } = await import("./logger.service.js");
describe("LoggerService", () => {
let loggerService: InstanceType<typeof LoggerService>;
beforeEach(() => {
jest.clearAllMocks();
loggerService = new LoggerService();
});
describe("warn", () => {
it("should call warning with the correct message", () => {
const message = "This is a warning message";
loggerService.warn(message);
expect(warningMock).toHaveBeenCalledWith(message);
});
});
describe("info", () => {
it("should call info with the correct message", () => {
const message = "This is an info message";
loggerService.info(message);
expect(infoMock).toHaveBeenCalledWith(message);
});
});
describe("debug", () => {
it("should call debug with the correct message", () => {
const message = "This is a debug message";
loggerService.debug(message);
expect(debugMock).toHaveBeenCalledWith(message);
});
});
describe("getServiceLogger", () => {
it("should return the correct logger function for debug level", () => {
const logger = loggerService.getServiceLogger(LogLevel.Debug);
expect(logger).toBe(loggerService.debug);
});
it("should return the correct logger function for info level", () => {
const logger = loggerService.getServiceLogger(LogLevel.Info);
expect(logger).toBe(loggerService.info);
});
it("should default to info level if an unknown level is provided", () => {
const logger = loggerService.getServiceLogger("unknown" as LogLevelType);
expect(logger).toBe(loggerService.info);
});
});
});