Cleaning up noise from test run output - #22449
Conversation
Webview controllers reject an internal _webviewReady deferred when they are disposed before the webview signals readiness. Because that rejection settles asynchronously, Mocha reports it as a stray 'rejected promise not handled within 1 second' against an unrelated test. Add an observeWebviewReady test helper that attaches a no-op catch to the controller's _webviewReady promise, and call it wherever tests construct (or internally dispose) webview controllers. Test-only change; no product code is modified.
WebviewPanelController.dispose rejects the base controller's _webviewReady deferred, producing an unhandled-rejection warning ~1s after the test ends. Attach observeWebviewReady in the panel controller test factory so the rejection is observed. Test-only change; no product code is modified.
…oise After a successful save, ResultsSerializer calls showInformationMessage().then() and shouldOpenSavedFile() (config.get) on its VscodeWrapper, and openSavedFile() chains openTextDocument().then()/showTextDocument(). Tests that drove these fire-and-forget success paths left showInformationMessage, openTextDocument, showTextDocument and getConfiguration().get unstubbed, so the chains rejected ~1s later as unhandled rejections. Add the missing stubs (including a get() on the custom-config wrapper). Test-only change; no product code is modified.
… noise The ConnectionDialogWebviewController constructor kicks off a fire-and-forget loadVscodeEntraDataAsync() when VS Code account mode is enabled. After a test disposes the controller, that background work calls updateState -> sendNotification on the disposed controller, surfacing as an unhandled 'Cannot send notification on disposed controller' rejection ~1s later. Stub the method on the prototype in setup and restore it in the two tests that exercise the real implementation. Test-only change; no product code is modified.
…ockerUtilities tests
There was a problem hiding this comment.
Pull request overview
This PR reduces unit test “noise” (unhandled promise rejections, missing stubs, and avoidable real-time delays) to make test runs cleaner and faster, especially around webview-controller disposal and connection-store initialization side effects.
Changes:
- Added a unit-test helper to observe (and handle) internal “webview ready” promise rejections when controllers are disposed before becoming ready, and applied it across webview-related tests.
- Updated several test suites to await controller/service initialization and stub previously-unstubbed ConnectionStore reads (connections/groups) to prevent incidental side-effect calls.
- Improved docker-related unit test performance by stubbing
spawnSync(to avoidfix-pathshell-outs) and using fake timers instead of real-time polling delays.
Reviewed changes
Copilot reviewed 15 out of 35 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| localization/xliff/sql-database-projects.zh-Hans.xlf | Auto-generated localization file change (ignored for code review). |
| extensions/mssql/test/unit/webviewPanelController.test.ts | Uses new webview-ready observer helper to avoid unhandled rejections on disposal. |
| extensions/mssql/test/unit/webviewBaseController.test.ts | Uses new webview-ready observer helper to avoid unhandled rejections on disposal. |
| extensions/mssql/test/unit/utils.ts | Adds observeWebviewReady helper for handling disposed-before-ready promise rejection noise in tests. |
| extensions/mssql/test/unit/userSurvey.test.ts | Observes webview readiness to prevent unhandled rejection noise during disposal. |
| extensions/mssql/test/unit/shortcutsConfigurationWebviewController.test.ts | Observes webview readiness to prevent unhandled rejection noise during disposal. |
| extensions/mssql/test/unit/schemaDesignerWebviewManager.test.ts | Observes webview readiness before disposing designers to prevent unhandled rejection noise. |
| extensions/mssql/test/unit/schemaDesignerWebviewController.test.ts | Observes webview readiness to prevent unhandled rejection noise during disposal. |
| extensions/mssql/test/unit/profiler/profilerWebviewController.test.ts | Observes webview readiness for created profiler webviews to prevent unhandled rejection noise. |
| extensions/mssql/test/unit/profiler/profilerController.test.ts | Wraps internal profiler webview disposal to observe readiness and prevent unhandled rejection noise. |
| extensions/mssql/test/unit/perFileConnection.test.ts | Awaits ConnectionManager.initialized and stubs connection store initialization to avoid side-effect noise. |
| extensions/mssql/test/unit/objectExplorerService.test.ts | Adds missing connection/group stubs and awaits OE initialization to avoid background side effects polluting tests. |
| extensions/mssql/test/unit/dockerUtilities.test.ts | Stubs spawnSync and uses fake timers to avoid slow real-time polling and shell-outs in unit tests. |
| extensions/mssql/test/unit/connectionManager.test.ts | Awaits initialization and stubs connection-store initialization/reads to reduce incidental side effects and noise. |
| extensions/mssql/test/unit/connectionDialogWebviewController.test.ts | Stubs fire-and-forget Entra data load and observes webview readiness to avoid disposed-controller rejections. |
| extensions/mssql/test/unit/addFirewallRuleWebviewController.test.ts | Observes webview readiness to prevent unhandled rejection noise during disposal. |
| export function observeWebviewReady(controller: unknown): void { | ||
| const ready = (controller as { _webviewReady?: { promise?: Promise<void> } })?._webviewReady; | ||
| void ready?.promise?.catch(() => { | ||
| /* Swallow the disposed-before-ready rejection in tests. */ | ||
| }); | ||
| } |
| const initializedDeferred = new Deferred<void>(); | ||
| initializedDeferred.resolve(); | ||
| Object.defineProperty(mockConnectionStore, "initialized", { | ||
| get: () => initializedDeferred, | ||
| }); |
| const initializedDeferred = new Deferred<void>(); | ||
| initializedDeferred.resolve(); | ||
| Object.defineProperty(mockConnectionStore, "initialized", { | ||
| get: () => initializedDeferred, | ||
| }); |
| export function observeWebviewReady(controller: unknown): void { | ||
| const ready = (controller as { _webviewReady?: { promise?: Promise<void> } })?._webviewReady; | ||
| void ready?.promise?.catch(() => { | ||
| /* Swallow the disposed-before-ready rejection in tests. */ | ||
| }); | ||
| } |
| const initializedDeferred = new Deferred<void>(); | ||
| initializedDeferred.resolve(); | ||
| Object.defineProperty(mockConnectionStore, "initialized", { | ||
| get: () => initializedDeferred, | ||
| }); |
| const initializedDeferred = new Deferred<void>(); | ||
| initializedDeferred.resolve(); | ||
| Object.defineProperty(mockConnectionStore, "initialized", { | ||
| get: () => initializedDeferred, | ||
| }); |
PR Changes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22449 +/- ##
==========================================
- Coverage 75.63% 75.63% -0.01%
==========================================
Files 412 412
Lines 129871 129886 +15
Branches 8307 8298 -9
==========================================
+ Hits 98230 98239 +9
- Misses 31641 31647 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@Benjin, can you configure the runner to not show a line entry for passed tests? Adds a lot of scrolling to the GitHub runs. |
|
Seems like line endings for loc files are messed up. |
Description
Cleans up several classes of test output pollution:
Code Changes Checklist
npm run test)Reviewers: Please read our reviewer guidelines