• Stars
    star
    570
  • Rank 78,245 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Synpress is e2e testing framework based on Cypress.io and playwright with support for metamask.

npm version Synpress CI CodeQL Release CI synpress Discord Twitter Follow

We're Hiring πŸŽ‰ β€” Think you have what it takes? We're looking for Software Engineer, find out more.

Synpress is E2E testing framework
based on Cypress and Playwright with support for MetaMask.

Sponsored & used by:

Synthetix Optimism

Power users:

Phantom Ethereum Name Service (ENS) Kwenta
Panther Protocol Guild Aragon Delvtech
Offchain Labs Snapshot Labs Hedera

Synpress Demo

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.

Table of content

πŸ§‘β€πŸ€β€πŸ§‘ Community

  • Discord => for live support and direct chat with devs.
  • Twitter => for updates and announcements.

πŸ–₯️ Install

# with pnpm
pnpm add --save-dev @synthetixio/synpress
# with npm
npm install --save-dev @synthetixio/synpress
# with yarn
yarn add -D @synthetixio/synpress

βš™οΈ Supported frameworks

πŸ‘ Supported wallets

✍️ Usage examples:


For full Synpress commands and their examples, check here.

To see in which direction Synpress is headed to, take a look at planning board.

🌟 Features

  • Added support for metamask 🦊
  • Supports headless mode πŸ€– (synpress run --headless)
    • Recommended for local development (but not for CI yet as it's new and experimental)
  • Integrated with Docker 🐳
    • Recommended for CI
    • Includes VNC and noVNC
    • Integrated video recording πŸŽ₯ (full screen)
    • Exposes noVNC with ngrok (optional)
  • Easy to debug πŸ›
    • Improved error handling
    • Supports cypress and playwright debuggers
    • noVNC allows for interactions through browser 🌐
    • Debug remote machines on CI with ngrok
  • Blazingly-fast ⚑
  • Extensible βš™οΈ (add own custom commands and plugins)
  • Can be used in existing Cypress setup
  • Supports dotenv
    • Loads all env vars from your .env file automatically (from project root folder)
  • Ability to use latest metamask or lock it's version to avoid unexpected failures related to metamask updates
  • Supports multi-lang of metamask, it doesn't depend on any labels
  • Synpress is fully tested
  • Waits for XHR requests, navigations and animations automatically
  • Ability to fail test run if there are any browser console errors found
  • Types support for all additional custom commands
  • The best possible options set up in place to avoid flakiness
  • Etherscan API helpers in place which for ex. allows to compare your transaction results with etherscan and check tx status
  • Synthetix helpers in place which allows to interact with synthetix protocol programmatically
  • Supports codespaces
    • Run your tests in docker
    • Get your feedback remotely thanks to ngrok
    • Use mpeg-4 preview plugin to watch videos from inside codespaces :) ...

πŸ‘· Example setup for eslint and tsconfig

Project structure:

