Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

The test file close_older_issues.test.cjs was written using Jest syntax (@jest/globals, jest.fn(), jest.clearAllMocks()), causing CI failure with "Cannot find module '@jest/globals'". The codebase uses Vitest.

Changes

  • Imports: Convert from require("@jest/globals") to import { describe, it, expect, beforeEach, vi } from "vitest"
  • Module loading: Change require() to ES module import statements
  • Mocking: Replace all jest.fn()vi.fn() and jest.clearAllMocks()vi.clearAllMocks()
  • Test fix: Correct test data where title was "Old Issue" but test expected it to start with "Prefix" (line 227)

Before

const { describe, it, expect, beforeEach } = require("@jest/globals");
const { closeOlderIssues, ... } = require("./close_older_issues.cjs");

global.core = {
  info: jest.fn(),
  warning: jest.fn(),
  error: jest.fn(),
};

beforeEach(() => {
  jest.clearAllMocks();
  mockGithub = {
    rest: {
      search: { issuesAndPullRequests: jest.fn() },
      // ...
    }
  };
});

After

import { describe, it, expect, beforeEach, vi } from "vitest";
import { closeOlderIssues, ... } from "./close_older_issues.cjs";

global.core = {
  info: vi.fn(),
  warning: vi.fn(),
  error: vi.fn(),
};

beforeEach(() => {
  vi.clearAllMocks();
  mockGithub = {
    rest: {
      search: { issuesAndPullRequests: vi.fn() },
      // ...
    }
  };
});

All 12 tests in close_older_issues.test.cjs now pass.

Original prompt

This section details on the original issue you should resolve

<issue_title>[CI Failure Doctor] CI Failure Doctor: close_older_issues.test.cjs uses Jest instead of Vitest</issue_title>
<issue_description>## Summary

The CI workflow failed on commit c1c6704 (PR #10882) because the newly added test file close_older_issues.test.cjs uses Jest test framework syntax (@jest/globals and jest.fn()) instead of the Vitest framework used throughout the codebase.

Failure Details

Root Cause Analysis

Primary Error

Error: Cannot find module '@jest/globals'
Require stack:
- /home/runner/work/gh-aw/gh-aw/actions/setup/js/close_older_issues.test.cjs
 ❯ close_older_issues.test.cjs:3:46

Technical Details

The test file close_older_issues.test.cjs (334 lines) uses Jest syntax patterns that are incompatible with Vitest:

Incorrect imports (Line 3):

const { describe, it, expect, beforeEach } = require("@jest/globals");

Incorrect mocking (Lines 8-10):

global.core = {
  info: jest.fn(),    // ❌ Should be vi.fn()
  warning: jest.fn(),
  error: jest.fn(),
};

Incorrect module loading:

  • Uses CommonJS require() instead of ES modules import

Correct Patterns Used in Other Test Files

All existing test files use Vitest:

// ✅ Correct - From add_comment.test.cjs, add_labels.test.cjs, etc.
import { describe, it, expect, beforeEach, vi } from "vitest";

const mockCore = {
  debug: vi.fn(),
  info: vi.fn(),
  warning: vi.fn(),
  error: vi.fn(),
};

Additional Test Failures

The run also showed 42 other test failures, mostly in collect_ndjson_output.test.cjs and safe_outputs_mcp_server_defaults.test.cjs, but these appear to be pre-existing issues unrelated to this specific failure.

Recommended Actions

Fix #1: Convert Test File to Vitest (Required)

Replace Jest syntax with Vitest in close_older_issues.test.cjs:

Changes needed:

  1. Update imports (line 3):

    // Before:
    const { describe, it, expect, beforeEach } = require("@jest/globals");
    
    // After:
    import { describe, it, expect, beforeEach, vi } from "vitest";
  2. Update module imports (line 4):

    // Before:
    const { closeOlderIssues, ... } = require("./close_older_issues.cjs");
    
    // After:
    import { closeOlderIssues, ... } from "./close_older_issues.cjs";
  3. Update mocking (lines 8-10):

    // Before:
    global.core = {
      info: jest.fn(),
      warning: jest.fn(),
      error: jest.fn(),
    };
    
    // After:
    global.core = {
      info: vi.fn(),
      warning: vi.fn(),
      error: vi.fn(),
    };
  4. Update all mock functions (lines 18-28 and throughout):

    // Before:
    mockGithub = {
      rest: {
        search: {
          issuesAndPullRequests: jest.fn(),
        },
        issues: {
          createComment: jest.fn(),
          update: jest.fn(),
        },
      },
    };
    
    // After:
    mockGithub = {
      rest: {
        search: {
          issuesAndPullRequests: vi.fn(),
        },
        issues: {
          createComment: vi.fn(),
          update: vi.fn(),
        },
      },
    };
  5. Update beforeEach (line 17):

    beforeEach(() => {
      vi.clearAllMocks();  // Instead of jest.clearAllMocks()
      // ... rest of setup
    });

Fix #2: Run Local Tests Before Committing

Always run the full test suite locally:

cd actions/setup/js
npm test

This would have caught the error immediately.

Prevention Strategies

1. Add Pre-commit Validation

Update AGENTS.md to emphasize test validation:

### JavaScript Test Requirements

**ALWAYS use Vitest patterns for JavaScript tests:**

1. **Imports**: Use `import { describe, it, expect, vi } from "vitest"`
2. **Mocking**: Use `vi.fn()` instead of `jest.fn()`
3. **Module loading**: Use ES module `import` instead of `require()`
4. **Clear mocks**: Use `vi.clearAllMocks()` instead of `jest.clearAllMocks()`

**Before committing JavaScript files:**
``````bash
cd actions/setup/js
npm ci              # Install dependencies
npm test           # Run all tests (includes typecheck)
npm run lint       # Run linter

Example - Correct test file structure:

import { describe, it, expect, beforeEach, vi } from "vitest";
import { myFunction } from "./my-module.cjs";

const mockCore = {
  info: vi.fn(),
  war...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes githubnext/gh-aw#10895

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

…ng test

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CI failure by updating test from Jest to Vitest Convert close_older_issues.test.cjs from Jest to Vitest Jan 20, 2026
Copilot AI requested a review from mnkiefer January 20, 2026 20:28
@pelikhan pelikhan marked this pull request as ready for review January 20, 2026 21:15
@pelikhan pelikhan merged commit 978053d into main Jan 20, 2026
48 checks passed
@pelikhan pelikhan deleted the copilot/fix-close-older-issues-test branch January 20, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants