Skip to content
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: Fix missing it.skip function in Angular tests #23829

Merged
merged 4 commits into from
Sep 15, 2022

Conversation

mike-plummer
Copy link
Contributor

@mike-plummer mike-plummer commented Sep 14, 2022

User facing changelog

  • Fixes an issue where it.skip was not available in Angular component tests

Additional details

zone.js/testing library patches Mocha to be "zone-aware", but the patch does not include it.skip. This is written up in that repo under this issue, but it's not seeing any movement. Since this is a relatively trivial fix on our end and has annoying impacts on our users it seemed better to patch on our side pending any potential fix from that library.

While debugging this issue I wrote up tests that validate skip and only for all major Mocha syntax blocks - I've added them to this PR even though only isn't really related since they seemed like useful checks to have in case Zone breaks these in the future

Steps to test

System Tests should validate

Manual validation would involve creating an NG project, installing Cypress and patching in updated angular package and validating that a test with it.skip does not fail with a parsing error

How has the user experience changed?

Users should be able to use it.skip in Angular tests

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [na] Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 14, 2022

Thanks for taking the time to open a PR!

Copy link
Contributor

@ZachJW34 ZachJW34 left a comment

Choose a reason for hiding this comment

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

Works great! One small comment on system tests

system-tests/test/component_testing_spec.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

Nice job fixing it, I think we can do a better test w/ Cypress in Cypress, lmk what you think!!

systemTests.it(`v${majorVersion} Zone.JS does not break Mocha`, {
project: `angular-${majorVersion}`,
spec: 'src/app/zonejs-mocha-skip.cy.ts,src/app/zonejs-mocha-only.cy.ts',
testingType: 'component',
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think this is the wrong place for this test. Also, we are not actually verifying that it.skip actually does what's it supposed to, only that it is available.

We could move this to a Cypress in Cypress test in app/cypress/e2e, and we could then assert against the command log that the correct number of tests are executed and/or skipped? That would verify not only that it works, but skip is the correct one (since we will see it visually marked as skipped in the Commanad Log, as well as the number of executed tests).

Copy link
Contributor

Choose a reason for hiding this comment

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

You would add it here: https://github.com/cypress-io/cypress/blob/develop/packages/app/cypress/e2e/cypress-in-cypress-component.cy.ts

If you haven't seen the Cypress in Cypress yet it's really cool - you can still use this project (in system tests) but you can now assert things are actually happening in the UI, too.

What do you think?

Copy link
Contributor Author

@mike-plummer mike-plummer Sep 15, 2022

Choose a reason for hiding this comment

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

@lmiller1990 It looks like cypress-in-cypress is configured to use React for CT, so were you thinking we would stand up a new cypress-in-cypress permutation using Angular?

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to use cypress-in-cypress to test against the command log, we have an existing pattern where we point Cypress at the command log inside of system-tests here. I could go either way, but I'm a fan of testing as much as possible in system-tests and only using cy-in-cy if absolutely required since the system-tests will always be less costly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took the approach Zach proposed to write some tests to validate the behavior of skip and only. Definitely not as elegant as cypress-in-cypress, but very performant and seems to provide the validation that was requested

Copy link
Contributor

@lmiller1990 lmiller1990 Sep 15, 2022

Choose a reason for hiding this comment

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

Oh I hadn't seen that @ZachJW34, neat.

The reason I suggested cypress-in-cypress is we have these really cool helpers:

waitForSpecToFinish(expectedResults?: {
passCount?: number
failCount?: number
pendingCount?: number
}): void
.

You can do

cy.waitForSpecToFinish({
  passCount: 4
  failCount: 0
  pendingCount: 1
})

Which is exactly what we want here - it's way more readable, at least to me. Maybe we should find a way to share more of these commands between cypress-in-cypress and system-tests in the future.

Anyway, as long as we've got something preventing this regression, I'm happy.

@cypress
Copy link

cypress bot commented Sep 15, 2022



Test summary

40020 0 3359 0Flakiness 2


Run details

Project cypress
Status Passed
Commit f274c81
Started Sep 15, 2022 3:57 PM
Ended Sep 15, 2022 4:13 PM
Duration 15:27 💡
OS Linux Debian - 11.3
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

config_env.cy.ts Flakiness
1 cy.origin- Cypress.config() > serializable > overwrites different values in secondary, even if the Cypress.config() value does not exist in the primary
commands/files.cy.ts Flakiness
1 cy.origin files > .fixture()

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@lmiller1990 lmiller1990 self-requested a review September 15, 2022 23:41
@lmiller1990 lmiller1990 merged commit 64c0f45 into develop Sep 15, 2022
@lmiller1990 lmiller1990 deleted the zachw/angular-restore-mocha-methods branch September 15, 2022 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

it.skip not working in Angular component test
3 participants