GithubHelp home page GithubHelp logo

isabella232 / synpress Goto Github PK

View Code? Open in Web Editor NEW

This project forked from smartcontractkit/synpress

0.0 0.0 0.0 4.15 MB

Synpress is an wrapper around Cypress.io with metamask support thanks to puppeteer.

License: MIT License

JavaScript 100.00%

synpress's Introduction

npm version Synpress CI CodeQL Release CI Discord Twitter Follow

⚙️ Synpress

Synpress is an wrapper around Cypress.io with metamask support thanks to puppeteer.

Synpress makes sure to always use latest version of metamask before tests are ran.

It also provides an easy way to use metamask straight from your e2e tests.

Feel free to take a look at kwenta repository for examples of usage.

For additional custom commands and their examples, check here.

👷 Example setup for eslint and tsconfig

Project structure:

project_dir
└── src
└── tests
    └── e2e
        └── .eslintrc.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 tsconfig.json inside your tests folder (/project_dir/tests/e2e):
{
    "compilerOptions": {
        "allowJs": true,
        "baseUrl": "../../node_modules",
        "types": ["cypress", "@types/puppeteer-core", "@synthetixio/synpress/support", "cypress-wait-until", "@testing-library/cypress"],
        "outDir": "./output"
    },
    "include": ["**/*.*"]
}
  1. You're done! 🎉

If you would like to use custom paths for your tests and configs, feel free to mirror default synpress config and modify it for your needs. Then you can direct synpress to use it with --configFile flag.

For example: synpress run --configFile __tests__/e2e/customConfig.json

⚡ Important

Synpress doesn't seem to communicate with metamask properly if "chromeWebSecurity": false flag is set. More about it here.

Tests work only in headed mode because extensions are not supported in headless mode in puppeteer and Cypress. It's intended to be used in conjunction with xvfb on CI.

There is a global before() which runs metamask setup before all tests:

  • passes welcome page
  • imports wallet
  • changes network (defaults to kovan) 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, etc..'.

To change default network (kovan), you can use NETWORK_NAME environmental variable, for example: NETWORK_NAME=rinkeby.

Available choices are: mainnet, ropsten, kovan, rinkeby, goerli 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 (optional) => 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=9.3.0 or METAMASK_VERSION=latest.

If you don't want to use environmental variables, you can modify setupMetamask() to following:

setupMetamask(secretWords, network, password), for example: setupMetamask('word1, word2, etc..', 'mainnet', 'password').

You can also add and switch to custom network by passing an object instead of string inside setupMetamask(secretWords, 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 enironmental variable.

🧪 Usage

  • synpress run to run tests
  • synpress open to open Cypress UI

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 a JSON 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 a JSON file where configuration values are set
  -h, --help                display help for command

🚢 Release process

  1. Create PR from dev branch to master branch
  2. Merge it
  3. Run GitHub Action workflow named Release CI with patch|minor|major depending on your needs.

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 npm run 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

synpress's People

Contributors

ainsleybc avatar alejandro-larumbe avatar dependabot[bot] avatar drptbl avatar tjbigelow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.