Skip to content

Commit

Permalink
test: Expand coverage of sourcemap validator (#25115)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

The sourcemap validator script has been updated to cover all build
files. This better protects against sourcemap errors.

The file `offscreen-0.js` is optionally validated. It is expected to be
missing in MV2 builds.

One file is still skipped because validation is failing
(`sentry-install.js`).

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25115?quickstart=1)

## **Related issues**

N/A

## **Manual testing steps**

* Run `yarn dist`
* Run `yarn validate-source-maps`, and see that it succeeds.

## **Screenshots/Recordings**

N/A

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
  • Loading branch information
Gudahtt authored Jul 18, 2024
1 parent 3da665c commit e7660c3
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions development/sourcemap-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,38 @@ start().catch((error) => {

async function start() {
const targetFiles = [
`common-0.js`,
`background-0.js`,
`ui-0.js`,
`scripts/contentscript.js`,
// `scripts/inpage.js`, skipped because the validator can't sample the inlined `scripts/inpage.js` script
'background-0.js',
'common-0.js',
'content-script-0.js',
'ui-0.js',
'scripts/contentscript.js',
'scripts/disable-console.js',
'scripts/policy-load.js',
// TODO: Investigate why these are failing
// 'scripts/sentry-install.js',
// `scripts/inpage.js`,
];
const optionalTargetFiles = ['scripts/app-init.js', 'offscreen-0.js'];
let valid = true;

for (const buildName of targetFiles) {
const fileIsValid = await validateSourcemapForFile({ buildName });
valid = valid && fileIsValid;
}
for (const buildName of optionalTargetFiles) {
const fileIsValid = await validateSourcemapForFile({
buildName,
optional: true,
});
valid = valid && fileIsValid;
}

if (!valid) {
process.exit(1);
}
}

async function validateSourcemapForFile({ buildName }) {
async function validateSourcemapForFile({ buildName, optional = false }) {
console.log(`build "${buildName}"`);
const platform = `chrome`;
// load build and sourcemaps
Expand All @@ -56,6 +69,12 @@ async function validateSourcemapForFile({ buildName }) {
// empty
}
if (!rawBuild) {
if (optional) {
console.warn(
`SourcemapValidator - file not found, skipping "${buildName}"`,
);
return true;
}
throw new Error(
`SourcemapValidator - failed to load source file for "${buildName}"`,
);
Expand Down

0 comments on commit e7660c3

Please sign in to comment.