Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,20 @@ jobs:
uses: actions/download-artifact@v4
with:
name: build-source-${{ runner.os }}-${{ github.sha }}
- name: Install Google Chrome
- name: Install browsers
if: ${{ matrix.package-name == '@metamask/snaps-controllers' || matrix.package-name == '@metamask/snaps-execution-environments' || matrix.package-name == '@metamask/snaps-utils' }}
uses: MetaMask/action-retry-command@v1
with:
command: yarn install-chrome
command: yarn playwright install --with-deps --only-shell chromium firefox
Copy link
Member

Choose a reason for hiding this comment

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

How will this work locally? Do you need to run any commands besides yarn and yarn test to run browser tests locally?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, Vitest will tell you to run yarn playwright install on the first time running yarn test.

- name: Run tests
uses: MetaMask/action-retry-command@v1
with:
command: yarn workspace ${{ matrix.package-name }} run test
- name: Run Firefox tests
if: ${{ matrix.package-name == '@metamask/snaps-controllers' || matrix.package-name == '@metamask/snaps-execution-environments' || matrix.package-name == '@metamask/snaps-utils' }}
uses: MetaMask/action-retry-command@v1
with:
command: yarn workspace ${{ matrix.package-name }} run test:browser:firefox
- name: Get coverage folder
id: get-coverage-folder
run: |
Expand Down
44 changes: 0 additions & 44 deletions .github/workflows/update-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,39 +179,6 @@ jobs:
.nvmrc
packages/examples/packages

update-chrome:
name: Update Chrome
runs-on: ubuntu-latest
if: ${{ inputs.dependabot == true && contains(inputs.pull-request-title, 'chromedriver') }}
needs:
- prepare
- dedupe-yarn-lock
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.PULL_REQUEST_UPDATE_TOKEN }}
PR_NUMBER: ${{ inputs.pull-request != 0 && inputs.pull-request || github.event.issue.number }}
- name: Restore yarn.lock
uses: actions/download-artifact@v4
with:
name: yarn-lock-${{ needs.prepare.outputs.COMMIT_SHA }}
- name: Checkout and setup environment
uses: MetaMask/action-checkout-and-setup@v1
with:
is-high-risk-environment: false
- name: Update Chrome
run: yarn update-chrome
- name: Save install script
uses: actions/upload-artifact@v4
with:
name: chrome-install-script-${{ needs.prepare.outputs.COMMIT_SHA }}
path: |
.nvmrc
scripts/install-chrome.sh

commit-result:
name: Commit result
runs-on: ubuntu-latest
Expand All @@ -222,7 +189,6 @@ jobs:
- dedupe-yarn-lock
- regenerate-lavamoat-policies
- update-examples
- update-chrome
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -269,15 +235,5 @@ jobs:
run: |
git add packages/examples/packages
git commit -m "${COMMIT_PREFIX}Update example snaps" || true
- name: Restore install script
if: ${{ inputs.dependabot == true && contains(inputs.pull-request-title, 'chromedriver') }}
uses: actions/download-artifact@v4
with:
name: chrome-install-script-${{ needs.prepare.outputs.COMMIT_SHA }}
- name: Commit install script
if: ${{ inputs.dependabot == true && contains(inputs.pull-request-title, 'chromedriver') }}
run: |
git add scripts/install-chrome.sh
git commit -m "${COMMIT_PREFIX}Update install Chrome script" || true
- name: Push changes
run: git push
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ packages/examples/examples/webpack/index.html

# Ubuntu package files
.deb

# Vitest test failure screenshots
__screenshots__
5 changes: 0 additions & 5 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ logFilters:

nodeLinker: node-modules

