ckerr

#51315: test: fix race in reentrant loadURL() ready-to-commit test

Merged
Created: Apr 25, 2026, 11:31:32 AM
Merged: Apr 26, 2026, 9:40:05 AM
4 comments
Target: main

Description of Change

Fix fails if loadurl is called after the navigation is ready to commit by using a done() callback to ensure the test waits for did-fail-load. Previously, the test would return immediately and call afterEach(closeAllWindows), potentially destroying the window while navigation was in flight.

This use of done() here matches how the nearby tests work.

Sample test failure:

Unhandled exception in main spec runner: TypeError: Object has been destroyed
not ok 390 webContents module loadURL() promise API "after each" hook: closeAllWindows in "loadURL() promise API"
    at BrowserWindow.n.loadURL (node:electron/js2c/browser_init:2:20276)
  done() called multiple times in hook <webContents module loadURL() promise API "after each" hook: closeAllWindows in "loadURL() promise API"> of file D:\a\_work\1\b\src\electron\spec\api-web-contents-spec.ts; in addition, done() received error: TypeError: Object has been destroyed
    at WebContents.<anonymous> (D:\a\_work\1\b\src\electron\spec\api-web-contents-spec.ts:563:11)
      at BrowserWindow.n.loadURL (node:electron/js2c/browser_init:2:20276)
    at Object.onceWrapper (node:events:631:26)
      at WebContents.<anonymous> (D:\a\_work\1\b\src\electron\spec\api-web-contents-spec.ts:563:11)
    at WebContents.emit (node:events:509:28)
      at Object.onceWrapper (node:events:631:26)
      at WebContents.emit (node:events:509:28) {
    uncaught: true
  }
  Error: done() called multiple times in hook <webContents module loadURL() promise API "after each" hook: closeAllWindows in "loadURL() promise API"> of file D:\a\_work\1\b\src\electron\spec\api-web-contents-spec.ts; in addition, done() received error: TypeError: Object has been destroyed
      at BrowserWindow.n.loadURL (node:electron/js2c/browser_init:2:20276)
      at WebContents.<anonymous> (electron\spec\api-web-contents-spec.ts:563:11)
      at Object.onceWrapper (node:events:631:26)
      at WebContents.emit (node:events:509:28) {
    uncaught: true
  }
      at process.emit (node:events:521:24)
      at process.emit (electron\node_modules\source-map-support\source-map-support.js:495:21)
      at process._fatalException (node:internal/process/execution:159:25)
✗ Electron tests failed with code 0x1.

Checklist

Release Notes

Notes: none.

Backports

40-x-y
Merged
PR Number
#51322
Merged At
Apr 26, 2026, 12:30:07 PM
Released In
Not yet
Release Date
Not yet
41-x-y
Merged
PR Number
#51323
Merged At
Apr 26, 2026, 12:30:13 PM
Released In
Not yet
Release Date
Not yet
42-x-y
Merged
PR Number
#51324
Merged At
Apr 26, 2026, 12:30:16 PM
Released In
Not yet
Release Date
Not yet

Semver Impact

Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.

Semantic Versioning helps users understand the impact of updates:

  • Major (X.y.z): Breaking changes that may require code modifications
  • Minor (x.Y.z): New features that maintain backward compatibility
  • Patch (x.y.Z): Bug fixes that don't change the API
  • None: Changes that don't affect using facing parts of Electron