#51315: test: fix race in reentrant loadURL() ready-to-commit test
Merged
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
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
-
npm testpasses - tests are changed or added
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, and past tense.
Release Notes
Notes: none.
Backports
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