-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: replace page.textContent with page.locator in integration tests #15021
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
base: main
Are you sure you want to change the base?
Conversation
|
Co-authored-by: elliott-with-the-longest-name-on-github <76245373+elliott-with-the-longest-name-on-github@users.noreply.github.com>
Co-authored-by: elliott-with-the-longest-name-on-github <76245373+elliott-with-the-longest-name-on-github@users.noreply.github.com>
Co-authored-by: elliott-with-the-longest-name-on-github <76245373+elliott-with-the-longest-name-on-github@users.noreply.github.com>
|
I had argued in the past for something similar, taking advantage of the retrying nature of various Playwright commands. The counterargument at the time was that these commands that automatically retry are more suitable for applications than they are for frameworks, and that we wanted to be able to be more precise about what we were asserting for regarding the specific timing of different things changing than was afforded by the retrying commands. I don't know whether there's been a change of heart about all that since then, which would have been a couple years ago. |
|
I think I would agree with that if that's what we were testing. But the reality is that every Playwright suite we have is not testing SvelteKit the framework, it's testing an application build with SvelteKit the framework. If we want specific, non-application-level tests that drill deeply into instantaneous behavior, we need to accomplish that at a unit-testing level. (All of this is very general, obviously, and I'm sure there are exceptions in either direction.) Right now, I'm just experimenting with this to gauge the efficacy of Copilot's agent capabilities and to try to cut down on flakiness. I've been hammering the test suites locally for the last few days and pretty much every "1/1000" failure on a test that is "correct but flaky" is due to us screaming past a check that needs to wait for the DOM to get up to date with everything else. |
|
That being said, I think the ideal policy here would basically be:
|
|
I don't think this will generally help because we do some magic to make sure the page is loaded before doing the non-polling assertions: kit/packages/kit/test/utils.js Line 117 in 9d1c523
|
|
looks like the change introduced some strict mode violations which will need to be resolved |
|
@benmccann right, it doesn't really change anything for the tests that do "nav, then check page content", but it absolutely does for anything that does "nav, then do anything and check for results". |
|
I think we generally use the appropriate assertion method. Rich had been worried previously that if we did the polling thing we might cover over some framework timing issues and that as framework authors we should be stricter than app authors. The only test I see fail frequently on the CI is one where we're checking network requests and I don't know how to await those properly: #14668 |
page.textContentassertions are flaky because they don't poll—they fetch text content once and fail immediately if the element isn't ready. Playwright recommends usingexpect(locator).toHaveText()which auto-retries.Changes
expect(await page.textContent(sel)).toBe(x)→await expect(page.locator(sel)).toHaveText(x)expect(await page.textContent(sel)).toContain(x)→await expect(page.locator(sel)).toContainText(x)await page.textContent(sel)→await page.locator(sel).textContent()Updated all test files in
packages/kit/test/apps/*:amp,basics,dev-only,embed,no-ssr,options,options-2,prerendered-app-error-pages,writesBefore/After
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.