project_dir
└── src
└── tests
    └── e2e
        └── .eslintrc.js
        └── support.js
        └── tsconfig.json
        └── specs
            └── example-spec.js
        └── pages
            └── example-page.js
  1. Create .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`,
};
  1. Create 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..

  1. Create 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": ["**/*.*"]
}
  1. You're done! πŸŽ‰

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

⚑ Important notes

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:

  • passes welcome page
  • imports wallet
  • changes network (defaults to goerli) or creates custom network and changes to it (depending on your setup)
  • switches back to Cypress window and starts testing

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:

  1. NETWORK_NAME => ex: synthetix
  2. RPC_URL => ex: https://synthetix-node.io
  3. CHAIN_ID => ex: 123
  4. SYMBOL => ex: SNX
  5. BLOCK_EXPLORER (optional) => ex: https://synthetix-explorer.io
  6. 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.

🐳 Using with Docker

Docker is awesome for CI. Give it a try.

Requirements

Some neat features

  • based on docker-e2e ❀
  • full screen video recording πŸŽ₯ (together with metamask extension)
  • VNC & noVNC support πŸ–₯️ (very easy to debug with browser)
  • ngrok πŸ”Œ integration (exposes noVNC for everyone)
    • remote: https://.ngrok.io/vnc.html?autoconnect=true (check logs for url)

How to run e2e tests for Synpress using Docker

  1. git clone [email protected]:Synthetixio/synpress.git
  2. cd synpress
  3. (optional) Fill env vars inside .env file
  4. (with foundry; preferred) docker-compose --profile synpress --profile foundry up --build --exit-code-from synpress or ./start-tests.sh
    • (without foundry) docker-compose up --profile synpress --build --exit-code-from synpress
  5. (with foundry and ngrok) 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.

πŸ’β€β™‚οΈ CI tips & tricks

πŸ§ͺ Usage & commands

  • synpress run to run tests
  • synpress 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

πŸ“ƒ Environmental variables

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 issues 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 indicates that tests are running from CI/CD pipeline

🚒 Release process

  1. Create PR from dev branch to master branch
  2. Merge it (new -beta version is automatically released)
  3. Run GitHub Action workflow named Release CI with 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:

  1. Switch to master branch and pull latest changes
  2. Run pnpm release:patch/minor/major command
  3. Keep dev branch up to date with master

Above actions will lead to:

  • New npm node module release
  • New GitHub packages node module release
  • New GitHub release (tagged) created with changelog from commit messages

πŸ“ More resources

More Repositories

1

synthetix

Synthetix Solidity smart contracts
JavaScript
1,177
star
2

synthetix-exchange

The Synthetix Exchange dApp code
TypeScript
121
star
3

synthetix-v3

TypeScript
117
star
4

SIPs

The Synthetix Improvement Proposal repository
Jupyter Notebook
104
star
5

staking

A dAPP for minting, burning, and earning on the Synthetix Protocol.
TypeScript
81
star
6

synthetix-mintr

Synthetix's Mintr v2.0: Lock up SNX to mint sUSD, claim weekly SNX and sUSD rewards for staking in the system..
JavaScript
75
star
7

synthetix-js

[deprecated] Please use https://github.com/Synthetixio/js-monorepo/tree/master/packages/contracts-interface
JavaScript
63
star
8

synthetix-subgraph

All sources for the handful of Synthetix subgraphs indexed by The Graph
TypeScript
61
star
9

js-monorepo

Standard JS conventions and utilities for working with Synthetix
TypeScript
31
star
10

cannon

Develop and test your smart contracts with existing protocols and tools inspired by Docker and Terraform
TypeScript
28
star
11

synthetix-data

A utility to query for data on Synthetix usage
JavaScript
24
star
12

simulation

Agent-based model of the proposed stablecoin.
Python
23
star
13

codegen-graph-ts

Create generated code based on a subgraph from The Graph
TypeScript
21
star
14

synthetix-website

Synthetix website powered by next.js + typescript
TypeScript
17
star
15

synthetix-docs

System and developer documentation for Synthetix
JavaScript
17
star
16

snx-grants-dao

TypeScript
16
star
17

perps-keepers

Keepers incentivised to maintain health on Synthetix Perps
TypeScript
16
star
18

synthetix-node

JavaScript
12
star
19

synthetix-v3-labs

Free experimentation on v3 components
Solidity
11
star
20

number-guessing-game

Example market for Synthetix v3
Solidity
11
star
21

hardhat-interact

Execute commands on deployed contracts using a helpful TUI. Inspired by `hardhat inteteract` command on https://github.com/Synthetixio/synthetix
TypeScript
10
star
22

kwenta

DEPRECATED. Please use: https://github.com/Kwenta/kwenta
TypeScript
10
star
23

synthetix-assets

Synthetix Assets
10
star
24

v3ui

Synthetix V3 UI Monorepo
TypeScript
10
star
25

js

BETA: Javascript library for interacting with the Synthetix protocol
TypeScript
9
star
26

optimistic-trader

Demo app to script your L2 bot
JavaScript
9
star
27

synthetix-dashboard

Synthetix Dashboard website
CSS
9
star
28

futures-keepers

TypeScript
8
star
29

vanity-contract

Tool to mine vanity ETH contract address
JavaScript
8
star
30

synthetix-deployments

Infrastructure-as-code definition for Synthetix contracts on all of its deployed networks
JavaScript
7
star
31

python-sdk

A python SDK for interactions with the Synthetix protocol
Python
7
star
32

contract-linker

Auto-linking to Synthetix contracts
JavaScript
5
star
33

tokenvest

JavaScript
5
star
34

synthetix-sandbox

Solidity
5
star
35

docker-sec-tools

Docker container based on docker-node with security-oriented tools included.
Dockerfile
4
star
36

Synthetix-Gitbook-v3

4
star
37

bfp-market

swsteth <> 1x short eth. l1 perp
TypeScript
4
star
38

deprecated-whitepaper

DEPRECATED - The old Havven White Paper
TeX
4
star
39

snx-v3-prototype

TypeScript
4
star
40

data

Create and host a database replica of activity on the Synthetix protocol
HTML
4
star
41

synthetix-scripts

A set of cli utilities for the Synthetix protocol
JavaScript
4
star
42

docker-e2e

Docker container based on docker-node with e2e-related tools included.
Dockerfile
3
star
43

synthetix-shaula-frontend

UI to interact with the new Synthetix Shaula release containing Multi-Collateral Loans and Shorting features.
JavaScript
2
star
44

synthetix-utility

Utility smart contracts to be used with the Synthetix dApps
2
star
45

synthetix-translations

Synthetix Translations module! Internationalization inside the Synthetix dApp ecosystem
JavaScript
2
star
46

synthetix-delegate

Synthetix Delegate
TypeScript
2
star
47

example-rewards-distributor

Example repository for deploying a rewards distributor
Solidity
2
star
48

perps-event-decoder

Decode perps transaction events
JavaScript
2
star
49

docker-node

Docker containers based on official node images used across Synthetix repositories for CI purposes.
Dockerfile
2
star
50

utility-contracts

A collection of useful smart contract components. (internal)
Python
2
star
51

synthetix-router

TypeScript
2
star
52

spartan-council

Custom Contract for issuing NFT tokens for SIP 93: Supersede SIP-90 to Delegated Council Governance.
JavaScript
2
star
53

fork

Simple utility to fork the Synthetix protocol for testing and benchmarking
JavaScript
1
star
54

ui

react ui components
TypeScript
1
star
55

docker-shared

Shared resources used across Synthetix docker images.
JavaScript
1
star
56

js-template

A starter project for JS-based projects (predominantly nodejs)
JavaScript
1
star
57

safe-synthetix-module

Customization for Gnosis Safes used to govern Synthetix protocol
Solidity
1
star
58

snx-ambassadors-dapp

The dApp for the delegation of voting powers to the SNX Ambassadors
TypeScript
1
star
59

stats

TypeScript
1
star
60

roadmap

Roadmap
1
star
61

ipfs-follower

Scripts for automatic ipfs-cluster-follower node installation
Shell
1
star
62

v3-markets-prototype

TypeScript
1
star
63

litepapers

All the Synthetix Litepaper versions that have been published in the past.
1
star
64

cannon-plugin-router

Cannon Plugin for generating Router
JavaScript
1
star
65

Synthetix-Gitbook-Docs

1
star
66

perps-ecosystem

TypeScript
1
star
67

trusted-multicall-forwarder

ERC-2771 compliant trusted forwarder including Multicall3 functionality with error bubbling
Solidity
1
star
68

sample-v3-keeper

Prototype V3 keeper using the Synthetix Python SDK
Python
1
star
69

sdk-playground

Tools and scripts using the Synthetix python sdk
Python
1
star
70

erc7412

Reference implementation for ERC-7412
Solidity
1
star
71

providers

Javascript library for handling providers on Layer 1 & Optimism Layer 2
TypeScript
1
star
72

snax-core

1
star