-
Notifications
You must be signed in to change notification settings - Fork 5k
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
base: main
Are you sure you want to change the base?
Conversation
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. |
@@ -379,6 +379,9 @@ jobs: | |||
root: . | |||
paths: | |||
- changed-files | |||
- store_artifacts: | |||
path: changed-files | |||
destination: changed-files |
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.
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); |
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.
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
.github/scripts/utils/utils.ts
Outdated
console.log('Owner', owner); | ||
console.log('Repository', repository); | ||
console.log('url', `https://circleci.com/api/v2/project/gh/${owner}/${repository}/pipeline?branch=${branch}`); | ||
|
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.
leaving the console logs intentionally to make debugging easier in case it's needed
test/e2e/changedFilesUtil.js
Outdated
@@ -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. |
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.
Nit: can we rename to changedFilesPaths
to reflect the param more?
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.
make sense, thank you!!
Co-authored-by: Danica Shen <[email protected]>
Builds ready [4702302]
Page Load Metrics (1863 ± 89 ms)
Bundle size diffs
|
.github/scripts/utils/utils.ts
Outdated
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.
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?
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.
Thank you, that's a great point 🔥 pushing some changes and will ask for re-review 🙇♀️
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 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.
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.
👋 @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 🙏
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.
Yeah I was slightly scared of that, okay leave it alone 🙂
Builds ready [41427bd]
Page Load Metrics (1877 ± 95 ms)
Bundle size diffs
|
|
||
return jobs; | ||
} | ||
|
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.
ℹ️ this logic is now in circle-artifacts file, as it's shared with the validate-page-object scriptl, as per @HowardBraham 's recommendation
Co-authored-by: Howard Braham <[email protected]>
Builds ready [9e15a13]
Page Load Metrics (1800 ± 70 ms)
Bundle size diffs
|
ℹ️ 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 |
Builds ready [3bd0661]
Page Load Metrics (1806 ± 103 ms)
Bundle size diffs
|
} | ||
|
||
// Run the verification for new files only | ||
verifyE2ePageObjectsUsage('A').catch((error) => { |
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.
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/'); |
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.
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
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.
agree, we can keep it like this for now and adjust it in the future if any exceptions arise
Builds ready [fdea90e]
Page Load Metrics (1477 ± 33 ms)
Bundle size diffs
|
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
get-changed-files-with-git-diff
job which checks the file differences, with 2 changesNext
Related issues
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/4053
Manual testing steps
For testing github actions
For testing the local script
yarn validate-e2e-page-object-usage
Screenshots/Recordings
Github action result failure
Github action success
https://github.com/MetaMask/metamask-extension/actions/runs/13135918521/job/36651161856?pr=29915
Local run
Pre-merge author checklist
Pre-merge reviewer checklist