Reviewed-on: #89 Co-authored-by: Timo Behrendt <t.behrendt@t00n.de> Co-committed-by: Timo Behrendt <t.behrendt@t00n.de>
This commit was merged in pull request #89.
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
export const getInput = jest.fn(() => "");
|
||||
export const info = jest.fn();
|
||||
export const warning = jest.fn();
|
||||
export const setOutput = jest.fn();
|
||||
export const setFailed = jest.fn();
|
||||
+22
-22
@@ -1,28 +1,30 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi, type MockedFunction } from "vitest";
|
||||
|
||||
import {
|
||||
IncrementType,
|
||||
Tag,
|
||||
GitService,
|
||||
CoreService,
|
||||
ConventionalCommitAnalyzer,
|
||||
TagService,
|
||||
TagIncrementer,
|
||||
LocalGitService,
|
||||
CoreService,
|
||||
GitService,
|
||||
IncrementType,
|
||||
LocalCoreService,
|
||||
LocalGitService,
|
||||
Tag,
|
||||
TagIncrementer,
|
||||
TagService,
|
||||
} from "./main";
|
||||
|
||||
// Mock child_process.execSync
|
||||
jest.mock("child_process", () => ({
|
||||
execSync: jest.fn(),
|
||||
vi.mock("child_process", () => ({
|
||||
execSync: vi.fn(),
|
||||
}));
|
||||
|
||||
import { execSync } from "child_process";
|
||||
const mockExecSync = execSync as jest.MockedFunction<typeof execSync>;
|
||||
const mockExecSync = execSync as MockedFunction<typeof execSync>;
|
||||
|
||||
// Mock interfaces for testing
|
||||
class MockGitService implements GitService {
|
||||
constructor(
|
||||
private mockTags: { name: string }[] = [],
|
||||
private mockCommit: { commit: { message: string } } = { commit: { message: "test commit" } }
|
||||
private mockCommit: { commit: { message: string } } = { commit: { message: "test commit" } },
|
||||
) {}
|
||||
|
||||
async listTags(perPage: number): Promise<{ name: string }[]> {
|
||||
@@ -174,19 +176,19 @@ describe("TagService", () => {
|
||||
|
||||
it("should throw error for invalid format", () => {
|
||||
expect(() => tagService.parseTag("invalid")).toThrow(
|
||||
"Invalid tag format: invalid. Expected semantic version (e.g., 1.2.3)"
|
||||
"Invalid tag format: invalid. Expected semantic version (e.g., 1.2.3)",
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw error for non-numeric versions", () => {
|
||||
expect(() => tagService.parseTag("1.a.3")).toThrow(
|
||||
"Invalid tag format: 1.a.3. Expected semantic version (e.g., 1.2.3)"
|
||||
"Invalid tag format: 1.a.3. Expected semantic version (e.g., 1.2.3)",
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw error for incomplete version", () => {
|
||||
expect(() => tagService.parseTag("1.2")).toThrow(
|
||||
"Invalid tag format: 1.2. Expected semantic version (e.g., 1.2.3)"
|
||||
"Invalid tag format: 1.2. Expected semantic version (e.g., 1.2.3)",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -209,7 +211,7 @@ describe("TagIncrementer", () => {
|
||||
mockGitService,
|
||||
mockCoreService,
|
||||
mockCommitAnalyzer,
|
||||
mockTagService
|
||||
mockTagService,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -241,7 +243,7 @@ describe("TagIncrementer", () => {
|
||||
|
||||
expect(result).toBe("0.0.0");
|
||||
expect(mockCoreService.getWarnings()).toContain(
|
||||
"WARNING: No tags found in repository, defaulting to 0.0.0"
|
||||
"WARNING: No tags found in repository, defaulting to 0.0.0",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -269,7 +271,7 @@ describe("TagIncrementer", () => {
|
||||
|
||||
expect(result).toBe("0.0.0");
|
||||
expect(mockCoreService.getWarnings()).toContain(
|
||||
"WARNING: No real tags found (only pre-release tags), defaulting to 0.0.0"
|
||||
"WARNING: No real tags found (only pre-release tags), defaulting to 0.0.0",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -426,7 +428,7 @@ describe("LocalGitService", () => {
|
||||
});
|
||||
|
||||
await expect(localGitService.testConnection()).rejects.toThrow(
|
||||
"Not in a git repository. Please ensure this action runs after checkout."
|
||||
"Not in a git repository. Please ensure this action runs after checkout.",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -439,8 +441,6 @@ describe("LocalCoreService", () => {
|
||||
localCoreService = new LocalCoreService();
|
||||
});
|
||||
|
||||
// @actions/core is mocked via jest.config.js moduleNameMapper
|
||||
|
||||
it("should have all required methods", () => {
|
||||
expect(typeof localCoreService.getInput).toBe("function");
|
||||
expect(typeof localCoreService.info).toBe("function");
|
||||
@@ -457,7 +457,7 @@ describe("TagIncrementer Integration", () => {
|
||||
[{ name: "v2.0.0-rc-26035c6e13" }, { name: "v1.1.4-rc-aa512edb16" }, { name: "v1.2.3" }],
|
||||
{
|
||||
commit: { message: "feat: new feature" },
|
||||
}
|
||||
},
|
||||
);
|
||||
const mockCoreService = new MockCoreService();
|
||||
const commitAnalyzer = new ConventionalCommitAnalyzer();
|
||||
@@ -467,7 +467,7 @@ describe("TagIncrementer Integration", () => {
|
||||
mockGitService,
|
||||
mockCoreService,
|
||||
commitAnalyzer,
|
||||
tagService
|
||||
tagService,
|
||||
);
|
||||
|
||||
const result = await tagIncrementer.incrementTag(undefined, "ref");
|
||||
|
||||
+9
-9
@@ -100,7 +100,7 @@ export class TagIncrementer {
|
||||
private gitService: GitService,
|
||||
private coreService: CoreService,
|
||||
private commitAnalyzer: ConventionalCommitAnalyzer,
|
||||
private tagService: TagService
|
||||
private tagService: TagService,
|
||||
) {}
|
||||
|
||||
async getBaseTag(lastTag: string | undefined, maxTags: number = 50): Promise<string> {
|
||||
@@ -138,7 +138,7 @@ export class TagIncrementer {
|
||||
|
||||
const analyzedCommit = this.commitAnalyzer.analyzeCommit(commit.message);
|
||||
this.coreService.info(
|
||||
`Analyzed commit - type: ${analyzedCommit.type}, breaking: ${analyzedCommit.breaking}`
|
||||
`Analyzed commit - type: ${analyzedCommit.type}, breaking: ${analyzedCommit.breaking}`,
|
||||
);
|
||||
|
||||
const incrementType = this.commitAnalyzer.determineIncrementType(analyzedCommit);
|
||||
@@ -147,14 +147,14 @@ export class TagIncrementer {
|
||||
return incrementType;
|
||||
} catch (error) {
|
||||
this.coreService.info(
|
||||
`Error fetching commit ${ref}: ${error instanceof Error ? error.message : String(error)}`
|
||||
`Error fetching commit ${ref}: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
|
||||
// Additional debugging for commit-related errors
|
||||
if (error instanceof Error && error.message.includes("404")) {
|
||||
this.coreService.info(`404 error suggests commit ${ref} was not found in repository`);
|
||||
this.coreService.info(
|
||||
`This could indicate: 1) SHA doesn't exist, 2) Repository access issue, 3) API endpoint mismatch`
|
||||
`This could indicate: 1) SHA doesn't exist, 2) Repository access issue, 3) API endpoint mismatch`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ export class TagIncrementer {
|
||||
ref: string,
|
||||
maxTags: number = 50,
|
||||
prerelease: boolean = false,
|
||||
githubSha: string = ""
|
||||
githubSha: string = "",
|
||||
): Promise<string> {
|
||||
this.coreService.info(`Starting tag increment process at ref ${ref}`);
|
||||
|
||||
@@ -175,7 +175,7 @@ export class TagIncrementer {
|
||||
const parsedTag = this.tagService.parseTag(baseTag);
|
||||
|
||||
this.coreService.info(
|
||||
`Parsed version: ${parsedTag.major}.${parsedTag.minor}.${parsedTag.patch}`
|
||||
`Parsed version: ${parsedTag.major}.${parsedTag.minor}.${parsedTag.patch}`,
|
||||
);
|
||||
|
||||
const incrementType = await this.determineIncrementType(ref);
|
||||
@@ -187,7 +187,7 @@ export class TagIncrementer {
|
||||
|
||||
this.coreService.info(`New tag: ${renderedTag}`);
|
||||
this.coreService.info(
|
||||
`Successfully determined new tag: ${renderedTag} (${incrementType} increment)`
|
||||
`Successfully determined new tag: ${renderedTag} (${incrementType} increment)`,
|
||||
);
|
||||
|
||||
return renderedTag;
|
||||
@@ -215,7 +215,7 @@ export class LocalGitService implements GitService {
|
||||
return { commit: { message } };
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`Failed to get commit ${ref}: ${error instanceof Error ? error.message : String(error)}`
|
||||
`Failed to get commit ${ref}: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -296,7 +296,7 @@ export async function run(): Promise<void> {
|
||||
ref,
|
||||
maxTags,
|
||||
prerelease,
|
||||
githubSha
|
||||
githubSha,
|
||||
);
|
||||
|
||||
coreService.info(`Process completed successfully. New tag: ${newTag}`);
|
||||
|
||||
Reference in New Issue
Block a user