Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2605182
fix: prevent infinite loop on prettyDOM calls
tsirlucas Jan 14, 2025
f780722
fix lint
tsirlucas Jan 14, 2025
0b13cbf
use MAX_SAFE_INTEGER instead of MAX_VALUE
tsirlucas Jan 15, 2025
6be46fe
add test case to handle large nested DOM in prettyDOM calls
tsirlucas Jan 15, 2025
f815b0a
handle browser crash in playwright provider
tsirlucas Jan 15, 2025
9b02f20
fix lint issues
tsirlucas Jan 15, 2025
ed16cda
bump test counter
tsirlucas Jan 15, 2025
0841caf
Merge branch 'main' into main
tsirlucas Jan 15, 2025
34ff688
adjust test count
tsirlucas Jan 15, 2025
7c00ff2
Merge branch 'main' of https://github.com/tsirlucas/vitest
tsirlucas Jan 15, 2025
c0b9c08
rebump test count
tsirlucas Jan 15, 2025
4e1adfc
Merge branch 'main' into main
tsirlucas Jan 15, 2025
e2f36ac
fix browser crash test
tsirlucas Jan 15, 2025
3a343d3
Merge branch 'main' of https://github.com/tsirlucas/vitest
tsirlucas Jan 15, 2025
8ee78bc
force maxDepth to be under predefined value
tsirlucas Jan 15, 2025
4d1728d
bump test counter
tsirlucas Jan 15, 2025
32a967f
update snapshot
tsirlucas Jan 15, 2025
9c2f84d
update test counters
tsirlucas Jan 15, 2025
2189730
add bigger timeout to large dom test
tsirlucas Jan 15, 2025
3bcb162
increase large dom test timeout
tsirlucas Jan 15, 2025
69299a2
exit gracefully on webdriver crash
tsirlucas Jan 15, 2025
8f6f9a6
Merge branch 'main' into main
tsirlucas Jan 15, 2025
d88b2a1
fix lint
tsirlucas Jan 15, 2025
f10d107
Merge branch 'main' of https://github.com/tsirlucas/vitest
tsirlucas Jan 15, 2025
fc4f64a
better crashing strategy
tsirlucas Jan 15, 2025
346c2ef
dont test crash on webkit
tsirlucas Jan 15, 2025
39bc395
undo webdriver changes
tsirlucas Jan 15, 2025
77b8972
remove unneeded code
tsirlucas Jan 15, 2025
1a90e07
better assertion for prettyDOM test
tsirlucas Jan 15, 2025
0002e1b
update maxContent for readability
tsirlucas Jan 15, 2025
891036d
adjust test so test counter is not dynamic
tsirlucas Jan 15, 2025
ed80dc4
use different depth and maxContent values for better snapshots
tsirlucas Jan 16, 2025
6307327
use test.runIf in browser crashing test
tsirlucas Jan 16, 2025
90600e8
pr review fix
tsirlucas Jan 16, 2025
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
6 changes: 6 additions & 0 deletions packages/browser/src/node/providers/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ export class PlaywrightBrowserProvider implements BrowserProvider {
})
}

// unhandled page crashes will hang vitest process
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was making the tests hang #7249 (comment)

page.on('crash', () => {
const session = this.project.vitest._browserSessions.getSession(sessionId)
session?.reject(new Error('Page crashed when executing tests'))
})

return page
}

Expand Down
4 changes: 3 additions & 1 deletion packages/utils/src/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ export function stringify(
})
}

// Prevents infinite loop https://github.com/vitest-dev/vitest/issues/7249
const nextMaxDepth = maxDepth === Infinity ? Number.MAX_SAFE_INTEGER : Math.floor(maxDepth / 2)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MAX_NUMBER would still crash the browser, so Im using MAX_SAFE_INTEGER which works fine. If you want me to use any specific number, please send it here so I can replace

return result.length >= MAX_LENGTH && maxDepth > 1
? stringify(object, Math.floor(maxDepth / 2))
? stringify(object, nextMaxDepth)
: result
}

Expand Down
30 changes: 30 additions & 0 deletions test/browser/test/__snapshots__/utils.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,33 @@ exports[`prints the element with attributes 1`] = `
</div>
</body>"
`;

exports[`should handle large nested DOM 1`] = `
"<body>






<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div … />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>..."
`;
15 changes: 15 additions & 0 deletions test/browser/test/browser-crash.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { it } from 'vitest';

Check failure on line 1 in test/browser/test/browser-crash.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Extra semicolon

it.skip('fails gracefully when browser crashes', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dont know what to do with this test. It reproduces the issue where browser crashes, but if I enable it it will break the pipeline

Copy link
Member

Choose a reason for hiding this comment

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

You can add this test to fixtures and create a new test file in test/browser/specs to run the fixture and assert that it fails correctly

let parentDiv = document.createElement("div")

Check failure on line 4 in test/browser/test/browser-crash.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

'parentDiv' is never reassigned. Use 'const' instead

Check failure on line 4 in test/browser/test/browser-crash.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Strings must use singlequote
let currentDiv = parentDiv;

Check failure on line 5 in test/browser/test/browser-crash.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Extra semicolon

// Simulate crash by adding a large number of nodes
for (let i = 0; i < 20000; i++) {
const newDiv = document.createElement("div")

Check failure on line 9 in test/browser/test/browser-crash.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Strings must use singlequote
currentDiv.appendChild(newDiv)
currentDiv = newDiv
}

document.body.appendChild(parentDiv)
})

Check failure on line 15 in test/browser/test/browser-crash.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Newline required at end of file but not found
16 changes: 16 additions & 0 deletions test/browser/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,19 @@

expect(await commands.stripVTControlCharacters(prettyDOM())).toMatchSnapshot()
})

test('should handle large nested DOM', async () => {
const depth = 20000;

Check failure on line 42 in test/browser/test/utils.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Extra semicolon

// if we try to manipulate dom to add 20000 divs, we get

Check failure on line 44 in test/browser/test/utils.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Trailing spaces not allowed
// max depth exceeded error
const openingTags = "<div>".repeat(depth);

Check failure on line 46 in test/browser/test/utils.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Strings must use singlequote

Check failure on line 46 in test/browser/test/utils.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Extra semicolon
const closingTags = "</div>".repeat(depth);
const domString = `${openingTags}${closingTags}`;

const parentDiv = document.createElement("div");
parentDiv.innerHTML = domString;

document.body.appendChild(parentDiv);
expect(await commands.stripVTControlCharacters(prettyDOM())).toMatchSnapshot()
});
Loading