packageExtensions:
'@wdio/browser-runner@*':
dependencies:
'@babel/core': '*'

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs
spec: 'https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js'
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"@types/lodash": "^4",
"@types/node": "18.14.2",
"@yarnpkg/types": "^4.0.0",
"chromedriver": "^135.0.0",
"depcheck": "^1.4.7",
"eslint": "^9.11.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -105,18 +104,19 @@
"eslint-plugin-promise": "^7.1.0",
"execa": "^5.1.1",
"favicons": "^7.1.2",
"geckodriver": "^4.2.0",
"jest": "^29.0.2",
"jest-silent-reporter": "^0.6.0",
"lint-staged": "^12.4.1",
"lodash": "^4.17.21",
"minimatch": "^7.4.1",
"playwright": "~1.49.0",
"prettier": "^3.3.3",
"prettier-2": "npm:prettier@^2.8.8",
"prettier-plugin-packagejson": "^2.5.8",
"rimraf": "^4.1.2",
"semver": "^7.5.4",
"simple-git-hooks": "^2.7.0",
"supports-color": "^7.2.0",
"ts-node": "^10.9.1",
"tsx": "^4.19.1",
"typescript": "~5.3.3",
Expand All @@ -132,9 +132,7 @@
"@lavamoat/preinstall-always-fail": false,
"simple-git-hooks": false,
"$root$": false,
"chromedriver": true,
"jest>jest-cli>jest-config>ts-node>@swc/core": false,
"geckodriver": true,
"ts-node>@swc/core": true,
"@swc/core": true,
"favicons>sharp": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ exports[`plugin generates a source map 1`] = `
};
}, {}]
}, {}, [1]);
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJyIiwiZSIsIm4iLCJ0IiwibyIsImkiLCJmIiwiYyIsInJlcXVpcmUiLCJ1IiwiYSIsIkVycm9yIiwiY29kZSIsInAiLCJleHBvcnRzIiwiY2FsbCIsImxlbmd0aCIsIm1vZHVsZSIsIm9uUnBjUmVxdWVzdCIsInJlcXVlc3QiLC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BQSxPQUFBRCxDQUFBO0VBQUE7RUFBQSxPQUFBSixDQUFBO0FBQUE7RUFBQSxjQUFBUSxPQUFBLEVBQUFTLE1BQUEsRUFBQUgsT0FBQTtJQ0NBRyxNQUFBLENBQUFILE9BQUEsQ0FBQUksWUFBQTtNQUFBQztJQUFBO01BQ0FDLE9BQUEsQ0FBQUMsR0FBQTtNQUVBO1FBQUFDLE1BQUE7UUFBQUM7TUFBQSxJQUFBSixPQUFBO01BQ0EsT0FBQUcsTUFBQSxHQUFBQyxFQUFBO0lBQ0EifQ=="
Copy link
Member Author

@Mrtenz Mrtenz Mar 28, 2025

Choose a reason for hiding this comment

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

This changed because of a bump in dependencies responsible for source maps.

//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJyIiwiZSIsIm4iLCJ0IiwibyIsImkiLCJmIiwiYyIsInJlcXVpcmUiLCJ1IiwiYSIsIkVycm9yIiwiY29kZSIsInAiLCJleHBvcnRzIiwiY2FsbCIsImxlbmd0aCIsIm1vZHVsZSIsIm9uUnBjUmVxdWVzdCIsInJlcXVlc3QiLCJjb25zb2xlIiwibG9nIiwibWV0aG9kIiwiaWQiXSwic291cmNlcyI6WyIuLi8uLi9ub2RlX21vZHVsZXMvYnJvd3Nlci1wYWNrL19wcmVsdWRlLmpzIiwiX3N0cmVhbV8wLmpzIl0sInNvdXJjZXNDb250ZW50IjpbIihmdW5jdGlvbigpe2Z1bmN0aW9uIHIoZSxuLHQpe2Z1bmN0aW9uIG8oaSxmKXtpZighbltpXSl7aWYoIWVbaV0pe3ZhciBjPVwiZnVuY3Rpb25cIj09dHlwZW9mIHJlcXVpcmUmJnJlcXVpcmU7aWYoIWYmJmMpcmV0dXJuIGMoaSwhMCk7aWYodSlyZXR1cm4gdShpLCEwKTt2YXIgYT1uZXcgRXJyb3IoXCJDYW5ub3QgZmluZCBtb2R1bGUgJ1wiK2krXCInXCIpO3Roc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csQ0FBQSxHQUFBWCxDQUFBLENBQUFHLENBQUE7VUFBQVMsT0FBQTtRQUFBO1FBQUFiLENBQUEsQ0FBQUksQ0FBQSxLQUFBVSxJQUFBLENBQUFGLENBQUEsQ0FBQUMsT0FBQSxZQUFBZCxDQUFBO1VBQUEsSUFBQUUsQ0FBQSxHQUFBRCxDQUFBLENBQUFJLENBQUEsS0FBQUwsQ0FBQTtVQUFBLE9BQUFJLENBQUEsQ0FBQUYsQ0FBQSxJQUFBRixDQUFBO1FBQUEsR0FBQWEsQ0FBQSxFQUFBQSxDQUFBLENBQUFDLE9BQUEsRUFBQWQsQ0FBQSxFQUFBQyxDQUFBLEVBQUFDLENBQUEsRUFBQUMsQ0FBQTtNQUFBO01BQUEsT0FBQUQsQ0FBQSxDQUFBRyxDQUFBLEVBQUFTLE9BQUE7SUFBQTtJQUFBLFNBQUFMLENBQUEsd0JBQUFELE9BQUEsSUFBQUEsT0FBQSxFQUFBSCxDQUFBLE1BQUFBLENBQUEsR0FBQUYsQ0FBQSxDQUFBYSxNQUFBLEVBQUFYLENBQUEsSUFBQUQsQ0FBQSxDQUFBRCxDQUFBLENBQUFFLENBQUE7SUFBQSxPQUFBRCxDQUFBO0VBQUE7RUFBQSxPQUFBSixDQUFBO0FBQUE7RUFBQSxjQUFBUSxPQUFBLEVBQUFTLE1BQUEsRUFBQUgsT0FBQTtJQ0NBRyxNQUFBLENBQUFILE9BQUEsQ0FBQUksWUFBQTtNQUFBQztJQUFBO01BQ0FDLE9BQUEsQ0FBQUMsR0FBQTtNQUVBO1FBQUFDLE1BQUE7UUFBQUM7TUFBQSxJQUFBSixPQUFBO01BQ0EsT0FBQUcsTUFBQSxHQUFBQyxFQUFBO0lBQ0EiLCJpZ25vcmVMaXN0IjpbXX0="
`;

