Skip to content

Commit 1a0dd93

Browse files
authored
Move test-snaps site to this repository (#1549)
* Add test-snaps site * Move files around and fix some breaking changes * Add license and update changelog * Remove SCSS in favour of CSS * Fix some issues with snaps * Deploy test-snaps to GitHub Pages on release * Fix secrets name * Update icon * Use publish_dir in action * Use icon without padding * Fix Rollup watch command * Fix BIP-44 snap invalid coin type * Fix copy issues * Fix workflow file * Remove unused workflow file * Add basic README * Update LavaMoat policies * Pin eslint-plugin-import to 2.26.0 as workaround for regression import-js/eslint-plugin-import#2775 * Revert "Pin eslint-plugin-import to 2.26.0 as workaround for regression" This reverts commit 457d6fa. * Swap out Gatsby for plain Webpack * Build test-snaps in CI * Revert some changes to yarn.lock * Update LavaMoat policies * Fix lint issues * Update snap shasums * Fix verify-tsconfig script * Fix workflow name * Fix `@metamask/providers` version * Revert change to .yarnrc.yml * Fix `@metamask/providers` version again
1 parent 6cbd7c4 commit 1a0dd93

File tree

111 files changed

+3840
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+3840
-32
lines changed

.github/workflows/build-lint-test.yml

+22
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,28 @@ jobs:
175175
exit 1
176176
fi
177177
178+
build-test-snaps:
179+
name: Build "@metamask/test-snaps"
180+
runs-on: ubuntu-latest
181+
needs: prepare
182+
steps:
183+
- uses: actions/checkout@v3
184+
- name: Setup Node
185+
uses: actions/setup-node@v3
186+
with:
187+
node-version-file: '.nvmrc'
188+
cache: yarn
189+
- run: yarn --immutable --immutable-cache
190+
- name: Build
191+
run: yarn workspace @metamask/test-snaps run build
192+
- name: Require clean working directory
193+
shell: bash
194+
run: |
195+
if ! git diff --exit-code; then
196+
echo "Working tree dirty at end of job"
197+
exit 1
198+
fi
199+
178200
policy:
179201
name: Generate LavaMoat policy
180202
runs-on: ubuntu-latest

.github/workflows/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
uses: ./.github/workflows/publish-release.yml
4949
secrets:
5050
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
51+
PUBLISH_PAGES_TOKEN: ${{ secrets.PUBLISH_PAGES_TOKEN }}
5152

5253
all-jobs-complete:
5354
name: All jobs complete
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish to GitHub Pages
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
build_script:
7+
required: true
8+
type: string
9+
destination_dir:
10+
required: true
11+
type: string
12+
publish_dir:
13+
required: true
14+
type: string
15+
secrets:
16+
PUBLISH_PAGES_TOKEN:
17+
required: true
18+
19+
jobs:
20+
publish-environment:
21+
name: Publish to GitHub Pages
22+
runs-on: ubuntu-latest
23+
environment: github-pages
24+
permissions:
25+
contents: write
26+
steps:
27+
- name: Ensure `build_script` is not empty
28+
if: ${{ inputs.destination_dir == '' }}
29+
run: exit 1
30+
- name: Ensure `destination_dir` is not empty
31+
if: ${{ inputs.destination_dir == '' }}
32+
run: exit 1
33+
- name: Ensure `publish_dir` is not empty
34+
if: ${{ inputs.publish_dir == '' }}
35+
run: exit 1
36+
- uses: actions/checkout@v3
37+
- name: Setup Node
38+
uses: actions/setup-node@v3
39+
with:
40+
node-version-file: '.nvmrc'
41+
- run: yarn --immutable
42+
- name: Run build script
43+
run: ${{ inputs.build_script }}
44+
- name: Deploy to `${{ inputs.destination_dir }}` directory of `gh-pages` branch
45+
uses: peaceiris/actions-gh-pages@de7ea6f8efb354206b205ef54722213d99067935
46+
with:
47+
personal_token: ${{ secrets.PUBLISH_PAGES_TOKEN }}
48+
publish_dir: ${{ inputs.publish_dir }}
49+
destination_dir: ${{ inputs.destination_dir }}

.github/workflows/publish-release.yml

+18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
secrets:
66
NPM_TOKEN:
77
required: true
8+
PUBLISH_PAGES_TOKEN:
9+
required: true
810

911
jobs:
1012
publish-release:
@@ -100,3 +102,19 @@ jobs:
100102
uses: ./.github/workflows/publish-environment.yml
101103
with:
102104
destination_dir: ${{ needs.get-release-version.outputs.RELEASE_VERSION }}
105+
106+
publish-test-snaps:
107+
needs: get-release-version
108+
name: Publish test snaps
109+
# The `rc/1.0.0` branch does not have `test-snaps` package, so we only run
110+
# this job on the `main` branch.
111+
if: ${{ github.ref_name == 'main' }}
112+
permissions:
113+
contents: write
114+
uses: ./.github/workflows/publish-github-pages.yml
115+
with:
116+
build_script: yarn workspace @metamask/test-snaps build
117+
destination_dir: test-snaps/${{ needs.get-release-version.outputs.RELEASE_VERSION }}
118+
publish_dir: ./packages/test-snaps/public
119+
secrets:
120+
PUBLISH_PAGES_TOKEN: ${{ secrets.PUBLISH_PAGES_TOKEN }}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"build:source": "yarn workspaces foreach --parallel --verbose run build:source",
2525
"build:types": "tsc --build tsconfig.build.json",
2626
"build:post-tsc": "yarn workspaces foreach --parallel --topological --topological-dev --verbose run build:post-tsc",
27-
"build:post-tsc:ci": "yarn workspaces foreach --parallel --topological --topological-dev --verbose --exclude root --exclude \"@metamask/snaps-simulator\" --exclude \"@metamask/snaps-execution-environments\" --exclude \"@metamask/snaps-jest\" --exclude \"@metamask/example-snaps\" run build:post-tsc",
27+
"build:post-tsc:ci": "yarn workspaces foreach --parallel --topological --topological-dev --verbose --exclude root --exclude \"@metamask/snaps-simulator\" --exclude \"@metamask/snaps-execution-environments\" --exclude \"@metamask/snaps-jest\" --exclude \"@metamask/example-snaps\" --exclude \"@metamask/test-snaps\" run build:post-tsc",
2828
"clean": "yarn workspaces foreach --parallel --verbose run clean",
2929
"test": "yarn workspaces foreach --parallel --verbose run test",
3030
"test:browser": "yarn workspaces foreach --verbose run test:browser",

packages/examples/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"build:post-tsc": "yarn build",
1818
"clean": "yarn workspaces foreach --parallel --verbose --no-private run clean",
1919
"start": "yarn workspaces foreach --parallel --verbose --interlaced --no-private --jobs unlimited run start",
20+
"start:test": "yarn start",
2021
"test": "yarn workspaces foreach --parallel --verbose --interlaced --no-private run test",
2122
"lint": "yarn workspaces foreach --parallel --verbose --interlaced --no-private run lint",
2223
"lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",

packages/examples/packages/notifications/snap.manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "/lLHUZ/SWHARUnhQ3KaAcyg7dEY2JLpr0SX+rWJBbHU=",
10+
"shasum": "2Sf6Y9KD0+pmcCQSbxMPteQz8sabuZi8Z6zHJ+uVUSY=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/notifications/src/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('onRpcRequest', () => {
3535

3636
expect(response).toRespondWith(null);
3737
expect(response).toSendNotification(
38-
'Hello, Jest, from within MetaMask!',
38+
'Hello from within MetaMask!',
3939
NotificationType.InApp,
4040
);
4141

packages/examples/packages/notifications/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
2828
// We're using the `NotificationType` enum here, but you can also use
2929
// the string values directly, e.g. `type: 'inApp'`.
3030
type: NotificationType.InApp,
31-
message: `Hello, ${origin}, from within MetaMask!`,
31+
message: `Hello from within MetaMask!`,
3232
},
3333
});
3434

packages/examples/packages/rollup-plugin/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" \"!snap.manifest.json\" --ignore-path ../../../../.gitignore",
2727
"test": "yarn test:e2e",
2828
"test:e2e": "jest",
29-
"start": "rollup watch",
29+
"start": "yarn build --watch",
3030
"prepare-manifest:preview": "../../../../scripts/prepare-preview-manifest.sh",
3131
"publish:preview": "yarn npm publish --tag preview"
3232
},

packages/examples/packages/wasm/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
2626
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
2727
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" \"!snap.manifest.json\" --ignore-path ../../../../.gitignore",
28-
"start": "webpack watch",
28+
"start": "concurrently --names webpack,server \"webpack watch\" \"http-server --no-dotfiles --port 8019 .\"",
2929
"test": "yarn test:e2e",
3030
"test:e2e": "jest",
3131
"prepare-manifest:preview": "../../../../scripts/prepare-preview-manifest.sh",
@@ -55,6 +55,7 @@
5555
"@typescript-eslint/eslint-plugin": "^5.42.1",
5656
"@typescript-eslint/parser": "^5.42.1",
5757
"assemblyscript": "^0.27.5",
58+
"concurrently": "^8.2.0",
5859
"deepmerge": "^4.2.2",
5960
"eslint": "^8.27.0",
6061
"eslint-config-prettier": "^8.5.0",
@@ -63,6 +64,7 @@
6364
"eslint-plugin-jsdoc": "^39.6.2",
6465
"eslint-plugin-node": "^11.1.0",
6566
"eslint-plugin-prettier": "^4.2.1",
67+
"http-server": "^14.1.1",
6668
"jest": "^29.0.2",
6769
"prettier": "^2.7.1",
6870
"prettier-plugin-packagejson": "^2.2.11",
@@ -71,7 +73,8 @@
7173
"ts-node": "^10.9.1",
7274
"typescript": "~4.8.4",
7375
"webpack": "^5.86.0",
74-
"webpack-cli": "^5.1.4"
76+
"webpack-cli": "^5.1.4",
77+
"webpack-dev-server": "^4.13.3"
7578
},
7679
"engines": {
7780
"node": ">=16.0.0"

packages/test-snaps/.eslintrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
extends: ['../../.eslintrc.js'],
3+
4+
parserOptions: {
5+
tsconfigRootDir: __dirname,
6+
},
7+
};

