-
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 file changes 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
Builds ready [ba02294]
Page Load Metrics (1652 ± 78 ms)
Bundle size diffs
|
for (const file of e2eFiles) { | ||
const content = fs.readFileSync(file, 'utf8'); | ||
// Check for the presence of page object imports | ||
const usesPageObjectModel = content.includes("from './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.
Can we use include '/page-objects'
so we don't need to worry about path ?
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.
oh yeahh, definitely better! I've updated the filter 🙏
content.includes("import") && content.includes("from '../../page-objects/"); | ||
|
||
if (!usesPageObjectModel) { | ||
console.error(`\x1b[31mFailure: You need to use Page Object Model in ${file}\x1b[0m`); |
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.
🙏🏻
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 |
Description
This PR adds a github action job, where it checks the changed 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 a small change: 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 actionNext
[TO DO] To discuss if we want to make this action Required, or allow it to fail for some time before hard enforcing it.
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
Local run
Pre-merge author checklist
Pre-merge reviewer checklist