-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from gnosis/e2e-tests
E2E tests
- Loading branch information
Showing
30 changed files
with
4,593 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
name: Tests | ||
name: CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: "**/node_modules" | ||
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} | ||
- run: yarn | ||
working-directory: ./extension | ||
- run: yarn run check | ||
cache: "yarn" | ||
cache-dependency-path: "**/yarn.lock" | ||
- run: yarn install --frozen-lockfile | ||
working-directory: ./extension | ||
- run: yarn build | ||
- name: Run static checks | ||
run: yarn run check | ||
working-directory: ./extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: End-to-end tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
cache: "yarn" | ||
cache-dependency-path: "**/yarn.lock" | ||
- name: Build extension | ||
working-directory: ./extension | ||
run: | | ||
yarn install --frozen-lockfile | ||
yarn build | ||
- run: yarn install --frozen-lockfile | ||
working-directory: ./e2e-tests | ||
env: | ||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true" | ||
- name: Run end-to-end tests | ||
uses: mujo-code/[email protected] | ||
env: | ||
CI: "true" | ||
SEED_PHRASE: ${{ secrets.E2E_TESTS_SEED_PHRASE }} | ||
with: | ||
args: yarn --cwd ./e2e-tests start | ||
- name: Upload failing test screenshots | ||
if: failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: failing-test-screenshots | ||
path: e2e-tests/output/screenshots | ||
retention-days: 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,16 +10,16 @@ jobs: | |
runs-on: ubuntu-latest | ||
name: Deploy Landing Page | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
- run: npm install -g yarn | ||
cache: "yarn" | ||
cache-dependency-path: "**/yarn.lock" | ||
- run: yarn install --frozen-lockfile | ||
working-directory: ./landing-page | ||
- run: yarn build | ||
working-directory: ./landing-page | ||
|
||
- name: Deploy to Github Pages | ||
uses: JamesIves/[email protected] | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"version": "0.2", | ||
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json", | ||
"language": "en", | ||
"words": [ | ||
"auryn", | ||
"chainsafe", | ||
"dappeteer", | ||
"headful" | ||
], | ||
"flagWords": [], | ||
"ignorePaths": [ | ||
"package.json", | ||
"yarn.lock", | ||
"node_modules/**", | ||
"tsconfig.json" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SEED_PHRASE=food garment clinic together tiny spread ball favorite slush link blur undo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.log | ||
.DS_Store | ||
.env | ||
/node_modules | ||
/output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint", | ||
"esbenp.prettier-vscode", | ||
"streetsidesoftware.code-spell-checker" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"editor.tabSize": 2, | ||
"editor.formatOnSave": true, | ||
"cSpell.userWords": [], // only use words from .cspell.json | ||
"cSpell.enabled": true, | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"typescript.enablePromptUseWorkspaceTsdk": true, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
}, | ||
"jest.jestCommandLine": "yarn start", | ||
"jest.autoRun": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', { targets: { node: 'current' } }], | ||
'@babel/preset-typescript', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Wallet } from 'ethers' | ||
|
||
if (!process.env.SEED_PHRASE) { | ||
throw new Error('SEED_PHRASE env variable is not set') | ||
} | ||
|
||
export const account = Wallet.fromMnemonic(process.env.SEED_PHRASE).address // 0xB07520a4494793461Cf8762246B7D8695548C22B | ||
|
||
if (account !== '0xB07520a4494793461Cf8762246B7D8695548C22B') { | ||
console.warn( | ||
`The test Safe and module setup that some tests rely on is using the MetaMask account 0xB07520a4494793461Cf8762246B7D8695548C22B. Your seed phrase is different: ${account}` | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import puppeteer, { Browser, Page } from 'puppeteer' | ||
|
||
import { promises } from 'fs' | ||
import os from 'os' | ||
import path from 'path' | ||
import NodeEnvironment from 'jest-environment-node' | ||
import { Dappeteer, getMetamaskWindow } from '@chainsafe/dappeteer' | ||
import { screenshot } from './screenshot' | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest_dappeteer_global_setup') | ||
|
||
interface GlobalAdditions { | ||
browser: Browser | ||
metamask: Dappeteer | ||
} | ||
|
||
class DappeteerEnvironment extends NodeEnvironment { | ||
global: NodeEnvironment['global'] & GlobalAdditions | ||
|
||
async setup() { | ||
await super.setup() | ||
// get the wsEndpoint | ||
const wsEndpoint = await promises.readFile( | ||
path.join(DIR, 'wsEndpoint'), | ||
'utf8' | ||
) | ||
if (!wsEndpoint) throw new Error('wsEndpoint not found') | ||
|
||
// connect to puppeteer | ||
const browser = await puppeteer.connect({ | ||
browserWSEndpoint: wsEndpoint, | ||
}) | ||
|
||
this.global.browser = browser | ||
this.global.metamask = await getMetamaskWindow(browser) | ||
} | ||
|
||
// Take a screenshot of the page on failing tests | ||
async handleTestEvent(event, state) { | ||
if (event.name === 'test_fn_failure') { | ||
console.log('Taking screenshot on failing test...') | ||
|
||
const page = await this.getActivePilotPage() | ||
if (page) { | ||
await screenshot(page, state.currentlyRunningTest.name) | ||
await page.close() | ||
} | ||
await screenshot( | ||
this.global.metamask.page, | ||
`${state.currentlyRunningTest.name}-metamask` | ||
) | ||
} | ||
} | ||
|
||
async getActivePilotPage(): Promise<Page | undefined> { | ||
const pages = await this.global.browser.pages() | ||
const pilotPages = pages.filter((page) => | ||
page.url().startsWith('https://pilot.gnosisguild.org') | ||
) | ||
let lastModifiedPilotPage: Page | undefined = undefined | ||
let lastModifiedDate = 0 | ||
let l = pilotPages[0] | ||
for (const pilotPage of pilotPages) { | ||
const lastModified = new Date( | ||
await pilotPage.evaluate(() => document.lastModified) | ||
).getTime() | ||
if (lastModified > lastModifiedDate) { | ||
lastModifiedDate = lastModified | ||
lastModifiedPilotPage = pilotPage | ||
} | ||
} | ||
if (!lastModifiedPilotPage) { | ||
console.warn('No active Pilot extension page found') | ||
} | ||
return lastModifiedPilotPage | ||
} | ||
} | ||
|
||
module.exports = DappeteerEnvironment |
Oops, something went wrong.