Skip to content

Commit 45de99c

Browse files
Copilotamondnet
andauthored
fix(tests): clear GITHUB_ACTIONS env in vitest unit project to prevent auto-invocation on import
Agent-Logs-Url: https://github.com/amondnet/vercel-action/sessions/e840b930-a078-4381-91dc-06dc24402e36 Co-authored-by: amondnet <1964421+amondnet@users.noreply.github.com>
1 parent b57e354 commit 45de99c

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,11 @@ export async function run(): Promise<void> {
345345
}
346346
}
347347

348-
// Auto-invoke run() only inside the GitHub Actions runner. A negative guard
349-
// like `!process.env.VITEST` would silently disable the action in any
350-
// workflow that happens to set VITEST (e.g. a step running unit tests in the
351-
// same job). GITHUB_ACTIONS is the canonical, runner-set sentinel.
348+
// Auto-invoke run() only inside the GitHub Actions runner.
349+
// GITHUB_ACTIONS is the canonical, runner-set sentinel that is not
350+
// user-controllable. Unit tests override this to '' in vitest.config.ts
351+
// (via test.env) so that module imports during tests do not trigger
352+
// auto-invocation.
352353
if (process.env.GITHUB_ACTIONS === 'true') {
353354
run().catch((error: unknown) => {
354355
if (error instanceof Error) {

vitest.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export default defineConfig({
2525
exclude: ['node_modules', 'dist', 'example'],
2626
testTimeout: 10000,
2727
hookTimeout: 10000,
28+
// Prevent index.ts from auto-invoking run() when tests import it.
29+
// The guard uses GITHUB_ACTIONS === 'true', which is set to 'true'
30+
// in the CI runner environment where unit tests also run.
31+
env: { GITHUB_ACTIONS: '' },
2832
},
2933
},
3034
{

0 commit comments

Comments
 (0)