compose-action/src/index.test.ts
dependabot[bot] 5a56211d04
Some checks failed
Internal - Main - Continuous Integration / ci (push) Has been cancelled
Need fix to Issue / main (push) Has been cancelled
Prepare release / release (push) Has been cancelled
Internal - Main - Continuous Integration / prepare-docs (push) Has been cancelled
Internal - Main - Continuous Integration / sync-docs (push) Has been cancelled
Mark stale issues and pull requests / main (push) Has been cancelled
chore(deps-dev): bump the npm-development-dependencies group across 1 directory with 2 updates
Bumps the npm-development-dependencies group with 2 updates in the / directory:
- [@ts-dev-tools/core](https://github.com/escemi-tech/ts-dev-tools)
- [eslint-plugin-jsonc](https://github.com/ota-meshi/eslint-plugin-jsonc)

Updates `@ts-dev-tools/core` from 1.10.0 to 1.11.1
- [Release notes](https://github.com/escemi-tech/ts-dev-tools/releases)

Updates `eslint-plugin-jsonc` from 2.21.1 to 3.1.1
- [Release notes](https://github.com/ota-meshi/eslint-plugin-jsonc/releases)
- [Changelog](https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/CHANGELOG.md)

---
updated-dependencies:
- dependency-name: "@ts-dev-tools/core"
  dependency-version: 1.11.1
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm-development-dependencies
- dependency-name: eslint-plugin-jsonc
  dependency-version: 3.1.1
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: npm-development-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
2026-03-05 11:20:58 +01:00

110 lines
3.7 KiB
TypeScript

import { jest, describe, it, expect, beforeEach } from "@jest/globals";
// Mock @actions/core
const setFailedMock = jest.fn();
jest.unstable_mockModule("@actions/core", () => ({
setFailed: setFailedMock,
getInput: jest.fn().mockReturnValue(""),
getMultilineInput: jest.fn().mockReturnValue([]),
debug: jest.fn(),
info: jest.fn(),
warning: jest.fn(),
}));
// Mock docker-compose
jest.unstable_mockModule("docker-compose", () => ({
upAll: jest.fn(),
upMany: jest.fn(),
down: jest.fn(),
logs: jest.fn(),
version: jest
.fn<() => Promise<{ data: { version: string } }>>()
.mockResolvedValue({ data: { version: "1.2.3" } }),
}));
// Mock node:fs
jest.unstable_mockModule("node:fs", async () => {
const actualFs = await jest.requireActual<typeof import("node:fs")>("node:fs");
return {
...actualFs,
existsSync: jest.fn().mockReturnValue(true),
default: {
...actualFs,
existsSync: jest.fn().mockReturnValue(true),
},
};
});
// Dynamic imports after mock setup
const { InputService } = await import("./services/input.service.js");
const { LoggerService, LogLevel } = await import("./services/logger.service.js");
const { DockerComposeInstallerService } =
await import("./services/docker-compose-installer.service.js");
const { DockerComposeService } = await import("./services/docker-compose.service.js");
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
let debugMock: jest.SpiedFunction<typeof LoggerService.prototype.debug>;
let infoMock: jest.SpiedFunction<typeof LoggerService.prototype.info>;
let installMock: jest.SpiedFunction<typeof DockerComposeInstallerService.prototype.install>;
let upMock: jest.SpiedFunction<typeof DockerComposeService.prototype.up>;
describe("index", () => {
beforeEach(() => {
jest.clearAllMocks();
infoMock = jest.spyOn(LoggerService.prototype, "info").mockImplementation(() => {});
debugMock = jest.spyOn(LoggerService.prototype, "debug").mockImplementation(() => {});
getInputsMock = jest.spyOn(InputService.prototype, "getInputs");
installMock = jest.spyOn(DockerComposeInstallerService.prototype, "install");
upMock = jest.spyOn(DockerComposeService.prototype, "up");
});
it("calls run when imported", async () => {
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
downFlags: [],
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
installMock.mockResolvedValue("1.2.3");
upMock.mockResolvedValueOnce();
await import("./index.js");
await new Promise((resolve) => setTimeout(resolve, 0));
expect(infoMock).toHaveBeenNthCalledWith(1, "Setting up docker compose");
expect(infoMock).toHaveBeenNthCalledWith(2, "docker compose version: 1.2.3");
// Verify that all of the functions were called correctly
expect(debugMock).toHaveBeenNthCalledWith(
1,
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":null,"githubToken":null,"serviceLogLevel":"debug"}'
);
expect(infoMock).toHaveBeenNthCalledWith(3, "Bringing up docker compose service(s)");
expect(upMock).toHaveBeenCalledWith({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
serviceLogger: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();
expect(infoMock).toHaveBeenNthCalledWith(4, "docker compose service(s) are up");
});
});