Skip to content

Commit fc92cd5

Browse files
refactor: make run() explicitly callable in tests, remove flaky setTimeout
Co-Authored-By: Niels Swimberghe <3382717+Swimburger@users.noreply.github.com>
1 parent bc361d8 commit fc92cd5

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

dist/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39766,7 +39766,10 @@ async function createPR(octokit, owner, repo, branchName, targetBranch, isFromFe
3976639766
core.info(`Pull request created: ${prResponse.data.html_url}`);
3976739767
return prResponse;
3976839768
}
39769-
run();
39769+
// Auto-invoke only when running as the action entry point (not when imported in tests)
39770+
if (process.env.NODE_ENV !== "test") {
39771+
run();
39772+
}
3977039773

3977139774

3977239775
/***/ }),

src/sync.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,8 @@ function setupMocks({
148148
async function importAndRun() {
149149
vi.resetModules();
150150

151-
await import("./sync");
152-
153-
// Wait for async operations to complete
154-
await new Promise((resolve) => setTimeout(resolve, 200));
151+
const { run } = await import("./sync");
152+
await run();
155153
}
156154

157155
beforeEach(() => {

src/sync.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,4 +693,7 @@ async function createPR(
693693
return prResponse;
694694
}
695695

696-
run();
696+
// Auto-invoke only when running as the action entry point (not when imported in tests)
697+
if (process.env.NODE_ENV !== "test") {
698+
run();
699+
}

0 commit comments

Comments
 (0)