Skip to content

Fix Windows Node 24 CI test execution by using Jest JS entrypoint#77

Merged
acrosman merged 4 commits intomainfrom
copilot/fix-github-actions-release-job
Apr 23, 2026
Merged

Fix Windows Node 24 CI test execution by using Jest JS entrypoint#77
acrosman merged 4 commits intomainfrom
copilot/fix-github-actions-release-job

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

Release workflow failures on Windows (Node 24) were caused by how Jest was invoked in npm scripts, not by preload module format. This PR updates test script commands to use Jest’s JavaScript entrypoint directly so they run cross-platform, while preserving the existing preload runtime behavior that allows games to load at startup.

  • Cross-platform Jest invocation

    • Updated package.json scripts:
      • test
      • test:watch
      • test:coverage
    • Switched from node_modules/.bin/jest (Unix shell shim) to node_modules/jest/bin/jest.js (direct Node entrypoint).
  • Behavior preserved

    • Preload runtime behavior remains unchanged to avoid the startup regression where games failed to load.
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
"test:coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage"
Original prompt

Repo: acrosman/BrainSpeedExercises

Goal: Fix the failing GitHub Actions job in workflow .github/workflows/release.yml (Release Build). The job fails on Windows in run https://github.com/acrosman/BrainSpeedExercises/actions/runs/24813101634/job/72621852346#step:5:24.

Context:

  • Project is ESM ("type": "module" in package.json).
  • app/preload.js currently uses CommonJS require('electron'), which can fail when loaded as ESM under Node 22/24 in CI.
  • Jest tests include app/preload.test.js which currently sets global.require and then imports ./preload.js.

Implement the suggested fix:

  1. Convert app/preload.js to proper ES module syntax:

    • Replace const { contextBridge, ipcRenderer } = require('electron'); with import { contextBridge, ipcRenderer } from 'electron';
    • Keep behavior the same.
  2. Update app/preload.test.js to mock the ESM import of electron using jest.unstable_mockModule('electron', ...) before importing ./preload.js.

    • Remove the global.require mocking and related cleanup.
    • Ensure tests still validate that the context bridge exposes api.invoke and that allowed/blocked channels behave as expected.
  3. Keep changes minimal; do not downgrade Node. Node 22 or 24 must remain usable.

  4. Ensure npm test passes.

Notes:

  • Current workflow uses actions/setup-node@v6 with Node 24.
  • Relevant files:
    • app/preload.js
    • app/preload.test.js
    • package.json
    • jest.config.js

Please open a PR with these changes.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The job is failing during the Node step (Windows runner) with a non-zero exit from a Node script, and you’re currently running on Node.js v24.15.0. The workflow is:

  • setup-node: node-version: 24
  • npm ci
  • npm test
  • npm run publish

Given the log tail, the failure is happening inside a Node process (most likely npm test or npm run publish) and is consistent with a Node 24 compatibility break (Node 24 is very new and commonly breaks older test runners, native addons, packaging scripts, and some Electron tooling).

Fix (recommended): run the release workflow on Node 20 (LTS)

Change the workflow to use Node 20 instead of 24. This is the most reliable fix for CI/release pipelines unless you’ve explicitly validated Node 24 across your dependencies.

Edit .github/workflows/release.yml at ref 0b6729158b27a039d18376414de8fe2fdf4167f8:

-      - name: Use Node.js 24
+      - name: Use Node.js 20 (LTS)
       uses: actions/setup-node@v6
       with:
-        node-version: 24
+        node-version: 20
         cache: "npm"

Why this works:

  • Most npm ecosystems/tools (tests, bundlers, release tooling) target LTS first.
  • Your workflow is release-critical (publishing artifacts). Stability > newest runtime.

Optional hardening (so it’s obvious which step fails)

Split the “publish” step to include more output and fail-fast context:

- name: Publish release artifacts
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: |
    node -v
    npm -v
    npm run publish --silent=false

If you must support Node 24

Then you’ll need to upgrade the specific dependency/tool that is crashing under Node 24 (often a test runner, Electron/electron-builder, node-gyp native dependency, or a packaging script). But with the information available from the job log snippet, the actionable and safest solution is to pin CI to Node 20 LTS for the release workflow.

User: A previous version of the process used Node 20, and threw the same error. Also Node 20 leaves support in a few days. That's a poor solution. Node 22 or 24 must be used.

Assistant: The failure is coming from a CommonJS require('electron') in an ES Module project. Your package.json sets "type": "module", but app/preload.js is written as CommonJS:

const { contextBridge, ipcRenderer } = require('electron');

On Node 22/24 this commonly fails when the file is loaded as ESM (directly by tests, bundling, or tooling), producing a Node crash and exit code 1 (which matches the log tail you shared). This also explains why Node 20 showed the same error: it’s a module-type mismatch, not a Node-version-specific problem.

Solution: convert app/preload.js to ESM and update the test to mock ESM imports

1) Update app/preload.js to use ESM import

/**
 * preload.js  Electron preload script for BrainSpeedExercises.
 *
 * Exposes a secure, allowlisted API to the renderer process via contextBridge.
 * Only explicitly allowed IPC channels ar...

</details>



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

*This pull request was created from Copilot chat.*
>

Copilot AI changed the title [WIP] Fix failing GitHub Actions job in release workflow Fix preload module format for Node 22/24 by migrating to ESM and updating Jest preload mock Apr 23, 2026
Copilot AI requested a review from acrosman April 23, 2026 02:41
@acrosman
Copy link
Copy Markdown
Owner

@copilot Games no longer load a start up. See attached images for errors.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 23, 2026

@copilot Games no longer load a start up. See attached images for errors.

Fixed in commit b96afda by reverting the preload ESM change and restoring the prior preload test setup so startup loading works again. Screenshot reference: https://github.com/user-attachments/assets/1a823e52-f23a-4aa9-80b4-874522615943

@acrosman
Copy link
Copy Markdown
Owner

@copilot Okay, you completely undid your changes. How do we solve the build problem that started this PR (in pasted image)? Start over, and try again.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 23, 2026

@copilot Okay, you completely undid your changes. How do we solve the build problem that started this PR (in pasted image)? Start over, and try again.

You’re right. I restarted from the CI logs and fixed the actual Windows Node 24 failure in commit 06c2635: npm test was invoking node_modules/.bin/jest (a Unix shell shim), which Windows Node parsed as JS and crashed. I updated test, test:watch, and test:coverage to call node_modules/jest/bin/jest.js directly, while keeping preload runtime behavior stable so games still load. Screenshot: /tmp/playwright-logs/preload-regression-check.png

Copilot AI changed the title Fix preload module format for Node 22/24 by migrating to ESM and updating Jest preload mock Fix Windows Node 24 CI test execution by using Jest JS entrypoint Apr 23, 2026
@acrosman acrosman marked this pull request as ready for review April 23, 2026 03:02
@acrosman acrosman merged commit aeb2d1c into main Apr 23, 2026
6 checks passed
@acrosman acrosman deleted the copilot/fix-github-actions-release-job branch April 23, 2026 03:04
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.

2 participants