Skip to content

Commit

Permalink
Move test-snaps site to this repository (#1549)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Mrtenz committed Jun 30, 2023
1 parent 6cbd7c4 commit 1a0dd93
Show file tree
Hide file tree
Showing 111 changed files with 3,840 additions and 32 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build-lint-test.yml
Expand Up @@ -175,6 +175,28 @@ jobs:
exit 1
fi
build-test-snaps:
name: Build "@metamask/test-snaps"
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn
- run: yarn --immutable --immutable-cache
- name: Build
run: yarn workspace @metamask/test-snaps run build
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
policy:
name: Generate LavaMoat policy
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Expand Up @@ -48,6 +48,7 @@ jobs:
uses: ./.github/workflows/publish-release.yml
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PUBLISH_PAGES_TOKEN: ${{ secrets.PUBLISH_PAGES_TOKEN }}

all-jobs-complete:
name: All jobs complete
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/publish-github-pages.yml
@@ -0,0 +1,49 @@
name: Publish to GitHub Pages

on:
workflow_call:
inputs:
build_script:
required: true
type: string
destination_dir:
required: true
type: string
publish_dir:
required: true
type: string
secrets:
PUBLISH_PAGES_TOKEN:
required: true

jobs:
publish-environment:
name: Publish to GitHub Pages
runs-on: ubuntu-latest
environment: github-pages
permissions:
contents: write
steps:
- name: Ensure `build_script` is not empty
if: ${{ inputs.destination_dir == '' }}
run: exit 1
- name: Ensure `destination_dir` is not empty
if: ${{ inputs.destination_dir == '' }}
run: exit 1
- name: Ensure `publish_dir` is not empty
if: ${{ inputs.publish_dir == '' }}
run: exit 1
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- run: yarn --immutable
- name: Run build script
run: ${{ inputs.build_script }}
- name: Deploy to `${{ inputs.destination_dir }}` directory of `gh-pages` branch
uses: peaceiris/actions-gh-pages@de7ea6f8efb354206b205ef54722213d99067935
with:
personal_token: ${{ secrets.PUBLISH_PAGES_TOKEN }}
publish_dir: ${{ inputs.publish_dir }}
destination_dir: ${{ inputs.destination_dir }}
18 changes: 18 additions & 0 deletions .github/workflows/publish-release.yml
Expand Up @@ -5,6 +5,8 @@ on:
secrets:
NPM_TOKEN:
required: true
PUBLISH_PAGES_TOKEN:
required: true

jobs:
publish-release:
Expand Down Expand Up @@ -100,3 +102,19 @@ jobs:
uses: ./.github/workflows/publish-environment.yml
with:
destination_dir: ${{ needs.get-release-version.outputs.RELEASE_VERSION }}

publish-test-snaps:
needs: get-release-version
name: Publish test snaps
# The `rc/1.0.0` branch does not have `test-snaps` package, so we only run
# this job on the `main` branch.
if: ${{ github.ref_name == 'main' }}
permissions:
contents: write
uses: ./.github/workflows/publish-github-pages.yml
with:
build_script: yarn workspace @metamask/test-snaps build
destination_dir: test-snaps/${{ needs.get-release-version.outputs.RELEASE_VERSION }}
publish_dir: ./packages/test-snaps/public
secrets:
PUBLISH_PAGES_TOKEN: ${{ secrets.PUBLISH_PAGES_TOKEN }}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -24,7 +24,7 @@
"build:source": "yarn workspaces foreach --parallel --verbose run build:source",
"build:types": "tsc --build tsconfig.build.json",
"build:post-tsc": "yarn workspaces foreach --parallel --topological --topological-dev --verbose run build:post-tsc",
"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",
"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",
"clean": "yarn workspaces foreach --parallel --verbose run clean",
"test": "yarn workspaces foreach --parallel --verbose run test",
"test:browser": "yarn workspaces foreach --verbose run test:browser",
Expand Down
1 change: 1 addition & 0 deletions packages/examples/package.json
Expand Up @@ -17,6 +17,7 @@
"build:post-tsc": "yarn build",
"clean": "yarn workspaces foreach --parallel --verbose --no-private run clean",
"start": "yarn workspaces foreach --parallel --verbose --interlaced --no-private --jobs unlimited run start",
"start:test": "yarn start",
"test": "yarn workspaces foreach --parallel --verbose --interlaced --no-private run test",
"lint": "yarn workspaces foreach --parallel --verbose --interlaced --no-private run lint",
"lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
Expand Down
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "/lLHUZ/SWHARUnhQ3KaAcyg7dEY2JLpr0SX+rWJBbHU=",
"shasum": "2Sf6Y9KD0+pmcCQSbxMPteQz8sabuZi8Z6zHJ+uVUSY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/notifications/src/index.test.ts
Expand Up @@ -35,7 +35,7 @@ describe('onRpcRequest', () => {

expect(response).toRespondWith(null);
expect(response).toSendNotification(
'Hello, Jest, from within MetaMask!',
'Hello from within MetaMask!',
NotificationType.InApp,
);

Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/notifications/src/index.ts
Expand Up @@ -28,7 +28,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
// We're using the `NotificationType` enum here, but you can also use
// the string values directly, e.g. `type: 'inApp'`.
type: NotificationType.InApp,
message: `Hello, ${origin}, from within MetaMask!`,
message: `Hello from within MetaMask!`,
},
});

Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/rollup-plugin/package.json
Expand Up @@ -26,7 +26,7 @@
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" \"!snap.manifest.json\" --ignore-path ../../../../.gitignore",
"test": "yarn test:e2e",
"test:e2e": "jest",
"start": "rollup watch",
"start": "yarn build --watch",
"prepare-manifest:preview": "../../../../scripts/prepare-preview-manifest.sh",
"publish:preview": "yarn npm publish --tag preview"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/examples/packages/wasm/package.json
Expand Up @@ -25,7 +25,7 @@
"lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" \"!snap.manifest.json\" --ignore-path ../../../../.gitignore",
"start": "webpack watch",
"start": "concurrently --names webpack,server \"webpack watch\" \"http-server --no-dotfiles --port 8019 .\"",
"test": "yarn test:e2e",
"test:e2e": "jest",
"prepare-manifest:preview": "../../../../scripts/prepare-preview-manifest.sh",
Expand Down Expand Up @@ -55,6 +55,7 @@
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"assemblyscript": "^0.27.5",
"concurrently": "^8.2.0",
"deepmerge": "^4.2.2",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -63,6 +64,7 @@
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"http-server": "^14.1.1",
"jest": "^29.0.2",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.11",
Expand All @@ -71,7 +73,8 @@
"ts-node": "^10.9.1",
"typescript": "~4.8.4",
"webpack": "^5.86.0",
"webpack-cli": "^5.1.4"
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.13.3"
},
"engines": {
"node": ">=16.0.0"
Expand Down
7 changes: 7 additions & 0 deletions packages/test-snaps/.eslintrc.js
@@ -0,0 +1,7 @@
module.exports = {
extends: ['../../.eslintrc.js'],

parserOptions: {
tsconfigRootDir: __dirname,
},
};
14 changes: 14 additions & 0 deletions packages/test-snaps/.swcrc
@@ -0,0 +1,14 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"transform": {
"react": {
"runtime": "automatic"
}
}
}
}
9 changes: 9 additions & 0 deletions packages/test-snaps/CHANGELOG.md
@@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

