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 }, 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(),