Security News
JSR Working Group Kicks Off with Ambitious Roadmap andΒ Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@synthetixio/synpress
Advanced tools
Synpress is e2e testing framework based around Cypress.io & playwright with included MetaMask support. Test your dapps with ease.
We're Hiring π β Think you have what it takes? Feel free to drop an email to jobs@synpress.io
Synpress
is E2E testing framework
based on Cypress
and Playwright
with support for MetaMask.
Synpress makes sure to always use latest version of metamask and puts a lot of effort to make sure that dapp tests are stable and trustful.
It also provides an easy way to use and access metamask straight from your e2e tests with all features of cypress and playwright.
π₯ Synpress works out-of-the-box with other frameworks! There is no need to use it directly. Check usage examples for more details.
# with pnpm
pnpm add --save-dev @synthetixio/synpress
# with npm
npm install --save-dev @synthetixio/synpress
# with yarn
yarn add -D @synthetixio/synpress
For full Synpress commands and their examples, check here.
To see in which direction Synpress is headed to, take a look at planning board.
synpress run --headless
)
.env
file automatically (from project root
folder)Project structure:
project_dir
βββ src
βββ tests
βββ e2e
βββ .eslintrc.js
βββ support.js
βββ tsconfig.json
βββ specs
βββ example-spec.js
βββ pages
βββ example-page.js
.eslintrc.js
inside your tests folder (/project_dir/tests/e2e
):const path = require('path');
const synpressPath = path.join(
process.cwd(),
'/node_modules/@synthetixio/synpress',
);
module.exports = {
extends: `${synpressPath}/.eslintrc.js`,
};
support.js
inside your tests folder (/project_dir/tests/e2e
):import '@synthetixio/synpress/support/index';
^ hint: you can also use this file to extend synpress - add custom commands, and more..
tsconfig.json
inside your tests folder (/project_dir/tests/e2e
):{
"compilerOptions": {
"allowJs": true,
"baseUrl": "../../node_modules",
"types": [
"cypress",
"@synthetixio/synpress/support",
"cypress-wait-until",
"@testing-library/cypress"
],
"outDir": "./output"
},
"include": ["**/*.*"]
}
To change specific values in default config, you can use --config
flag. For
example, to change path for support.js
file, you can use
synpress run --config "supportFile=__tests__/e2e/supportFile.js"
If you would like to use custom paths for your tests and configs, you should
mirror (full) default synpress config
and then modify it for your needs. Then you can direct synpress to use it with
--configFile
flag.
For example: synpress run --configFile __tests__/e2e/customConfig.config.js
Synpress doesn't seem to communicate with metamask properly if
"chromeWebSecurity": false
flag is set. More about it
here.
Thanks to
new headless mode in Chrome,
tests are now working in headless mode π€ (synpress run --headless
). However,
I recommend to use it only for local development as this feature is new and
experimental and may cause issues on CI (UNIX). So please, stick to non-headless
mode on CI.
In the past, tests worked only in non-headless mode because extensions were not supported in headless mode by playwright and Cypress. As a workaround, we've provided Docker π³ containers. They solved this issue and it's an alternative.
You have to setup xvfb
and window manager (like fluxbox
or xfce4
) to run
tests without issues on CI (together with DISPLAY
env var). Take a look at
CI tips & tricks
for working examples.
There is a global
before()
which runs metamask setup before all tests:
goerli
) or creates custom network and changes
to it (depending on your setup)It requires environmental variable called SECRET_WORDS
to be present in
following format => 'word1 word2 word3 ..'
(delimited with spaces) or private
key in an environmental variable called PRIVATE_KEY
.
To change default network (goerli
), you can use NETWORK_NAME
environmental
variable, for example: NETWORK_NAME=sepolia
.
Available choices are: mainnet
, goerli
, sepolia
and localhost
.
To create and switch to custom network at metamask setup phase, use these:
NETWORK_NAME
=> ex: synthetix
RPC_URL
=> ex: https://synthetix-node.io
CHAIN_ID
=> ex: 123
SYMBOL
=> ex: SNX
BLOCK_EXPLORER
(optional) => ex: https://synthetix-explorer.io
IS_TESTNET
(optional) => ex: false
Metamask version is hardcoded and frequently updated under supervision to avoid
a case when e2e tests break because of CSS classes changes in new version, so
all you need is to keep synpress updated in your project. However, you can still
override metamask with METAMASK_VERSION
environmental variable, for example:
METAMASK_VERSION=10.21.0
or METAMASK_VERSION=latest
.
If you don't want to use environmental variables, you can modify
setupMetamask()
to following:
setupMetamask(secretWordsOrPrivateKey, network, password)
, for example:
setupMetamask('word1 word2 word3 ..', 'mainnet', 'password')
(delimited with
spaces).
You can also add and switch to custom network by passing an object
instead of
string
inside setupMetamask(secretWordsOrPrivateKey, network, password)
function for network
parameter.
If you want to use Etherscan API helpers, you will have to provide Etherscan API
key using ETHERSCAN_KEY
environmental variable.
To fail a test if there are any browser console errors, set FAIL_ON_ERROR
to
1
or true
.
Automatic waiting for XHR requests to finish before tests start can be turned on
with CYPRESS_RESOURCES_WAIT
environmental variable, set it to 1
or true
.
If you want to skip metamask extension installation or metamask setup, you can
use SKIP_METAMASK_INSTALL
and SKIP_METAMASK_SETUP
separately. Both variables
accept 1
or true
.
Synpress is blazingly-fast β‘ by default! If you want to change that, you can
use STABLE_MODE=true
(which will introduce delays only between main actions,
300ms by default) / STABLE_MODE=<value>
or SLOW_MODE=true
(which will
introduce delay between every action, 50ms by default) / SLOW_MODE=<value>
.
DEBUG=synpress:*
is very useful while debugging your tests. It enables
following features:
You may encounter 403 errors (on shared IPs & CI) related to rate limiting while
fetching metamask releases from GitHub REST API. This should never happen at
all, but it's good to mention. To prevent it from happening, you can create new
private access token on GitHub (without any additional access) and specify
GH_USERNAME
& GH_PAT
environmental variables.
Docker is awesome for CI. Give it a try.
git clone git@github.com:Synthetixio/synpress.git
cd synpress
.env
filedocker-compose --profile synpress --profile foundry up --build --exit-code-from synpress
or ./start-tests.sh
docker-compose up --profile synpress --build --exit-code-from synpress
docker-compose --profile synpress --profile foundry --profile ngrok up --build --exit-code-from synpress
All examples of setup are present in this repository. Just take a look around.
ubuntu-latest
.ubuntu-latest
, has configured VNC, noVNC and ngrok for easy
debugging.ubuntu-latest
with docker compose
stack.ubuntu-latest
, using official
cypress-io/github-action.synpress run
to run testssynpress open
to open Cypress UI (may be bugged in some cases because it
doesn't clear metamask state before each e2e test, please use synpress run
)Command line interface (synpress help
):
Usage: synpress run [options]
launch tests
Options:
-b, --browser <name> run on specified browser (default: "chrome")
-c, --config <config> set configuration values, separate multiple values with a comma
-cf, --configFile <path> specify a path to *.js file where configuration values are set
-e, --env <env=val> set environment variables, separate multiple values with comma
-s, --spec <path or glob> run only provided spec files
-ne, --noExit keep runner open after tests finish
-pr, --project <path> run with specific project path
-q, --quiet only test runner output in console
-r, --reporter <reporter> specify mocha reporter
-ro, --reporterOptions <options> specify mocha reporter options, separate multiple values with comma
-r, --record [dashboard] record video of tests running after setting up your project to record
-k, --key <key> [dashboard] set record key
-p, --parallel [dashboard] run recorded specs in parallel across multiple machines
-g, --group [name] [dashboard] group recorded tests together under a single run
-t, --tag <name> [dashboard] add tags to dashboard for test run
-h, --help display help for command
Usage: synpress open [options]
launch test runner UI
Options:
-cf, --configFile <path> specify a path to *.js file where configuration values are set
-h, --help display help for command
Variable | Description |
---|---|
SECRET_WORDS | Space separated words for the test wallet recovery phrase (mnemonic; 12 words) |
PRIVATE_KEY | Test wallet private key |
NETWORK_NAME | Network name (eg NETWORK_NAME=Optimism ) |
RPC_URL | Network RPC (egRPC_URL=https://mainnet.optimism.io ) |
CHAIN_ID | Network ID (egCHAIN_ID=10 ) |
SYMBOL | Native chain token ticker (eg SYMBOL=OP ) |
IS_TESTNET | boolean indicates that the added network is testnet |
BLOCK_EXPLORER | Blockchain explorer (eg BLOCK_EXPLORER=https://optimistic.etherscan.io/ ) |
SYNDEBUG | Set debugging mode to be on |
STABLE_MODE | Introduce delay between main actions, 300ms by default (eg STABLE_MODE=300ms , STABLE_MODE=true ) |
SLOW_MODE | Introduce delay between every action, 50ms by default (eg SLOW_MODE=true , SLOW_MODE=200ms ) |
METAMASK_VERSION | Metamask version to be installed |
SKIP_METAMASK_INSTALL | Will skip MetaMask installation |
SKIP_METAMASK_SETUP | Will skip MetaMask initial setup |
GH_USERNAME | GitHub username (used to avoid rate-limit issue while downloading metamask) |
GH_PAT | GitHub personal access token (used to avoid rate-limit issue while downloading metamask) |
ETHERSCAN_KEY | Etherscan key (used only for etherscan-related commands) |
FAIL_ON_ERROR | Fail a test if there are any browser console errors |
CYPRESS_GROUP | Group tests |
CI | boolean value indicate that tests are runing from CI/CD pipeline |
dev
branch to master
branch-beta
version is automatically released)patch|minor|major
depending on your needs to promote your build.Alternatively, instead of running GitHub Action for release, you can move on with manual release process:
master
branch and pull latest changespnpm release:patch/minor/major
commanddev
branch up to date with master
Above actions will lead to:
FAQs
[![npm version](https://badge.fury.io/js/%40synthetixio%2Fsynpress.svg)](https://badge.fury.io/js/%40synthetixio%2Fsynpress) [![Discord](https://img.shields.io/discord/1103781993394733136.svg?color=768AD4&label=discord&logo=https%3A%2F%2Fdiscordapp.com%2F
The npm package @synthetixio/synpress receives a total of 8,782 weekly downloads. As such, @synthetixio/synpress popularity was classified as popular.
We found that @synthetixio/synpress demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.