Skip to content

fix: jest - Run and repair excluded CJS tests #3484

Open

Description

@eleshar

Problem

.jest.config.cjs testMatch covers *.test.js, *.test.ts and *.test.mjs, but not *.test.cjs. The 20 tracked *.test.cjs files outside archived/ never run, so their failures are invisible.

Forced run (JEST_TEST_MATCH_*="**/*.test.cjs", 2026-09-23): 18 of 20 suites fail, 21 of 118 tests.

Failing suites:

  • agents/changelog-agent/includes/tests/{keepAChangelogParser,changelogValidator}.test.cjs
  • agents/release-agent/__tests__/{integration,gitOps}.test.cjs, agents/release-agent/includes/tests/{versionManager,repoDetector}.test.cjs
  • agents/wordpress-release-utilities-agent/includes/tests/readmeTxt.test.cjs
  • scripts/automation/__tests__/update-projects-status.test.cjs
  • scripts/validation/__tests__/validate-labels-before-creation.test.cjs
  • scripts/workflows/__tests__/orchestrate-phase-progression.test.cjs (this one only tests helpers defined inside the test file itself)
  • scripts/workflows/changelog/__tests__/{checkout-pr-head,merge-entries.integration,merge-entries,changelog-management}.test.cjs
  • scripts/workflows/metrics/__tests__/metrics-reporting.test.cjs
  • scripts/workflows/projects/__tests__/{scan-completion,archive-projects}.test.cjs
  • scripts/workflows/release/__tests__/trigger-telemetry.test.cjs

Change

Acceptance

  • npx jest --config .jest.config.cjs --listTests includes every tracked *.test.cjs, and all of them pass.

Definition of Ready (DoR)

  • Bug is reproducible and clearly described
  • Steps to reproduce written
  • Environment details provided
  • Screenshots/logs included (if possible)
  • Linked to existing issues/PRs (if any)
  • Estimate added (if relevant)
  • Ready for triage
  • Estimate added (if applicable)

Definition of Done (DoD)

  • Issue is fixed and tested
  • Bug confirmed and reproducible
  • Fix implemented and tested (all supported browsers/devices)
  • Documentation updated (if needed)
  • Changelog entry prepared for PR (CHANGELOG.md)
  • QA performed
  • Accessibility: no WCAG 2.2 AA regressions (semantic HTML, keyboard support, colour contrast)
  • Performance: no adverse impact introduced
  • Branch prefix is correct (fix/)
  • Branch deleted after merge
  • Linked issue updated with latest status and closed after merge

Relates to #3469, #3472, #3479

