-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
fix(angular): mount cy-root in original location #25965
fix(angular): mount cy-root in original location #25965
Conversation
26 flaky tests on run #44429 ↗︎Details:
|
Test | ||
---|---|---|
... > runs generated spec |
Screenshot
|
specs_list_latest_runs.cy.ts • 1 flaky test • app-e2e
Test | ||
---|---|---|
App/Cloud Integration - Latest runs and Average duration > when no runs are recorded > shows placeholders for all visible specs |
Screenshot
|
cypress-in-cypress-component.cy.ts • 1 flaky test • app-e2e
Test | ||
---|---|---|
Cypress In Cypress CT > default config > redirects to the specs list with error if a spec is not found |
Screenshot
|
studio/studio.cy.ts • 1 flaky test • app-e2e
Test | ||
---|---|---|
Cypress Studio > updates an existing test with a click action |
Screenshot
|
cypress-origin-communicator.cy.ts • 1 flaky test • app-e2e
Test | ||
---|---|---|
Cypress In Cypress Origin Communicator > cy.origin passivity with app interactions > passes upon test reload mid test execution |
Screenshot
|
The first 5 flaky specs are shown, see all 15 specs in Cypress Cloud.
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also trim up the system-tests added. Scaffolding system tests are expensive so if we can tack this on to an existing test that would be ideal. Plus, the system-test added is based on using a project using a custom-root, adding it to the default would make more sense.
You can remove your system-test changes and add:
context('component-index.html', () => {
before(() => {
const cyRoot = document.querySelector(cyRootSelector)!
expect(cyRoot.parentElement === document.body)
document.body.innerHTML = `
<div id="container">
<div data-cy-root></div>
</div>
`
})
it('preserves html hierarchy', () => {
cy.mount(ChildComponent, { componentProperties: { msg: 'Render 1' } })
cy.contains('Render 1')
cy.get(cyRootSelector).should('exist').parent().should('have.id', 'container')
cy.get('#container').should('exist').parent().should('have.prop', 'tagName').should('eq', 'BODY')
// structure persists after teardown
cy.mount(ChildComponent, { componentProperties: { msg: 'Render 2' } })
cy.contains('Render 2')
cy.get(cyRootSelector).should('exist').parent().should('have.id', 'container')
cy.get('#container').should('exist').parent().should('have.prop', 'tagName').should('eq', 'BODY')
})
})
to system-tests/project-fixtures/angular/src/app/mount.cy.ts
. This will also run across all versions of angular for added coverage, and since it's already part of an existing scaffold it will be fast.
npm/angular/src/mount.ts
Outdated
if (parentElement && parentElement?.tagName !== 'HTML') { | ||
parentElement.appendChild(rootElement) | ||
} else { | ||
document.body.appendChild(rootElement) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (parentElement && parentElement?.tagName !== 'HTML') { | |
parentElement.appendChild(rootElement) | |
} else { | |
document.body.appendChild(rootElement) | |
} |
The true fix here is the removal of document.body.appendChild(rootElement)
, we don't need this extra logic since rootElement
is already guaranteed to be in the DOM (getContainerEl()
uses querySelector, so if it wasn't in the DOM it will throw)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't see the mount.cy.ts. You are right, it is a much better idea to inject the different HTML during the test.
I will update my branch based on your suggestion
Will give @jordanpowell88 a chance to review before merging, but this looks good to me. |
Additional details
Steps to test
Throw a .only on
https://github.com/mv740/cypress/blob/e7879be246f0db6e24901ece225eacc12afb3bde/system-tests/test/component_testing_spec.ts#L147
test with
yarn test component_testing
How has the user experience changed?
PR Tasks
cypress-documentation
?type definitions
?