[Unreleased]: https://github.com/MetaMask/snaps/
15 changes: 15 additions & 0 deletions packages/test-snaps/LICENSE
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2023 MetaMask

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5 changes: 5 additions & 0 deletions packages/test-snaps/README.md
@@ -0,0 +1,5 @@
# `@metamask/test-snaps`

The test snaps website for MetaMask Snaps, used for (automated) end-to-end
testing. The test snaps website is a simple static website, containing a way to
interact with [the example snaps](../examples), to test their functionality.
14 changes: 14 additions & 0 deletions packages/test-snaps/jest.config.js
@@ -0,0 +1,14 @@
const deepmerge = require('deepmerge');

const baseConfig = require('../../jest.config.base');

module.exports = deepmerge(baseConfig, {
coverageThreshold: {
global: {
branches: 0,
functions: 0,
lines: 0,
statements: 0,
},
},
});
89 changes: 89 additions & 0 deletions packages/test-snaps/package.json
@@ -0,0 +1,89 @@
{
"name": "@metamask/test-snaps",
"version": "0.35.2-flask.1",
"private": true,
"description": "The test snaps website for MetaMask Snaps, used for end-to-end testing.",
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/snaps.git"
},
"license": "ISC",
"sideEffects": false,
"files": [],
"scripts": {
"test": "jest --passWithNoTests && yarn posttest",
"posttest": "jest-it-up",
"test:ci": "yarn test",
"start": "yarn workspaces foreach --parallel --verbose --interlaced --all --include \"@metamask/test-snaps\" --include \"@metamask/example-snaps\" run start:test",
"start:test": "cross-env NODE_ENV=development webpack serve",
"build": "cross-env NODE_ENV=production webpack",
"build:clean": "yarn clean && yarn build",
"build:post-tsc": "yarn build",
"clean": "rimraf 'dist'",
"lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog",
"lint:ci": "yarn lint",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:changelog": "yarn auto-changelog validate"
},
"dependencies": {
"@metamask/snaps-utils": "workspace:^",
"@metamask/utils": "^6.0.1",
"@popperjs/core": "^2.11.8",
"@reduxjs/toolkit": "^1.9.5",
"bootstrap": "^5.2.2",
"gl-matrix": "^3.4.3",
"react": "^18.2.0",
"react-bootstrap": "^2.5.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.5",
"simplex-noise": "^4.0.0"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.1.0",
"@metamask/eslint-config": "^11.0.0",
"@metamask/eslint-config-jest": "^11.0.0",
"@metamask/eslint-config-nodejs": "^11.0.1",
"@metamask/eslint-config-typescript": "^11.0.0",
"@metamask/providers": "^11.0.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
"@swc/core": "^1.3.66",
"@swc/jest": "^0.2.26",
"@types/jest": "^27.5.1",
"@types/node": "^20.3.1",
"@types/webpack-env": "^1.18.1",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"copy-webpack-plugin": "^11.0.0",
"cross-env": "^7.0.3",
"css-loader": "^6.7.3",
"deepmerge": "^4.2.2",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"favicons": "^7.1.2",
"favicons-webpack-plugin": "^6.0.0",
"html-webpack-plugin": "^5.5.0",
"jest": "^29.0.2",
"jest-it-up": "^2.0.0",
"prettier": "^2.7.1",
"rimraf": "^4.1.2",
"style-loader": "^3.3.2",
"swc-loader": "^0.2.3",
"terser-webpack-plugin": "^5.3.9",
"ts-node": "^10.9.1",
"tsconfig-paths-webpack-plugin": "^4.0.1",
"typescript": "~4.8.4",
"webpack": "^5.86.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.13.3"
},
"engines": {
"node": ">=16.0.0"
}
}
23 changes: 23 additions & 0 deletions packages/test-snaps/src/App.tsx
@@ -0,0 +1,23 @@
import { FunctionComponent } from 'react';
import { Container, Row } from 'react-bootstrap';

import { Logo } from './components';
import { InstalledSnaps, snaps } from './features';

export const App: FunctionComponent = () => {
return (
<Container fluid>
<Logo />

<Row className="gx-3 gy-3 row-cols-xs-1 row-cols-sm-2 row-cols-lg-3">
{/* Installed Snaps list */}
<InstalledSnaps />

{/* Snap test UI */}
{Object.values(snaps).map((Component, index) => (
<Component key={`snap-${index}`} />
))}
</Row>
</Container>
);
};

0 comments on commit 1a0dd93

Please sign in to comment.