From 3e4cc9eb233eeaf2eb21d765602b1cab30e6a5c1 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 18 Mar 2026 14:40:25 +0000 Subject: [PATCH 1/2] Tweak `vitest/no-standalone-expect` rule --- eslint.config.js | 14 +++++++++++- test/failOnConsole.ts | 51 +++++++++++++++++++++---------------------- test/setupBrowser.ts | 1 - 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index e82c38659a..9343eea553 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -960,7 +960,19 @@ copy( 'vitest/no-mocks-import': 1, 'vitest/no-restricted-matchers': 0, 'vitest/no-restricted-vi-methods': 0, - 'vitest/no-standalone-expect': 1, + 'vitest/no-standalone-expect': [ + 1, + { + additionalTestBlockFunctions: [ + 'beforeAll', + 'beforeEach', + 'afterAll', + 'afterEach', + 'aroundAll', + 'aroundEach' + ] + } + ], 'vitest/no-test-prefixes': 1, 'vitest/no-test-return-statement': 1, 'vitest/no-unneeded-async-expect-function': 1, diff --git a/test/failOnConsole.ts b/test/failOnConsole.ts index c5acfa094f..a7b990a6fc 100644 --- a/test/failOnConsole.ts +++ b/test/failOnConsole.ts @@ -1,37 +1,36 @@ let consoleErrorOrConsoleWarnWereCalled = false; beforeAll(() => { - // replace instead of mutating `console` to avoid infinite loops - globalThis.console = { - ...console, - error(...params) { - if ( - params[0] instanceof Error && - params[0].message === 'ResizeObserver loop completed with undelivered notifications.' - ) { - return; - } - - consoleErrorOrConsoleWarnWereCalled = true; - console.log(...params); - }, - warn(...params) { - consoleErrorOrConsoleWarnWereCalled = true; - console.log(...params); + console.error = (...params) => { + if ( + params[0] instanceof Error && + params[0].message === 'ResizeObserver loop completed with undelivered notifications.' + ) { + return; } + + consoleErrorOrConsoleWarnWereCalled = true; + console.log(...params); + }; + + console.warn = (...params) => { + consoleErrorOrConsoleWarnWereCalled = true; + console.log(...params); }; }); -afterEach(() => { - // Wait for both the test and `afterEach` hooks to complete to ensure all logs are caught +afterEach(({ task, signal }) => { + // Wait for the test and all `afterEach` hooks to complete to ensure all logs are caught onTestFinished(() => { - // eslint-disable-next-line vitest/no-standalone-expect - expect - .soft( - consoleErrorOrConsoleWarnWereCalled, - 'console.error() and/or console.warn() were called during the test' - ) - .toBe(false); + // avoid failing test runs twice + if (task.result!.state !== 'fail' || signal.aborted) { + expect + .soft( + consoleErrorOrConsoleWarnWereCalled, + 'errors/warnings were logged to the console during the test' + ) + .toBe(false); + } consoleErrorOrConsoleWarnWereCalled = false; }); diff --git a/test/setupBrowser.ts b/test/setupBrowser.ts index f9553b58ba..1823974c50 100644 --- a/test/setupBrowser.ts +++ b/test/setupBrowser.ts @@ -90,7 +90,6 @@ beforeEach(async () => { afterEach(() => { vi.useRealTimers(); - // eslint-disable-next-line vitest/no-standalone-expect expect .soft( document.hasFocus(), From 2dc44ae82098d531151f870b80c3e0956e6fdadb Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 18 Mar 2026 14:50:12 +0000 Subject: [PATCH 2/2] update settings.json --- .vscode/settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2ed08e616f..b76ddf9a99 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,8 +8,8 @@ "editor.defaultFormatter": "oxc.oxc-vscode", "editor.formatOnSave": true, "editor.formatOnSaveMode": "file", - "typescript.enablePromptUseWorkspaceTsdk": true, - "typescript.tsdk": "node_modules/typescript/lib", + "js/ts.tsdk.promptToUseWorkspaceVersion": true, + "js/ts.tsdk.path": "node_modules/typescript/lib", "files.readonlyInclude": { "**/routeTree.gen.ts": true },