exports[`plugin processes files using Browserify 1`] = `
Expand Down
7 changes: 2 additions & 5 deletions packages/snaps-controllers/.depcheckrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
"@metamask/eslint-*",
"@types/*",
"@typescript-eslint/*",
"@wdio/*",
"@vitest/coverage-istanbul",
"eslint-config-*",
"eslint-plugin-*",
"jest-silent-reporter",
"expect-webdriverio",
"prettier-plugin-packagejson",
"ts-node",
"typedoc",
"typescript",
"vite",
"wdio-*",
"webdriverio"
"vite"
]
}
2 changes: 1 addition & 1 deletion packages/snaps-controllers/coverage.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"branches": 93.42,
"branches": 93.44,
"functions": 97.38,
"lines": 98.34,
"statements": 98.08
Expand Down
22 changes: 6 additions & 16 deletions packages/snaps-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "jest --reporters=jest-silent-reporter && yarn test:browser",
"test:browser": "wdio run wdio.config.js",
"test:browser": "vitest",
"test:browser:firefox": "vitest --config ./vitest.config.firefox.mts",
"test:clean": "jest --clearCache",
"test:post": "ts-node scripts/coverage.ts && rimraf coverage/jest coverage/wdio",
"test:post": "ts-node scripts/coverage.ts && rimraf coverage/jest coverage/vite",
"test:pre": "yarn mkdirp test/fixtures && ./scripts/generate-fixtures.sh",
"test:verbose": "jest --verbose",
"test:watch": "jest --watch"
Expand Down Expand Up @@ -109,8 +110,6 @@
"tar-stream": "^3.1.7"
},
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"@lavamoat/allow-scripts": "^3.0.4",
"@metamask/auto-changelog": "^5.0.1",
"@metamask/browser-passworder": "^6.0.0",
Expand All @@ -124,22 +123,14 @@
"@types/gunzip-maybe": "^1.4.0",
"@types/jest": "^27.5.1",
"@types/luxon": "^3",
"@types/mocha": "^10.0.1",
"@types/node": "18.14.2",
"@types/readable-stream": "^4.0.15",
"@types/semver": "^7.5.0",
"@types/tar-stream": "^3.1.1",
"@wdio/browser-runner": "^8.19.0",
"@wdio/cli": "^8.19.0",
"@wdio/globals": "^8.19.0",
"@wdio/mocha-framework": "^8.19.0",
"@wdio/spec-reporter": "^8.19.0",
"@wdio/static-server-service": "^8.19.0",
"@vitest/browser": "^3.0.8",
"deepmerge": "^4.2.2",
"depcheck": "^1.4.7",
"esbuild": "^0.25.2",
"eslint": "^9.11.0",
"expect-webdriverio": "^4.4.1",
"istanbul-lib-coverage": "^3.2.0",
"istanbul-lib-report": "^3.0.0",
"istanbul-reports": "^3.1.5",
Expand All @@ -152,10 +143,9 @@
"ts-node": "^10.9.1",
"typescript": "~5.3.3",
"vite": "^6.2.3",
"vite-plugin-node-polyfills": "^0.23.0",
"vite-tsconfig-paths": "^4.0.5",
"wdio-chromedriver-service": "^8.1.1",
"wdio-geckodriver-service": "^5.0.2",
"webdriverio": "^8.19.0"
"vitest": "^3.0.8"
},
"peerDependencies": {
"@metamask/snaps-execution-environments": "workspace:^"
Expand Down
27 changes: 14 additions & 13 deletions packages/snaps-controllers/scripts/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const JEST_COVERAGE_FILE = resolve(
'coverage-final.json',
);

const WDIO_COVERAGE_FILE = resolve(
const VITE_COVERAGE_FILE = resolve(
COVERAGE_PATH,
'wdio',
'vite',
'coverage-final.json',
);

Expand Down Expand Up @@ -54,36 +54,37 @@ function generateSummaryReport<Report extends ReportType>(
}

/**
* Merge the coverage reports from Jest and WebdriverIO. This checks if the
* coverage for a given file is higher in WebdriverIO than in Jest. If it is,
* it replaces the Jest coverage with the WebdriverIO coverage.
* Merge the coverage reports from Jest and Vite. This checks if the coverage
* for a given file is higher in Vite than in Jest. If it is, it replaces the
* Jest coverage with the Vite coverage.
*
* This is a workaround for WebdriverIO's coverage reporting having inaccurate
* line numbers.
* This is a workaround for Vite's coverage reporting having inaccurate line
* numbers.
*
* @returns The summary of the merged coverage.
*/
// TODO: Check if Vite's coverage is actually inaccurate.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's worth looking into in this PR, especially if we can avoid unnecessary computation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems like either Jest or Vite is inaccurate. I checked the iframe execution service for example: Vite shows it as completely covered, but after merging with Jest, one line is not covered.

The actual computation done here isn't really significant anyway though, and long term we can likely remove this once we migrate all tests to Vitest.

async function mergeReports() {
const jestMap = await fs
.readFile(JEST_COVERAGE_FILE, 'utf8')
.then(JSON.parse)
.then(createCoverageMap);

const wdioMap = await fs
.readFile(WDIO_COVERAGE_FILE, 'utf8')
const viteMap = await fs
.readFile(VITE_COVERAGE_FILE, 'utf8')
.then(JSON.parse)
.then(createCoverageMap);

const jestFiles = jestMap.files();

wdioMap.files().forEach((file) => {
const coverage = wdioMap.fileCoverageFor(file);
const wdioSummary = coverage.toSummary();
viteMap.files().forEach((file) => {
const coverage = viteMap.fileCoverageFor(file);
const viteSummary = coverage.toSummary();
const jestSummary = jestMap.fileCoverageFor(file).toSummary();

if (
!jestFiles.includes(file) ||
COVERAGE_KEYS.every((key) => wdioSummary[key].pct >= jestSummary[key].pct)
COVERAGE_KEYS.every((key) => viteSummary[key].pct >= jestSummary[key].pct)
) {
jestMap.filter((jestFile) => jestFile !== file);
jestMap.addFileCoverage(coverage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import {
spy,
} from '@metamask/snaps-utils/test-utils';
import { assert } from '@metamask/utils';
import { describe, it, expect } from 'vitest';

import { IframeExecutionService } from './IframeExecutionService';
import { createService, MOCK_BLOCK_NUMBER } from '../../test-utils';
import { MOCK_BLOCK_NUMBER } from '../../test-utils/constants';
import { createService } from '../../test-utils/service';

const IFRAME_URL = 'http://localhost:4567';
const IFRAME_URL = 'http://localhost:63315/iframe/executor/index.html';
const IFRAME_SANDBOX_URL = 'http://localhost:63315/iframe/test/index.html';

describe('IframeExecutionService', () => {
it('can boot', async () => {
Expand Down Expand Up @@ -88,7 +91,7 @@ describe('IframeExecutionService', () => {
});

it('can detect outbound requests', async () => {
expect.assertions(4);
expect.assertions(5);
Comment on lines -91 to +94
Copy link
Member Author

Choose a reason for hiding this comment

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

This number was wrong initially, it seems WDIO just ignores it.


const { service, messenger } = createService(IframeExecutionService, {
iframeUrl: new URL(IFRAME_URL),
Expand Down Expand Up @@ -157,11 +160,11 @@ describe('IframeExecutionService', () => {
// Creates an iframe attempts to access the iframe created by the execution
// service. This should fail due to the sandboxing.
const testFrame = document.createElement('iframe');
testFrame.src = `${IFRAME_URL}/test/sandbox`;
testFrame.src = IFRAME_SANDBOX_URL;
document.body.appendChild(testFrame);

expect(await message).toContain(
'Failed to access document of the snap iframe: SecurityError',
'Failed to access document of the snap iframe.',
);
});

Expand Down
27 changes: 18 additions & 9 deletions packages/snaps-controllers/src/services/iframe/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,35 @@
<script>
(function () {
try {
const snap = top.querySelector('iframe[data-testid="snaps-iframe"]');
// Parent is the iframe created by Vitest containing the Snap iframe
// and this page as a sibling iframe. We try to access the Snap iframe
// from the parent iframe.
const snap = parent.document.querySelector(
'iframe[data-testid="snaps-iframe"]',
);
if (!snap) {
window.parent.postMessage('Failed to find snap iframe.', '*');
window.parent.postMessage('Failed to find Snap iframe.', '*');
return;
}

// We try to access the snap iframe document. If this works, it means
// that the iframe is not sandboxed. Otherwise it will throw an error.
snap.document;

window.parent.postMessage(
'Same origin frames access worked which might suggest sandboxing failed.',
'*',
);
Comment on lines -14 to -27
Copy link
Member Author

Choose a reason for hiding this comment

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

This test was wrong in the first place. The iframe was served from a different origin, and trying to access top.querySelector resulted in:

SecurityError: Failed to read a named property 'querySelector' from 'Window': Blocked a frame with origin "http://localhost:4567/" from accessing a cross-origin frame.

So the snap.document was never reached, and top.querySelector isn't even a function even if it was accessible. 😅

I confirmed that the new test properly tests the sandboxing behaviour, as it's now served from the same origin. Removing the sandbox property from the iframe now results in a test failure.

if (snap.contentDocument === null) {
window.parent.postMessage(
'Failed to access document of the snap iframe.',
'*',
);
return;
}
} catch (e) {
window.parent.postMessage(
`Failed to access document of the snap iframe: ${e.toString()}`,
`An unknown error occurred: ${e.toString()}`,
'*',
);
}

// Fall through case, which should not happen.
window.parent.postMessage('Unexpected success.', '*');
})();
</script>
</body>
Expand Down
Loading
Loading