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

chore: validate page object usage in new spec files on every PR #29915

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

seaona
Copy link
Contributor

@seaona seaona commented Jan 27, 2025

Description

This PR adds a github action job, where it checks the new files from a PR, and validates if the e2e spec files are using page object model (by checking the imports of the file).
If not, the job will fail.

The goal is to help bumping the adoption of the page object model in all e2e, currently at ~34%.

How

  • Re-using the get-changed-files-with-git-diff job which checks the file differences, with 2 changes
    • now we store the results in artifacts, given that this job happens in Circle ci, but the present work is done in a github action (because we want to migrate everything in github actions). So if we save that as an artifact we can access it from the github action
    • now we also get the status of the file (A/M/D) to distinguish between new and changed files

Screenshot from 2025-02-04 09-27-12

  • Re-using the existing function for filtering the e2e spec files
  • Using a Typescript file for the github action script, as it will be easier to re-use util functions in the future, if needed. Also it's likely more familiar than bash for most of the people

Open in GitHub Codespaces

Next

  • We are going to make this job required right away, as it applies to new spec files only
  • After some time, when page objects are more adopted, we are going to apply to both new and changed files - to see if Required or not
  • Eventually this should apply to new and changed files, and the job should be always required

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/4053

Manual testing steps

For testing github actions

  1. Check github action test with a spec not using POM and another one using it https://github.com/MetaMask/metamask-extension/actions/runs/13007720258/job/36278205346?pr=29915
  2. Alternatively, create a copy from this branch and change a couple of spec files (using and not using page objects). Then check the github action
  3. Functionality of git diff and e2e quality gate is preserved (check this job)

Screenshot from 2025-02-04 14-08-27

For testing the local script

  1. Create a local branch
  2. Change a spec using page object model
  3. Change another one not using it
  4. Run yarn validate-e2e-page-object-usage
  5. See results

Screenshots/Recordings

Github action result failure

Screenshot from 2025-01-28 10-54-47

Github action success

https://github.com/MetaMask/metamask-extension/actions/runs/13135918521/job/36651161856?pr=29915

Screenshot from 2025-02-04 14-03-48

Local run

Screenshot from 2025-01-28 11-08-32

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-qa QA team label Jan 27, 2025
@@ -379,6 +379,9 @@ jobs:
root: .
paths:
- changed-files
- store_artifacts:
path: changed-files
destination: changed-files
Copy link
Contributor Author

Choose a reason for hiding this comment

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

before, we were just reading from the files, as the jobs that needed this were all in circle ci.
Now we need to store the results as an artifact, because we need to access the result from github actions too.