packages/test-snaps/.swcrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://json.schemastore.org/swcrc",
3+
"jsc": {
4+
"parser": {
5+
"syntax": "typescript",
6+
"tsx": true
7+
},
8+
"transform": {
9+
"react": {
10+
"runtime": "automatic"
11+
}
12+
}
13+
}
14+
}

packages/test-snaps/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
9+
[Unreleased]: https://github.com/MetaMask/snaps/

packages/test-snaps/LICENSE

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ISC License
2+
3+
Copyright (c) 2023 MetaMask
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

packages/test-snaps/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# `@metamask/test-snaps`
2+
3+
The test snaps website for MetaMask Snaps, used for (automated) end-to-end
4+
testing. The test snaps website is a simple static website, containing a way to
5+
interact with [the example snaps](../examples), to test their functionality.

packages/test-snaps/jest.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const deepmerge = require('deepmerge');
2+
3+
const baseConfig = require('../../jest.config.base');
4+
5+
module.exports = deepmerge(baseConfig, {
6+
coverageThreshold: {
7+
global: {
8+
branches: 0,
9+
functions: 0,
10+
lines: 0,
11+
statements: 0,
12+
},
13+
},
14+
});

packages/test-snaps/package.json

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"name": "@metamask/test-snaps",
3+
"version": "0.35.2-flask.1",
4+
"private": true,
5+
"description": "The test snaps website for MetaMask Snaps, used for end-to-end testing.",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/MetaMask/snaps.git"
9+
},
10+
"license": "ISC",
11+
"sideEffects": false,
12+
"files": [],
13+
"scripts": {
14+
"test": "jest --passWithNoTests && yarn posttest",
15+
"posttest": "jest-it-up",
16+
"test:ci": "yarn test",
17+
"start": "yarn workspaces foreach --parallel --verbose --interlaced --all --include \"@metamask/test-snaps\" --include \"@metamask/example-snaps\" run start:test",
18+
"start:test": "cross-env NODE_ENV=development webpack serve",
19+
"build": "cross-env NODE_ENV=production webpack",
20+
"build:clean": "yarn clean && yarn build",
21+
"build:post-tsc": "yarn build",
22+
"clean": "rimraf 'dist'",
23+
"lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
24+
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
25+
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog",
26+
"lint:ci": "yarn lint",
27+
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
28+
"lint:changelog": "yarn auto-changelog validate"
29+
},
30+
"dependencies": {
31+
"@metamask/snaps-utils": "workspace:^",
32+
"@metamask/utils": "^6.0.1",
33+
"@popperjs/core": "^2.11.8",
34+
"@reduxjs/toolkit": "^1.9.5",
35+
"bootstrap": "^5.2.2",
36+
"gl-matrix": "^3.4.3",
37+
"react": "^18.2.0",
38+
"react-bootstrap": "^2.5.0",
39+
"react-dom": "^18.2.0",
40+
"react-redux": "^8.0.5",
41+
"simplex-noise": "^4.0.0"
42+
},
43+
"devDependencies": {
44+
"@metamask/auto-changelog": "^3.1.0",
45+
"@metamask/eslint-config": "^11.0.0",
46+
"@metamask/eslint-config-jest": "^11.0.0",
47+
"@metamask/eslint-config-nodejs": "^11.0.1",
48+
"@metamask/eslint-config-typescript": "^11.0.0",
49+
"@metamask/providers": "^11.0.0",
50+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
51+
"@swc/core": "^1.3.66",
52+
"@swc/jest": "^0.2.26",
53+
"@types/jest": "^27.5.1",
54+
"@types/node": "^20.3.1",
55+
"@types/webpack-env": "^1.18.1",
56+
"@typescript-eslint/eslint-plugin": "^5.42.1",
57+
"@typescript-eslint/parser": "^5.42.1",
58+
"copy-webpack-plugin": "^11.0.0",
59+
"cross-env": "^7.0.3",
60+
"css-loader": "^6.7.3",
61+
"deepmerge": "^4.2.2",
62+
"eslint": "^8.27.0",
63+
"eslint-config-prettier": "^8.5.0",
64+
"eslint-plugin-import": "^2.26.0",
65+
"eslint-plugin-jest": "^27.1.5",
66+
"eslint-plugin-jsdoc": "^39.6.2",
67+
"eslint-plugin-node": "^11.1.0",
68+
"eslint-plugin-prettier": "^4.2.1",
69+
"favicons": "^7.1.2",
70+
"favicons-webpack-plugin": "^6.0.0",
71+
"html-webpack-plugin": "^5.5.0",
72+
"jest": "^29.0.2",
73+
"jest-it-up": "^2.0.0",
74+
"prettier": "^2.7.1",
75+
"rimraf": "^4.1.2",
76+
"style-loader": "^3.3.2",
77+
"swc-loader": "^0.2.3",
78+
"terser-webpack-plugin": "^5.3.9",
79+
"ts-node": "^10.9.1",
80+
"tsconfig-paths-webpack-plugin": "^4.0.1",
81+
"typescript": "~4.8.4",
82+
"webpack": "^5.86.0",
83+
"webpack-cli": "^5.1.4",
84+
"webpack-dev-server": "^4.13.3"
85+
},
86+
"engines": {
87+
"node": ">=16.0.0"
88+
}
89+
}

packages/test-snaps/src/App.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { FunctionComponent } from 'react';
2+
import { Container, Row } from 'react-bootstrap';
3+
4+
import { Logo } from './components';
5+
import { InstalledSnaps, snaps } from './features';
6+
7+
export const App: FunctionComponent = () => {
8+
return (
9+
<Container fluid>
10+
<Logo />
11+
12+
<Row className="gx-3 gy-3 row-cols-xs-1 row-cols-sm-2 row-cols-lg-3">
13+
{/* Installed Snaps list */}
14+
<InstalledSnaps />
15+
16+
{/* Snap test UI */}
17+
{Object.values(snaps).map((Component, index) => (
18+
<Component key={`snap-${index}`} />
19+
))}
20+
</Row>
21+
</Container>
22+
);
23+
};

0 commit comments

Comments
 (0)