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 file changes on every PR #29915

Open
wants to merge 31 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 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

  • Re-using the 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 action
  • 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

[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

  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

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

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
@seaona seaona changed the title chore: validate page object usage chore: validate page object usage in every PR Jan 28, 2025
@seaona seaona changed the title chore: validate page object usage in every PR chore: validate page object usage in file changes on every PR Jan 28, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [ba02294]
Page Load Metrics (1652 ± 78 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint14462040165015976
domContentLoaded14321960162914670
load14482041165216278
domInteractive2497412010
backgroundConnect982262311
firstReactRender1599492914
getState45710115
initialActions0442105
loadScripts9961447118012460
setupStore792262713
uiStartup165027851927268129
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

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/") ||
Copy link
Contributor

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 ?

Copy link
Contributor Author

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`);
Copy link
Contributor

Choose a reason for hiding this comment

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

🙏🏻

@@ -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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO-NOT-MERGE Pull requests that should not be merged team-extension-platform team-qa QA team
Projects
Status: Needs dev review
Development

Successfully merging this pull request may close these issues.

4 participants