Skip to content

Remove Cypress #52905

Closed
Closed

Description

@huyenltnguyen

Description

This issue to track the work needed for the Cypress removal.

Summary

We have added a significant amount of Playwright tests to the codebase, so I think we're in a good position to start removing Cypress.

I'd propose we proceed by going through each Cypress file and check if the test cases are written in Playwright. Add the tests in if they aren't.

Potential impediments

There is a significant discrepancy I've found and I'm afraid it might complicate the migration work. It's that Cypress has a .task() API that allows us to execute a Node command while Playwright doesn't. With this API, we can choose to work with new user data or certified user data in each test case, but we don't have this flexibility with Playwright.

IMHO, the ability to write tests with new user data is important, as we need to have test coverage for flows such as completing a new step/challenge, claiming a certifications, etc.

A couple approaches I have so far:

  1. Keep using certified user data, but mock APIs when needed, either manually or using HAR files.
    1.1 Mocking manually:
    await page.route('*/**/user/get-session-user', async route => {
    const response = await route.fetch();
    const json = await response.json();
    // /email-sign-up is only accessible if `acceptedPrivacyTerms` is `false`.
    // We need to patch the response in order to access the page.
    json.user.certifieduser.acceptedPrivacyTerms = false;
    json.user.certifieduser.sendQuincyEmail = false;
    await route.fulfill({ json });
    });
    // Intercept the endpoint to prevent `acceptedPrivacyTerms` from being set
    await page.route('*/**/update-privacy-terms', async route => {
    const json = [{ message: 'flash.privacy-updated', type: 'success' }];
    await route.fulfill({ json });
    });

    1.2 Using HAR files: https://playwright.dev/docs/mock#mocking-with-har-files
  2. Run exec() within Playwright tests when needed. Example: https://stackoverflow.com/questions/71397181/node-execute-command-asynchronously-and-read-results-on-completion
  3. Split the Playwright CI flow into one that runs with seed and one that runs with seed:certified-user

I'm still unsure which approach I prefer:

  • (1) is okay, but we lose some confidence as the APIs aren't tested
  • (2) should work, but I have never executed a Node command directly in tests, so I'm not sure if there will be any problems coming from this
  • (3) is probably the ideal way to setup and execute our tests. But the changes will be quite involved as we will need to specify which test suites should be run by which CI flow

Action items

Setup a GHA workflow that runs Playwright test with pnpm run seed

  • Setup a GHA workflow that runs Playwright test with pnpm run seed

Add missing Playwright test cases

Migrate and remove Cypress test files

Remove Cypress

  • Remove all Cypress workflows from GitHubActions
  • Remove the cypress folder
  • Remove Cypress scripts and config (the files are in the root)
  • Remove Cypress as a dependency
  • Remove all data-cy remaining in the codebase

Activity

  1. added
    status: discussing
    scope: tools/scripts
    on Jan 3, 2024
  2. locked and limited conversation to collaborators on Jan 3, 2024
  3. ShaunSHamilton commented on Jan 8, 2024

    @ShaunSHamilton
    Member

    Thanks for tracking this.

    1: No thank you 🙂
    2: This should work, provided:
    a) Tests are not run in parallel
    b) The order of the tests is predictable (or, we have to seed and mock for every test)
    3: Seems like the ideal solution, and, provided we can specify a directory to run for playwrite (i know we can), then it is more like having two e2e folders, and should not require much more work than answering a quick question: "Does this test require the mocked Camper or new Camper"

    For 3, we might even have 3 directories:

    1. e2e/new/
    2. e2e/mocked/
    3. e2e/independent
  4. pinned this issue on Jan 9, 2024
  5. ojeytonwilliams commented on Jan 9, 2024

    @ojeytonwilliams
    Contributor

    I agree that 3) is the way to go for now.

    In the future we can seed multiple users and login to whichever user is appropriate for the test, but that's a little way off.

  6. unpinned this issue on Jan 10, 2024
  7. pinned this issue on May 2, 2024
  8. added
    status: PR in works
    and removed
    status: discussing
    on May 7, 2024
  9. unpinned this issue on Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope: tools/scriptsstatus: PR in works

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions