Skip to content

Commit a2fda08

Browse files
committed
Fix tests
1 parent 1413aa3 commit a2fda08

2 files changed

Lines changed: 36 additions & 27 deletions

File tree

tests/integration/core.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ const BASIC_FILE_CHANGES = {
3737
],
3838
};
3939

40+
// Match branch name as in core.ts
41+
function getInternalTempBranch(name: string) {
42+
return `changesets-ghcommit-test/${name}`;
43+
}
44+
4045
describe("commitFilesFromBase64", () => {
4146
let repositoryId: string;
4247
let testTargetCommit: string;
@@ -247,7 +252,9 @@ describe("commitFilesFromBase64", () => {
247252
describe("existing branches", () => {
248253
it("can commit to existing branch when force is true", async () => {
249254
const branch = getTempBranch("existing-branch-force");
255+
const internalTempBranch = getInternalTempBranch(branch);
250256
onTestFinished(() => deleteBranch(branch));
257+
onTestFinished(() => deleteBranch(internalTempBranch, true));
251258

252259
// Create an exiting branch
253260
await createRefMutation(octokit, {
@@ -273,13 +280,14 @@ describe("commitFilesFromBase64", () => {
273280
});
274281

275282
await expectParentHasOid({ branch, oid: testTargetCommit });
283+
await expectBranchDoesNotExist(internalTempBranch);
276284
});
277285

278286
it("cleans up a pre-existing temporary branch when force is true", async () => {
279287
const branch = getTempBranch("existing-branch-force-existing-temp");
280-
const tempBranch = getTempBranch(`temp-${branch}`);
288+
const internalTempBranch = getInternalTempBranch(branch);
281289
onTestFinished(() => deleteBranch(branch));
282-
onTestFinished(() => deleteBranch(tempBranch));
290+
onTestFinished(() => deleteBranch(internalTempBranch, true));
283291

284292
await createRefMutation(octokit, {
285293
input: {
@@ -292,7 +300,7 @@ describe("commitFilesFromBase64", () => {
292300
await createRefMutation(octokit, {
293301
input: {
294302
repositoryId,
295-
name: `refs/heads/${tempBranch}`,
303+
name: `refs/heads/${internalTempBranch}`,
296304
oid: testTargetCommit2,
297305
},
298306
});
@@ -312,7 +320,7 @@ describe("commitFilesFromBase64", () => {
312320
});
313321

314322
await expectParentHasOid({ branch, oid: testTargetCommit });
315-
await expectBranchDoesNotExist(tempBranch);
323+
await expectBranchDoesNotExist(internalTempBranch);
316324
});
317325

318326
it("cannot commit to existing branch when force is false", async () => {

tests/integration/utils.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,30 +158,31 @@ export async function expectBranchDoesNotExist(branch: string) {
158158

159159
// #region Octokit helpers
160160

161-
export async function deleteBranch(branch: string) {
162-
console.debug(`Deleting branch ${branch}`);
163-
// Get Ref
164-
const ref = await getRepositoryMetadata(octokit, {
165-
owner,
166-
repo,
167-
baseRef: `refs/heads/${branch}`,
168-
targetRef: `refs/heads/${branch}`,
169-
});
170-
171-
const refId = ref?.baseRef?.id;
172-
173-
if (!refId) {
174-
console.warn(`Branch ${branch} not found`);
175-
return;
161+
export async function deleteBranch(branch: string, allowNotExist = false) {
162+
try {
163+
const ref = await getRepositoryMetadata(octokit, {
164+
owner,
165+
repo,
166+
baseRef: `refs/heads/${branch}`,
167+
targetRef: `refs/heads/${branch}`,
168+
});
169+
170+
const refId = ref?.baseRef?.id;
171+
if (!refId) {
172+
if (!allowNotExist) {
173+
console.warn(`Branch ${branch} not found`);
174+
}
175+
return;
176+
}
177+
178+
await deleteRefMutation(octokit, {
179+
input: {
180+
refId,
181+
},
182+
});
183+
} catch (error) {
184+
console.error(`Failed to delete branch ${branch}:`, error);
176185
}
177-
178-
await deleteRefMutation(octokit, {
179-
input: {
180-
refId,
181-
},
182-
});
183-
184-
console.debug(`Deleted branch ${branch}`);
185186
}
186187

187188
// #endregion

0 commit comments

Comments
 (0)