diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 80c39f74d..1f61f68aa 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,25 +1,25 @@ version: 2 updates: - - package-ecosystem: "github-actions" - directory: "/" + - package-ecosystem: 'github-actions' + directory: '/' schedule: - interval: "daily" + interval: 'daily' - - package-ecosystem: "npm" - directory: "/" + - package-ecosystem: 'npm' + directory: '/' schedule: - interval: "daily" + interval: 'daily' open-pull-requests-limit: 5 - target-branch: "dev" + target-branch: 'dev' allow: - - dependency-name: "cypress" - dependency-type: "production" - - dependency-name: "synthetix-*" - dependency-type: "production" - - dependency-name: "@synthetixio/*" - dependency-type: "production" + - dependency-name: 'cypress' + dependency-type: 'production' + - dependency-name: 'synthetix-*' + dependency-type: 'production' + - dependency-name: '@synthetixio/*' + dependency-type: 'production' labels: - - "npm" - - "dependencies" + - 'npm' + - 'dependencies' pull-request-branch-name: - separator: "-" + separator: '-' diff --git a/.github/workflows/audit_and_lint.yml b/.github/workflows/audit_and_lint.yml index 349783be0..84d5a2422 100644 --- a/.github/workflows/audit_and_lint.yml +++ b/.github/workflows/audit_and_lint.yml @@ -5,17 +5,20 @@ on: pull_request: branches: [master, dev] +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true + jobs: audit: # run only on master/dev branch and pull requests - if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request' + if: + github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || + github.event_name == 'pull_request' runs-on: ubuntu-latest container: - image: ghcr.io/synthetixio/docker-sec-tools/alpine:16.14 - credentials: - username: synthetixio - password: ${{ secrets.GH_PACKAGES_READ_ONLY }} + image: synthetixio/docker-sec-tools:16.14-alpine steps: - name: Checkout @@ -25,19 +28,21 @@ jobs: run: npm audit --audit-level=critical - name: Lockfile lint - run: lockfile-lint -p package-lock.json --type npm --allowed-hosts npm github.com --allowed-schemes "https:" "git+ssh:" --empty-hostname false + run: + lockfile-lint -p package-lock.json --type npm --allowed-hosts npm + github.com --allowed-schemes "https:" "git+ssh:" --empty-hostname + false build: needs: audit # run only on audit success or audit skipped - if: always() && (needs.audit.result == 'success' || needs.audit.result == 'skipped') + if: + always() && (needs.audit.result == 'success' || needs.audit.result == + 'skipped') runs-on: ubuntu-latest container: - image: ghcr.io/synthetixio/docker-node/alpine:16.14 - credentials: - username: synthetixio - password: ${{ secrets.GH_PACKAGES_READ_ONLY }} + image: synthetixio/docker-node:16.14-alpine steps: - name: Checkout @@ -66,13 +71,17 @@ jobs: - name: Lint # run only on master/dev branch and pull requests - if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request' + if: + github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || + github.event_name == 'pull_request' run: npm run lint:sarif - name: Upload lint results # run if lint failed and only on master/dev branch and pull requests - if: always() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request') - uses: github/codeql-action/upload-sarif@c7f292ea4f542c473194b33813ccd4c207a6c725 # pin@codeql-bundle-20210517 + if: + always() && (github.ref == 'refs/heads/master' || github.ref == + 'refs/heads/dev' || github.event_name == 'pull_request') + uses: github/codeql-action/upload-sarif@b398f525a5587552e573b247ac661067fafa920b # pin@codeql-bundle-20210517 with: sarif_file: lint-results.sarif continue-on-error: true diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 9d2ac0500..ba320e779 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -17,10 +17,10 @@ jobs: uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # pin@v2 - name: Initialize CodeQL - uses: github/codeql-action/init@c7f292ea4f542c473194b33813ccd4c207a6c725 + uses: github/codeql-action/init@b398f525a5587552e573b247ac661067fafa920b with: queries: security-and-quality languages: javascript - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@c7f292ea4f542c473194b33813ccd4c207a6c725 + uses: github/codeql-action/analyze@b398f525a5587552e573b247ac661067fafa920b diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index de039e3f4..0641e6721 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,7 +37,9 @@ jobs: path: | .npm-cache node_modules - key: ${{ runner.os }}-ubuntu-node-16-${{ hashFiles('**/package-lock.json') }} + key: + ${{ runner.os }}-ubuntu-node-16-${{ + hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-ubuntu-node-16- continue-on-error: true diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 000000000..fb940393d --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,10 @@ +# Autoformatter friendly markdownlint config (all formatting rules disabled) +default: true +blank_lines: false +bullet: false +html: false +indentation: false +line_length: false +spaces: false +url: false +whitespace: false diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index a873ca7a7..000000000 --- a/.prettierrc.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - semi: true, - trailingComma: 'all', - singleQuote: true, - printWidth: 80, - tabWidth: 2, - arrowParens: 'avoid', -}; diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 000000000..55126634a --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,7 @@ +semi: true +trailingComma: all +singleQuote: true +printWidth: 80 +tabWidth: 2 +arrowParens: avoid +proseWrap: always diff --git a/.trunk/.gitignore b/.trunk/.gitignore new file mode 100644 index 000000000..203835328 --- /dev/null +++ b/.trunk/.gitignore @@ -0,0 +1,4 @@ +*out +*logs +plugins +user_trunk.yaml diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml new file mode 100644 index 000000000..9814eb383 --- /dev/null +++ b/.trunk/trunk.yaml @@ -0,0 +1,26 @@ +version: 0.1 +cli: + version: 0.16.1-beta + sha256: + darwin_arm64: 3fb733a9907ec366d86d06313d1b0c956a0f9e86cdbaeaaa72ecf29fb9de17a7 + darwin_x86_64: d15589aaf2128d4a732f96f101ccfad433532d2027a9b809c74169371c7e270e + linux_x86_64: 87245d043c5f0c9bf5b21ff66a43df715f459068bd2e47964c7d517cca074007 +lint: + enabled: + - actionlint@1.6.17 + - eslint@8.23.0 + - git-diff-check@SYSTEM + - gitleaks@8.11.2 + - markdownlint@0.32.2 + - prettier@2.7.1 + ignore: + - linters: [ALL] + paths: + - node_modules/** + - tests/test-dapp + - downloads + - tests/e2e/videos + - tests/e2e/screenshots + threshold: + - linters: [ALL] + level: high diff --git a/README.md b/README.md index 30cdb01ff..d517d5bf1 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Release CI](https://github.com/Synthetixio/synpress/actions/workflows/release.yml/badge.svg?branch=master)](https://github.com/Synthetixio/synpress/actions/workflows/release.yml) [![Discord](https://img.shields.io/discord/961408653502599171.svg?color=768AD4&label=discord&logo=https%3A%2F%2Fdiscordapp.com%2Fassets%2F8c9701b98ad4372b58f13fd9f65f966e.svg)](https://discordapp.com/channels/961408653502599171/) [![Twitter Follow](https://img.shields.io/twitter/follow/synpress_.svg?label=Synpress_&style=social)](https://twitter.com/Synpress_) + #
@@ -12,30 +13,45 @@
#
-[Synpress](https://github.com/Synthetixio/synpress) is a wrapper around [Cypress.io](https://github.com/cypress-io/cypress) with [metamask](https://metamask.io/) support thanks to [puppeteer](https://github.com/puppeteer/puppeteer).
+[Synpress](https://github.com/Synthetixio/synpress) is a wrapper around
+[Cypress.io](https://github.com/cypress-io/cypress) with
+[metamask](https://metamask.io/) support thanks to
+[puppeteer](https://github.com/puppeteer/puppeteer).
-Synpress makes sure to always use latest version of metamask before tests are ran.
+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.
-For usage examples, feel free to take a look at [kwenta](https://github.com/kwenta/kwenta/tree/master/tests/e2e), [staking](https://github.com/Synthetixio/staking/tree/master/tests/e2e) or [synpress](https://github.com/Synthetixio/synpress/tree/master/tests/e2e) repository.
+For usage examples, feel free to take a look at
+[kwenta](https://github.com/kwenta/kwenta/tree/dev/tests/e2e),
+[staking](https://github.com/Synthetixio/staking/tree/dev/tests/e2e) or
+[synpress](https://github.com/Synthetixio/synpress/tree/dev/tests/e2e)
+repository.
-For additional custom commands and their examples, [check here](https://github.com/synthetixio/synpress/blob/master/support/index.d.ts).
+For additional custom commands and their examples,
+[check here](https://github.com/synthetixio/synpress/blob/dev/support/index.d.ts).
-To see in which direction Synpress is headed to, take a look at this [planning board](https://github.com/orgs/Synthetixio/projects/14).
+To see in which direction Synpress is headed to, take a look at this
+[planning board](https://github.com/orgs/Synthetixio/projects/14).
**Features:**
- metamask support
-- ability to use latest metamask or lock it's version to avoid unexpected failures related to metamask update
+- ability to use latest metamask or lock it's version to avoid unexpected
+ failures related to metamask update
- supports multi-lang of metamask, it doesn't depend on any labels
-- synpress is fully [tested](https://github.com/Synthetixio/synpress/tree/dev/tests/e2e/specs)
+- synpress is fully
+ [tested](https://github.com/Synthetixio/synpress/tree/dev/tests/e2e/specs)
- automatically waits for all XHR requests to be finished before tests are run
-- ability to fail e2e tests if there are any browser console error found during test run
+- ability to fail e2e tests if there are any browser console error found during
+ test run
- 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 programatically
+- 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
+ programatically
## ๐ท Example setup for eslint and tsconfig
@@ -47,6 +63,7 @@ project_dir
โโโ tests
โโโ e2e
โโโ .eslintrc.js
+ โโโ support.js
โโโ tsconfig.json
โโโ specs
โโโ example-spec.js
@@ -58,51 +75,89 @@ project_dir
```js
const path = require('path');
-const synpressPath = path.join(process.cwd(), '/node_modules/@synthetixio/synpress');
+const synpressPath = path.join(
+ process.cwd(),
+ '/node_modules/@synthetixio/synpress',
+);
module.exports = {
- extends: `${synpressPath}/.eslintrc.js`,
+ extends: `${synpressPath}/.eslintrc.js`,
};
```
-2. Create `tsconfig.json` inside your tests folder (`/project_dir/tests/e2e`):
+2. Create `support.js` inside your tests folder (`/project_dir/tests/e2e`):
+
+```js
+import '@synthetixio/synpress/support/index';
+```
+
+_^ hint: you can also use this file to extend synpress - add custom commands,
+and more.._
+
+3. Create `tsconfig.json` inside your tests folder (`/project_dir/tests/e2e`):
```json
{
- "compilerOptions": {
- "allowJs": true,
- "baseUrl": "../../node_modules",
- "types": ["cypress", "@types/puppeteer-core", "@synthetixio/synpress/support", "cypress-wait-until", "@testing-library/cypress"],
- "outDir": "./output"
- },
- "include": ["**/*.*"]
+ "compilerOptions": {
+ "allowJs": true,
+ "baseUrl": "../../node_modules",
+ "types": [
+ "cypress",
+ "@types/puppeteer-core",
+ "@synthetixio/synpress/support",
+ "cypress-wait-until",
+ "@testing-library/cypress"
+ ],
+ "outDir": "./output"
+ },
+ "include": ["**/*.*"]
}
```
-3. You're done! ๐
+4. 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, feel free to mirror [default synpress config](https://github.com/Synthetixio/synpress/blob/dev/synpress.json) and modify it for your needs. Then you can direct synpress to use it with `--configFile` flag.
+If you would like to use custom paths for your tests and configs, feel free to
+mirror
+[default synpress config](https://github.com/Synthetixio/synpress/blob/dev/synpress.config.js)
+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`
+For example: `synpress run --configFile __tests__/e2e/customConfig.config.js`
## โก Important
-Synpress doesn't seem to communicate with metamask properly if `"chromeWebSecurity": false` flag is set. More about it [here](https://github.com/Synthetixio/synpress/issues/17).
+Synpress doesn't seem to communicate with metamask properly if
+`"chromeWebSecurity": false` flag is set. More about it
+[here](https://github.com/Synthetixio/synpress/issues/17).
-Tests work only in headed mode because extensions are not supported in headless mode in [puppeteer](https://github.com/puppeteer/puppeteer/issues/659) and [Cypress](https://docs.cypress.io/api/plugins/browser-launch-api.html#Add-browser-extensions). It's intended to be used in conjunction with `xvfb` on CI.
+Tests work only in headed mode because extensions are not supported in headless
+mode in [puppeteer](https://github.com/puppeteer/puppeteer/issues/659) and
+[Cypress](https://docs.cypress.io/api/plugins/browser-launch-api.html#Add-browser-extensions).
+It's intended to be used in conjunction with `xvfb` on CI.
-There is a global [`before()`](https://github.com/synthetixio/synpress/blob/master/support/index.js#L25) which runs metamask setup before all tests:
+There is a global
+[`before()`](https://github.com/synthetixio/synpress/blob/dev/support/index.js#L27)
+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)
+- 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..'` or private key in an environmental variable called `PRIVATE_KEY`.
+It requires environmental variable called `SECRET_WORDS` to be present in
+following format => `'word1, word2, etc..'` or private key in an environmental
+variable called `PRIVATE_KEY`.
-To change default network (`kovan`), you can use `NETWORK_NAME` environmental variable, for example: `NETWORK_NAME=rinkeby`.
+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`.
+Available choices are: `mainnet`, `ropsten`, `kovan`, `rinkeby`, `goerli` and
+`localhost`.
To create and switch to custom network at metamask setup phase, use these:
@@ -113,26 +168,42 @@ To create and switch to custom network at metamask setup phase, use these:
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`.
+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()`](https://github.com/synthetixio/synpress/blob/master/support/index.js#L26) to following:
+If you don't want to use environmental variables, you can modify
+[`setupMetamask()`](https://github.com/synthetixio/synpress/blob/dev/support/index.js#L29)
+to following:
-`setupMetamask(secretWordsOrPrivateKey, network, password)`, for example: `setupMetamask('word1, word2, etc..', 'mainnet', 'password')`.
+`setupMetamask(secretWordsOrPrivateKey, 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(secretWordsOrPrivateKey, network, password)` function for `network` parameter.
+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` enironmental variable.
+If you want to use Etherscan API helpers, you will have to provide Etherscan API
+key using `ETHERSCAN_KEY` enironmental variable.
-To fail a test if there are any browser console errors, set `FAIL_ON_ERROR` to `1` or `true`.
+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 off with `CYPRESS_SKIP_RESOURCES_WAIT` environmental variable, set it to `1` or `true`.
+Automatic waiting for XHR requests to finish before tests start can be turned
+off with `CYPRESS_SKIP_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`.
+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`.
## ๐งช Usage
- `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`)
+- `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`):
@@ -144,7 +215,7 @@ launch tests
Options:
-b, --browser