New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(browser): run test files in isolated iframes #5036
Conversation
✅ Deploy Preview for fastidious-cascaron-4ded94 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
8d06522
to
701b365
Compare
60baafc
to
4189f1a
Compare
@userquin @Aslemammad I don't really like that we run all tests in parallel - this makes it impossible to use keyboard events for example. Should we default to running tests one after another? |
What do you mean about using keyboard events? related to this issue #4918? IIRC you cannot simulate |
Yes, look into the open PR. (I didn't test it yet, it's just a drafter POC). But the idea is that we need to have an element with a focus but if we run tests in parallel the focus can shift between iframes and elements at any time. |
I think there is no need, using Add it('test focus', async () => {
const host2 = document.createElement('div')
host2.setAttribute('id', 'host2')
document.body.appendChild(host2)
const btn1 = document.createElement('button')
btn1.innerHTML = 'Click me 1'
btn1.addEventListener('keydown', (e) => {
console.log(e)
})
btn1.addEventListener('keyup', (e) => {
console.log(e)
})
host2.appendChild(btn1)
const btn2 = document.createElement('button')
btn2.innerHTML = 'Click me 2'
host2.appendChild(btn2)
expect(document.activeElement).toBe(document.body)
btn1.focus()
expect(document.activeElement).toBe(btn1)
btn2.focus()
expect(document.activeElement).toBe(btn2)
btn1.focus()
expect(document.activeElement).toBe(btn1)
await new Promise(resolve => setTimeout(resolve, 100))
btn1.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab' }))
btn1.dispatchEvent(new KeyboardEvent('keyup', { key: 'Tab' }))
/* btn1.dispatchEvent(new KeyboardEvent('keypress', {
key: 'Tab',
view: window,
bubbles: true,
cancelable: true,
/!* code: 'Tab',
isComposing: true,
charCode: 0,
keyCode: 9,
which: 9,
composed: true,
location: 0,
view: window,
bubbles: true,
cancelable: true,
shiftKey: false,
ctrlKey: false,
altKey: false,
metaKey: false, *!/
})) */
await new Promise(resolve => setTimeout(resolve, 100))
console.log(document.activeElement)
// THIS WILL FAIL
// expect(document.activeElement).toBe(btn2)
}) |
There is a great need for that. Dispatching keyboard event doesn't work the same way as the user would do it. In the real world, the keyboard triggers multiple events and it is not possible to emulate the order of it down to the microtask in the browser (just like the click), so we need to do it through a webdriver API or google devtools API.
|
Once the tests finish, the focus will be on the last focus test (when opening/focusing the browser). |
86713a0
to
eac0817
Compare
Description
This PR changes how Vitest runs browser tests internally. This is a successor to #3584, but without any visuals.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.