mirror of
https://github.com/millionco/react-doctor.git
synced 2026-09-14 20:00:24 +08:00
88a5c3cb49
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { tmpdir } from "node:os";
|
|
import * as path from "node:path";
|
|
import * as fs from "node:fs";
|
|
import { describe, expect, it } from "vite-plus/test";
|
|
import {
|
|
getReactDoctorWorkflowPath,
|
|
installReactDoctorWorkflow,
|
|
} from "../src/cli/utils/install-github-workflow.js";
|
|
|
|
const installInTempDir = (
|
|
defaultBranch?: string,
|
|
): { readonly content: string; readonly cleanup: () => void } => {
|
|
const projectRoot = fs.mkdtempSync(path.join(tmpdir(), "react-doctor-workflow-install-"));
|
|
const result = installReactDoctorWorkflow(projectRoot, defaultBranch);
|
|
expect(result.status).toBe("created");
|
|
return {
|
|
content: fs.readFileSync(getReactDoctorWorkflowPath(projectRoot), "utf8"),
|
|
cleanup: () => fs.rmSync(projectRoot, { recursive: true, force: true }),
|
|
};
|
|
};
|
|
|
|
describe("installReactDoctorWorkflow push trigger", () => {
|
|
it("scans the repo's default branch on push, not a hardcoded main", () => {
|
|
const { content, cleanup } = installInTempDir("develop");
|
|
try {
|
|
expect(content).toContain('branches: ["develop"]');
|
|
expect(content).toContain("Scans `develop` on every push");
|
|
expect(content).not.toContain("[main]");
|
|
} finally {
|
|
cleanup();
|
|
}
|
|
});
|
|
|
|
it("falls back to main when the default branch is unknown", () => {
|
|
const { content, cleanup } = installInTempDir();
|
|
try {
|
|
expect(content).toContain('branches: ["main"]');
|
|
} finally {
|
|
cleanup();
|
|
}
|
|
});
|
|
|
|
it("checks out full git history so PR runs can find the merge base", () => {
|
|
const { content, cleanup } = installInTempDir();
|
|
try {
|
|
// Without fetch-depth: 0 a shallow checkout has no merge base, so the
|
|
// compare-mode scan degrades to reporting every pre-existing issue.
|
|
expect(content).toContain("- uses: actions/checkout@v5");
|
|
expect(content).toContain("fetch-depth: 0");
|
|
} finally {
|
|
cleanup();
|
|
}
|
|
});
|
|
});
|