fetchManifestFlagsFromPRAndGit().then((manifestFlags) => {
let timeout;

if (manifestFlags.circleci?.timeoutMinutes) {
timeout = manifestFlags.circleci?.timeoutMinutes;
} else {
const changedOrNewTests = filterE2eChangedFiles();
const changedFiles = readChangedFiles();
const changedOrNewTests = filterE2eChangedFiles(changedFiles);
Copy link
Contributor Author

@seaona seaona Jan 28, 2025

Choose a reason for hiding this comment

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

this is due to a change in the filterE2eChangedFiles as now it accepts the files in the func argument, so it can also be re-used in the github action job

console.log('Owner', owner);
console.log('Repository', repository);
console.log('url', `https://circleci.com/api/v2/project/gh/${owner}/${repository}/pipeline?branch=${branch}`);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

leaving the console logs intentionally to make debugging easier in case it's needed

@seaona seaona marked this pull request as ready for review January 28, 2025 10:34
@seaona seaona requested a review from a team as a code owner January 28, 2025 10:34
@@ -29,10 +29,10 @@ function readChangedFiles() {
/**
* Filters the list of changed files to include only E2E test files within the 'test/e2e/' directory.
*
* @returns {<string[]>} An array of filtered E2E test file paths.
* @param {string[]} changedFiles - An array of changed file paths to filter.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: can we rename to changedFilesPaths to reflect the param more?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense, thank you!!

@metamaskbot
Copy link
Collaborator

Builds ready [4702302]
Page Load Metrics (1863 ± 89 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30623381730507243
domContentLoaded15592254185218087
load15632280186318589
domInteractive26103442311
backgroundConnect84617115
firstReactRender1698542813
getState573192110
initialActions01000
loadScripts10631692133915977
setupStore86121209
uiStartup182426722203256123
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Contributor

Choose a reason for hiding this comment

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

How about calling this file .github/scripts/shared/circle-artifacts.ts?

Also, the file .devcontainer/download-builds.ts is doing extremely similar things. Can we make them both run the same shared code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, that's a great point 🔥 pushing some changes and will ask for re-review 🙇‍♀️

Copy link
Contributor

Choose a reason for hiding this comment

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

If you're up for it, this looks like a great PR to migrate this file to TS. If you get into some really sticky situation, don't worry about it, but I think it might be straightforward.

Copy link
Contributor Author

@seaona seaona Jan 29, 2025

Choose a reason for hiding this comment

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

👋 @HowardBraham thanks for the comment! So I changed it to TS but then I fond that we also need to change the run-all.js and possibly a couple of more files? So I think we could leave it out of scope of this PR, but let me know if you think otherwise 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I was slightly scared of that, okay leave it alone 🙂

@metamaskbot
Copy link
Collaborator

Builds ready [41427bd]
Page Load Metrics (1877 ± 95 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint41521731803371178
domContentLoaded15462154183818187
load15542176187719795
domInteractive2787472010
backgroundConnect1086432713
firstReactRender1698372512
getState55815157
initialActions01000
loadScripts10901617134716278
setupStore85822199
uiStartup178926122134227109
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)


return jobs;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ this logic is now in circle-artifacts file, as it's shared with the validate-page-object scriptl, as per @HowardBraham 's recommendation

@metamaskbot
Copy link
Collaborator

Builds ready [9e15a13]
Page Load Metrics (1800 ± 70 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30921651721355170
domContentLoaded15172120178013766
load15262166180014670
domInteractive25141493014
backgroundConnect96525189
firstReactRender17103532914
getState411721
initialActions0442105
loadScripts10921660130113967
setupStore882252412
uiStartup18092585209220196
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@seaona seaona added the DO-NOT-MERGE Pull requests that should not be merged label Jan 30, 2025
@seaona
Copy link
Contributor Author

seaona commented Jan 30, 2025

ℹ️ One last thing left to update, based on the platform team feedback: apply the rule only to new files (not changed) -- I'll work in this at the end of the day today and tmrr morning

@seaona seaona changed the title chore: validate page object usage in file changes on every PR chore: validate page object usage in new spec files on every PR Feb 4, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [3bd0661]
Page Load Metrics (1806 ± 103 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint34022851726378182
domContentLoaded148522431779210101
load149022531806215103
domInteractive25111502713
backgroundConnect983302311
firstReactRender15102512813
getState45216147
initialActions01000
loadScripts10351704129217885
setupStore78416199
uiStartup171925892089272131
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@seaona seaona added area-qa Relating to QA work (Quality Assurance) and removed DO-NOT-MERGE Pull requests that should not be merged labels Feb 4, 2025
}

// Run the verification for new files only
verifyE2ePageObjectsUsage('A').catch((error) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the future this can be changed, to 'both' whenever we want to verify both Added and Modified files

try {
const content = fs.readFileSync(file, 'utf8');
// Check for the presence of page object imports
const usesPageObjectModel = content.includes('./page-objects/');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this has an underlying assumption that all specs that use POM will have at least 1 page-objects import, and that those who don't, won't have any.
This could be 'tricked' or not apply in some cases but it's hard to tell when would this happen

Copy link
Contributor

Choose a reason for hiding this comment

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

agree, we can keep it like this for now and adjust it in the future if any exceptions arise

@metamaskbot
Copy link
Collaborator

Builds ready [fdea90e]
Page Load Metrics (1477 ± 33 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1370161214806732
domContentLoaded1364160414616531
load1368161214776933
domInteractive236934168
backgroundConnect85821189
firstReactRender1496422814
getState49521
initialActions01000
loadScripts934112610384823
setupStore78314188
uiStartup15822174173214570
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-qa Relating to QA work (Quality Assurance) team-extension-platform team-qa QA team
Projects
Status: Needs dev review
Development

Successfully merging this pull request may close these issues.

5 participants