Repository: electron/electron
Pull request: test: fixup visibility tests

#### Description of Change
- While working on #44136, I discovered that we were not properly cleaning up webcontents in the visibility spec.  32-x-y in particular [continues to have issues with the visibility specs failing](https://ci.appveyor.com/project/electron-bot/electron-x64-testing/builds/51039960/job/dfncljb41qcusi5k/tests). I believe this PR should clean those up.
<!--
Thank you for your Pull Request. Please provide a description above and review
the requirements below.

Contributors guide: https://github.com/electron/electron/blob/main/CONTRIBUTING.md
-->

#### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] PR description included and stakeholders cc'd
- [x] `npm test` passes
- [x] tests are [changed or added](https://github.com/electron/electron/blob/main/docs/development/testing.md)
- [x] [PR release notes](https://github.com/electron/clerk/blob/main/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/main/README.md#examples).

#### Release Notes

Notes: <!-- Please add a one-line description for app developers to read in the release notes, or 'none' if no notes relevant to app developers. Examples and help on special cases: https://github.com/electron/clerk/blob/main/README.md#examples -->none


Changed files:
filename: spec/api-web-contents-view-spec.ts
patch: @@ -8,7 +8,11 @@ import { defer } from './lib/spec-helpers';
 import { closeAllWindows } from './lib/window-helpers';
 
 describe('WebContentsView', () => {
-  afterEach(closeAllWindows);
+  afterEach(async () => {
+    await closeAllWindows();
+    const existingWCS = webContents.getAllWebContents();
+    existingWCS.forEach((contents) => contents.close());
+  });
 
   it('can be instantiated with no arguments', () => {
     // eslint-disable-next-line no-new

filename: spec/api-web-request-spec.ts
patch: @@ -64,7 +64,6 @@ describe('webRequest module', () => {
     protocol.registerStringProtocol('cors', (req, cb) => cb(''));
     defaultURL = (await listen(server)).url + '/';
     http2URL = (await listen(h2server)).url + '/';
-    console.log(http2URL);
   });
 
   after(() => {
@@ -660,7 +659,7 @@ describe('webRequest module', () => {
       });
 
       // Cleanup.
-      after(() => {
+      defer(() => {
         contents.destroy();
         server.close();
         ses.webRequest.onBeforeRequest(null);

filename: spec/visibility-state-spec.ts
patch: @@ -1,4 +1,4 @@
-import { BaseWindow, BrowserWindow, BrowserWindowConstructorOptions, ipcMain, WebContents, WebContentsView } from 'electron/main';
+import { BaseWindow, BrowserWindow, BrowserWindowConstructorOptions, ipcMain, webContents, WebContents, WebContentsView } from 'electron/main';
 
 import { expect } from 'chai';
 
@@ -15,8 +15,11 @@ import { closeWindow } from './lib/window-helpers';
 ifdescribe(process.platform !== 'linux')('document.visibilityState', () => {
   let w: BaseWindow & {webContents: WebContents};
 
-  afterEach(() => {
-    return closeWindow(w);
+  afterEach(async () => {
+    await closeWindow(w);
+    w = null as unknown as BrowserWindow;
+    const existingWCS = webContents.getAllWebContents();
+    existingWCS.forEach((contents) => contents.close());
   });
 
   const load = () => w.webContents.loadFile(path.resolve(__dirname, 'fixtures', 'chromium', 'visibilitystate.html'));