Activity

  1. linear-code commented on Sep 23, 2026

    @linear-code
  2. eleshar commented on Sep 30, 2026

    @eleshar
    ContributorAuthor

    Still live on develop @ 1a1021eea8 — and #3560 is a duplicate of this

    .jest.config.cjs:27-34 on develop:

        testMatch: [
            process.env.JEST_TEST_MATCH_1 || '**/tests/**/*.test.js',
            process.env.JEST_TEST_MATCH_2 || '**/tests/**/*.test.ts',
            process.env.JEST_TEST_MATCH_3 || '**/tests/**/*.test.mjs',
            process.env.JEST_TEST_MATCH_4 || '**/__tests__/**/*.test.js',
            process.env.JEST_TEST_MATCH_5 || '**/__tests__/**/*.test.ts',
            process.env.JEST_TEST_MATCH_6 || '**/__tests__/**/*.test.mjs',
        ],

    Six patterns, three extensions, no .cjs. The repository carries 20 *.test.cjs files on develop, so none of them is ever selected by npm test. moduleFileExtensions at line 47 does list cjs, so the files resolve once selected — it is testMatch alone that excludes them.

    Duplicate of #3560

    #3560 is titled "ci: 20 .test.cjs suites run in no known runner" and reports the same 20 files. #3484 adds the testMatch diagnosis and the "18 fail when run" measurement. #3484 is the better-formed of the two — it names the mechanism, this one only observes the absence. One should win and the other close; which is a maintainer call, but merging both would produce two pull requests touching the same six lines of .jest.config.cjs.

    Note the env-var indirection already in place: JEST_TEST_MATCH_1 … 6 can override any pattern, so a test can drive the new .cjs pattern without editing the file. That is also the fastest way to confirm the 18 failures before committing to the fix.

  3. eleshar commented on Oct 1, 2026

    @eleshar
    ContributorAuthor

    Re-measured on develop at cb955e47dd (ESLint 10.11.0, Jest 30.5.2, Node v24.21.0), each of the 20 tracked *.test.cjs files in its own Jest process, because one of them kills the runner and would otherwise hide the rest.

    Result

    3 suites pass · 16 fail · 1 produces no summary at all.

    Suite Tests
    agents/wordpress-release-utilities-agent/includes/tests/pluginHeader.test.cjs 26 passed — PASS
    agents/wordpress-release-utilities-agent/includes/tests/themeCss.test.cjs 20 passed — PASS
    scripts/validation/__tests__/validate-labels-before-creation.test.cjs 22 passed — PASS
    agents/release-agent/__tests__/gitOps.test.cjs 3 failed, 8 passed
    agents/release-agent/__tests__/integration.test.cjs 3 failed, 4 passed
    agents/wordpress-release-utilities-agent/includes/tests/readmeTxt.test.cjs 2 failed, 19 passed
    scripts/workflows/release/__tests__/trigger-telemetry.test.cjs 11 failed, 11 total
    scripts/workflows/changelog/__tests__/merge-entries.test.cjs no summary — kills the runner
    11 further suites Tests: 0 total, Test Suites: 1 failed

    Totals across the reporting suites: 19 failed, 99 passed, 118 total.

    This reconciles with the 118 total recorded on 2026-09-23 and the 21 failures recorded then: same denominator, 19 failing now. One suite that failed then passes now — validate-labels-before-creation.test.cjs. The conclusion is unchanged: these are not safe to enable.

    Two things this issue did not identify

    1. Adding **/*.test.cjs to testMatch is not sufficient. The transform in .jest.config.cjs is:

    transform: {
        '^.+\\.(js|mjs|ts|tsx|jsx)?$': [ … ]
    }

    cjs is absent. moduleFileExtensions already includes cjs, so resolution is fine, but the test files are not transformed. Any proposal that only widens testMatch needs this changed too, and it should be verified rather than assumed.

    2. Eleven suites fail at module load, before registering a single test. They report Tests: 0 total rather than a test failure. That is a different defect class from "a test asserts the wrong thing", and it is why the failure count looks small relative to the suite count. These will not be fixed by adjusting expectations.

    3. merge-entries.test.cjs calls process.exit(), at line 223:

    console.log(`\n${testsPassed} passed, ${testsFailed} failed`);
    process.exit(testsFailed > 0 ? 1 : 0);

    This terminates the whole Jest worker. In a single run with all 20 enabled, the run dies there with no summary at all — which is exactly what happened when I forced the full set. .jest.config.cjs already excludes four sibling .js scripts from testPathIgnorePatterns for this reason, with a comment saying each "calls process.exit() directly, which crashes the Jest worker instead of reporting a failure". These files need the same treatment or a rewrite.

    Why no pull request

    Enabling these is unsafe on the evidence above: 17 of 20 do not pass, and one is not even a Jest suite as written. This is triage work across 17 suites, which is a change of a different shape and should not ride along with a configuration change.

    Related: #3560 covers the same files from the "which runner owns each file" angle. On the evidence here I would keep #3484 as the tracker and close #3560 as the duplicate — #3484 states the defect and its acceptance criterion, whereas #3560 proposes migrating to .test.js or wiring package-local runners, and this measurement shows neither helps until the suites actually pass.

  4. eleshar commented on Oct 3, 2026

    @eleshar
    ContributorAuthor

    Context from #3711 (merged as 907442298): before it, bare npx jest found no configuration and fell back to Jest's built-in defaults, which did match the 20 *.test.cjs suites. With the new root jest.config.cjs forwarding to .jest.config.cjs, bare Jest now discovers exactly what the intended configuration does, and that configuration's testMatch does not include .cjs test files. So these suites are still not run by npm test, and bare Jest no longer picks them up either. This issue is unchanged: they still need a decision to be included in testMatch (and the failing ones fixed) or run by their own runner.

  5. changed the title [-]test: 20 *.test.cjs files never run (testMatch omits .cjs); 18 fail when run[/-] [+]fix: jest - Run and repair excluded CJS tests[/+] on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions