From fd49ac2f3f2aa47a0979674844d8eaea595554cb Mon Sep 17 00:00:00 2001 From: John Kleinschmidt Date: Mon, 2 Dec 2024 16:43:06 -0500 Subject: [PATCH] find out what spec is leaving stuff open --- spec/index.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/index.js b/spec/index.js index ab8c2f0db1..5d0565fab8 100644 --- a/spec/index.js +++ b/spec/index.js @@ -1,4 +1,4 @@ -const { app, protocol } = require('electron'); +const { app, protocol, BaseWindow, webContents } = require('electron'); const fs = require('node:fs'); const path = require('node:path'); @@ -108,9 +108,22 @@ app.whenReady().then(async () => { // 3. regular `afterEach` hooks run. // 4. `afterAll` hook runs here to verify that there are no windows left open const { runCleanupFunctions } = require('./lib/spec-helpers'); - mocha.suite.on('suite', function attach (suite) { + function attach (suite) { suite.afterEach('cleanup', runCleanupFunctions); suite.on('suite', attach); + } + mocha.suite.on('suite', (suite) => { + attach(suite); + suite.afterAll('end of test cleanup', async () => { + const windowsLeftOpen = BaseWindow.getAllWindows().length; + const webContentsDangling = webContents.getAllWebContents().length; + if (windowsLeftOpen > 0) { + console.log(`WARNING!!!!!!!!!! ${suite.fullTitle()} ${path.basename(suite.file)} left ${windowsLeftOpen} windows open!`); + } + if (webContentsDangling > 0) { + console.log(`WARNING!!!!!!!!!! ${suite.fullTitle()} ${path.basename(suite.file)} left ${webContentsDangling} WebContents dangling!`); + } + }); }); if (!process.env.MOCHA_REPORTER) {