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

Setup Cypress UI testing #234

Merged
merged 1 commit into from
Aug 5, 2024
Merged

Conversation

Griffin-Sullivan
Copy link
Contributor

@Griffin-Sullivan Griffin-Sullivan commented Jul 30, 2024

Description

This PR adds all of the setup and configuration for running Cypress mock tests. I've also included some changes that will account for adding things like code coverage and e2e testing in the future. At the moment, I wrote one small test to show that the tests are working which checks that the home page loads and the 404 page loads. I also removed a unit test file, as we are planning to add unit tests in a future PR and figured it'd be better to start with a clean slate.

How Has This Been Tested?

So far I have been npm run commands in the ./clients/ui/frontend directory. Making sure the commands I added to package.json work like building, serving, and running mock tests.

To test the changes you can:

  1. cd clients/ui/frontend
  2. npm install
  3. npm run cypress:run:mock

Merge criteria:

  • The commits and have meaningful messages; the author will squash them after approval or will ask to merge with squash.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@ederign
Copy link
Member

ederign commented Jul 31, 2024

@Griffin-Sullivan, I'll be back tomorrow to review this PR. Sorry for the delay on it!

Copy link
Contributor

@lucferbux lucferbux left a comment

Choose a reason for hiding this comment

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

Ok, I've left a couple of comments here, I'm running the commands now, if I find something else I'll re-review it.

@@ -0,0 +1,2 @@
# Test against prod build hosted by lightweight http server
BASE_URL=http://localhost:9001
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll need to do a follow up to better handled .env variables.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've created a follow up doc to handle this, but it's more than enough right now.

import { env, BASE_URL } from '~/src/__tests__/cypress/cypress/utils/testConfig';


const resultsDir = `${env.CY_RESULTS_DIR || 'results'}/${env.CY_MOCK ? 'mocked' : 'e2e'}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to be sure we carry over som of these env variables to either a .env file or a package.json command, where CY_RESULTS_DIR comes from? if we get the default, it might be great to document it somewhere.

videosFolder: `${resultsDir}/videos`,
env: {
MOCK: !!env.CY_MOCK,
coverage: !!env.CY_COVERAGE,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as this, we got a cypress:run:mock_coverage command with that env variable set to true, but here it will be always false, should we add that command or just handle this?

}),
);

export const BASE_URL = env.BASE_URL || '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok great, we'll need to do follow ups with env variables, but head to a great start here.

@ederign
Copy link
Member

ederign commented Aug 1, 2024

@Griffin-Sullivan can you also update ../ui/frontend/docs/dev-setup.md together with this PR?

@ederign
Copy link
Member

ederign commented Aug 1, 2024

@Griffin-Sullivan could you please also reintroduce test runs in GHA? #237

@Griffin-Sullivan Griffin-Sullivan force-pushed the cypress branch 2 times, most recently from b0f9495 to de49516 Compare August 2, 2024 13:33
@Griffin-Sullivan
Copy link
Contributor Author

@ederign Ok I updated everything if you want to take another look

@ederign
Copy link
Member

ederign commented Aug 5, 2024

/ok-to-test

1 similar comment
@tarilabs
Copy link
Member

tarilabs commented Aug 5, 2024

/ok-to-test

Copy link
Contributor

@lucferbux lucferbux left a comment

Choose a reason for hiding this comment

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

There's only a couple of nits left, but really great work here!!

## Cypress Tests
Copy link
Contributor

Choose a reason for hiding this comment

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

Just one nit, can you update the CONTRIBUTING.MD file?
Thre're the Debugging and Testing section, there you can put something like:

See [frontend testing guidelines](docs/testing.md) for more information.


Single command to run all Cypress tests or a specific test (build frontend, start HTTP server, run Cypress):
```bash
Copy link
Contributor

Choose a reason for hiding this comment

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

leave a blank space: MD031/blanks-around-fences


To best match production, build the frontend and use a lightweight HTTP server to host the files. This method will require manual rebuilds when changes are made to the dashboard frontend code.
```bash
Copy link
Contributor

Choose a reason for hiding this comment

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

leave a blan space: MD031/blanks-around-fences


To run all Cypress tests or a specific test headless
```bash
Copy link
Contributor

Choose a reason for hiding this comment

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

same: MD031/blanks-around-fences

"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"cypress:run": "cypress run -b chrome --project src/__tests__/cypress",
"cypress:run:mock": "CY_MOCK=1 npm run cypress:run -- ",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"cypress:run:mock": "CY_MOCK=1 npm run cypress:run -- ",
"cypress:run:mock": "CY_MOCK=1 npm run cypress:run -- ",
"cypress:run": "cypress run -b chrome --project src/__tests__/cypress",
"cypress:open": "cypress open --project src/__tests__/cypress",

Can we add cypress:open too, to have the cypress dashboard? It's quite handy and works really great to debut stuff, if you like that, we can add it to the testing docs too.

Copy link
Contributor

Choose a reason for hiding this comment

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

In the dashboard docs:

There are two commands to run Cypress mock tests (always use the `:mock` variants).
- `open`: Open the Cypress GUI
  \`\`\`bash
  npm run cypress:open:mock
  \`\`\`
- `run`: Run all Cypress tests or a specific test headless
  \`\`\`bash
  npm run cypress:run:mock

  npm run cypress:run:mock -- --spec "**/testfile.cy.ts"
  \`\`\`

Signed-off-by: Griffin-Sullivan <gsulliva@redhat.com>
Copy link
Contributor

@lucferbux lucferbux left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link

@lucferbux: changing LGTM is restricted to collaborators

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ederign
Copy link
Member

ederign commented Aug 5, 2024

/ok-to-test

@ederign
Copy link
Member

ederign commented Aug 5, 2024

/approve

@ederign
Copy link
Member

ederign commented Aug 5, 2024

/lgtm

@google-oss-prow google-oss-prow bot added the lgtm label Aug 5, 2024
@ederign
Copy link
Member

ederign commented Aug 5, 2024

/lgtm

Copy link
Member

@tarilabs tarilabs left a comment

Choose a reason for hiding this comment

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

based on #234 (comment)

/approve

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ederign, lucferbux, tarilabs

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit e9fbf26 into kubeflow:main Aug 5, 2024
13 of 14 checks passed
dhirajsb pushed a commit to dhirajsb/model-registry-kfp that referenced this pull request Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants