Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out these two are deprecated in favor of these new settings.
I had odd eslint warnings in vscode but not in the cli, that's how I found out.

"files.readonlyInclude": {
"**/routeTree.gen.ts": true
},
Expand Down
14 changes: 13 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
51 changes: 25 additions & 26 deletions test/failOnConsole.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
let consoleErrorOrConsoleWarnWereCalled = false;

beforeAll(() => {
// replace instead of mutating `console` to avoid infinite loops
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably hasn't been an issue for a while.
Maybe it was an issue with an older implementation of failOnConsole, or with JSDOM?

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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way if a test fails AND has logs, we won't focus on both why the test failed and the fact that the test logged errors/warnings, so that devs can focus on the test failure first, which in most cases will also resolve the logs. Also good for agents I suspect.

Image Image

expect
.soft(
consoleErrorOrConsoleWarnWereCalled,
'errors/warnings were logged to the console during the test'
)
.toBe(false);
}

consoleErrorOrConsoleWarnWereCalled = false;
});
Expand Down
1 change: 0 additions & 1 deletion test/setupBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ beforeEach(async () => {
afterEach(() => {
vi.useRealTimers();

// eslint-disable-next-line vitest/no-standalone-expect
expect
.soft(
document.hasFocus(),
Expand Down
Loading