Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable synpress in order to connect metamask with jumper app #1560

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
628a84c
feat: enable synpress in order to connect metamask with jumper app
bojank93 Dec 2, 2024
69d2568
feat: add yarn.lock file
bojank93 Dec 2, 2024
3352405
fix: modify playwright.yml file to build local env in CI
bojank93 Dec 2, 2024
af7a488
fix: fixing playwright yaml file by adding wait on to make sure local…
bojank93 Dec 2, 2024
957f481
fix: modify playwright config to reuse existing server
bojank93 Dec 2, 2024
1ee0a1c
fix: modify import of json files in e2e tests
bojank93 Dec 2, 2024
47e5dfa
fix: increase number of workers in CI
bojank93 Dec 2, 2024
7eb4cc5
fix: fix number of workers in CI
bojank93 Dec 2, 2024
0ab0614
fix: fix number of workers
bojank93 Dec 2, 2024
da01b28
Merge branch 'develop' into e2e/integrate-synpress
ilijabojanovic Dec 2, 2024
94cc059
increase timeout of jobs
bojank93 Dec 3, 2024
e816218
fix: add more workers in CI
bojank93 Dec 3, 2024
3ee339e
feat: enable sharded tests
bojank93 Dec 4, 2024
ac52fa9
Merge branch 'develop' into e2e/integrate-synpress
bojank93 Dec 4, 2024
c5dd2ae
added building synpress cache
bojank93 Dec 4, 2024
c265ca4
Merge branch 'e2e/integrate-synpress' of https://github.com/jumperexc…
bojank93 Dec 4, 2024
55595e6
fix: improve commands
bojank93 Dec 4, 2024
4bae7d7
fix: move building cache inside test not in CI
bojank93 Dec 4, 2024
99c9de4
fix: delete redundant tests
bojank93 Dec 4, 2024
b178442
fix: increase timeout to 20mins
bojank93 Dec 4, 2024
5f6be6f
fix: remove --force flag from builiding synpress cache command
bojank93 Dec 4, 2024
640c56d
feat: imrpove connect wallet test
bojank93 Dec 4, 2024
09a531b
fix: make connectWallet setup test working in CI
bojank93 Dec 4, 2024
5166178
feat: modify synpressCache function
bojank93 Dec 4, 2024
7a14786
fix: synpressCache function
bojank93 Dec 4, 2024
c151d0f
fix: delete cache-synpress folder if exists
bojank93 Dec 4, 2024
2712102
fix: make sure wallet cache is completed
bojank93 Dec 4, 2024
0026b95
revert changes in synpressCache function
bojank93 Dec 4, 2024
a83fa08
fix: change order of steps inside playwright.yml
bojank93 Dec 4, 2024
707b5f5
fix: delete step for inslling xvfb in CI
bojank93 Dec 4, 2024
db8c022
fix: remove reduntant code
bojank93 Dec 4, 2024
ba365dd
fix: fix typo in yaml file
bojank93 Dec 4, 2024
de7313f
fix: fixing command in package.json
bojank93 Dec 4, 2024
6574830
fix: fix wait-on command
bojank93 Dec 4, 2024
20acafb
fix:change the command for building cache
bojank93 Dec 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 18
- name: Install dependencies
run: yarn install
- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium
- name: Build env and build synpress cache
run: yarn dev & npx wait-on http://localhost:3000 && yarn build:cache:ci --force tests/wallet-setup/
- name: Run Playwright tests
env:
PLAYWRIGHT_JSON_OUTPUT_NAME: report-${{ matrix.shard }}.json
run: |
yarn playwright test \
yarn run test:ci:e2e \
--shard ${{ matrix.shard }}/${{ strategy.job-total }} \
--reporter=json
- uses: daun/playwright-report-summary@v3
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ yarn-error.log*

# testing
/coverage
.cache-synpress/**
.tests/snapshots.spec.ts/**


npm-debug.log*
yarn-debug.log*
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "jumper.exchange",
"version": "1.0.0",
"type": "module",
"private": true,
"repository": "https://github.com/jumperexchange/jumper-exchange",
"packageManager": "[email protected]",
Expand Down Expand Up @@ -33,6 +34,7 @@
"@solana/wallet-adapter-solflare": "^0.6.28",
"@solana/web3.js": "^1.95.4",
"@strapi/blocks-react-renderer": "^1.0.1",
"@synthetixio/synpress": "4.0.0-alpha.7",
"@tanstack/react-query": "^5.59.20",
"@widgetbot/react-embed": "^1.9.0",
"accept-language": "^3.0.20",
Expand All @@ -59,11 +61,13 @@
"sharp": "^0.33.5",
"siwe": "^2.3.2",
"uuid": "^10.0.0",
"wait-on": "^8.0.1",
"zustand": "^4.5.5"
},
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@eslint/eslintrc": "^3.1.0",
"@metamask/test-dapp": "8.2.0",
"@next/eslint-plugin-next": "^14.2.17",
"@playwright/test": "^1.48.2",
"@types/gtag.js": "^0.0.20",
Expand Down Expand Up @@ -106,7 +110,12 @@
"fix:all-files": "eslint . --ext .ts,.tsx,.js,.jsx --fix",
"pre-commit": "lint-staged",
"pre-push": "yarn && yarn build",
"i18next-resources-for-ts": "i18next-resources-for-ts interface -i ./src/i18n/translations/en -o ./src/i18n/resources.d.ts"
"i18next-resources-for-ts": "i18next-resources-for-ts interface -i ./src/i18n/translations/en -o ./src/i18n/resources.d.ts",
"test:ci:e2e": "xvfb-run npx playwright test",
"test:e2e-real": "npx playwright test --headed",
"build:cache": "synpress --headless",
"build:cache:ci": "xvfb-run npx synpress"

},
"lint-staged": {
"**/*.(ts|tsx|js)": [
Expand Down
12 changes: 6 additions & 6 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defineConfig, devices } from '@playwright/test';

import { PlaywrightTestConfig } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
Expand All @@ -17,7 +17,7 @@ require('dotenv').config();
// const baseURL = `http://localhost:${PORT}`;

export default defineConfig({
timeout: 60 * 1000,
timeout: 120 * 1000,
expect: {
timeout: 40 * 1000,
},
Expand All @@ -27,9 +27,9 @@ export default defineConfig({
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 2,
retries: process.env.CI ? 3 : 3,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : 1,
workers: process.env.CI ? 4 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [['html'], ['json', { outputFile: 'test-results.json' }]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
Expand All @@ -44,7 +44,7 @@ export default defineConfig({
command: 'yarn run dev',
url: 'http://localhost:3000',
timeout: 200 * 1000,
reuseExistingServer: !process.env.CI,
reuseExistingServer: true,
},

/* Configure projects for major browsers */
Expand Down
25 changes: 25 additions & 0 deletions synpressCache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { spawn } from 'child_process';

async function buildSynpressCache() {
console.log('Building Synpress cache...');

return new Promise<void>((resolve, reject) => {
const process = spawn('yarn', ['build:cache', '--force', 'tests/wallet-setup/'], { stdio: 'inherit' });

process.on('close', (code) => {
if (code === 0) {
console.log('Synpress cache build complete.');
resolve();
} else {
console.error(`Failed to build Synpress cache with exit code ${code}`);
reject(new Error(`Cache build failed with code ${code}`));
}
});

process.on('error', (error) => {
console.error('Error during cache build:', error);
reject(error);
});
});
}
export default buildSynpressCache;
34 changes: 34 additions & 0 deletions tests/connectWallet.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { testWithSynpress } from '@synthetixio/synpress-core';
import { MetaMask, metaMaskFixtures } from '@synthetixio/synpress';
import { openOrCloseMainMenu , itemInMenu, closeWelcomeScreen } from './testData/commonFunctions';
import basicSetup from './wallet-setup/basic.setup';

const test = testWithSynpress(metaMaskFixtures(basicSetup));

const { expect } = test;
test.describe('Connect Metamask with Jumper app and open /profile page',()=>{
test('should connect wallet to Jumper', async ({
context,
page,
extensionId,
}) => {
const metamask = new MetaMask(
context,
page,
basicSetup.walletPassword,
extensionId,
);
const connectWalletButton = page.locator('#connect-wallet-button');
const metaMaskWalletOption = page.locator('xpath=//span[normalize-space(text())="MetaMask"]');
const availableMissionTitle = page.locator('xpath=//p[normalize-space(text())="Available Missions"]');
await expect(connectWalletButton).toBeEnabled();
await connectWalletButton.click();
await metaMaskWalletOption.click();
await metamask.connectToDapp(['Account 1']);
await closeWelcomeScreen(page)
await openOrCloseMainMenu(page);
await itemInMenu(page, 'Jumper Profile');
await page.locator('.profile-page').isVisible();
await expect(availableMissionTitle).toBeVisible();
});
})
10 changes: 1 addition & 9 deletions tests/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test';
import values from '../tests/testData/values.json';
import values from '../tests/testData/values.json' assert { type:"json"};
import {
closeWelcomeScreen,
expectBackgroundColorToHaveCss,
Expand Down Expand Up @@ -135,14 +135,6 @@ test.describe('Jumper full e2e flow', () => {
await expect(searchBar).toBeVisible();
});

test.skip('Should be able to navigate to Supefest', async ({ page }) => {
const learnMoreButton = page.locator('#learn-more-button');
await openOrCloseMainMenu(page);
await itemInMenu(page, 'Superfest Festival');
await expect(learnMoreButton).toBeVisible();
await expect(page).toHaveURL(values.localSuperfestURL);
});

test('Should open Developers section inside menu', async ({ page }) => {
await openOrCloseMainMenu(page);
await itemInMenu(page, 'Developers');
Expand Down
2 changes: 1 addition & 1 deletion tests/swapActions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from '@playwright/test';
import chainData from './testData/chainData.json';
import chainData from './testData/chainData.json' assert {type:"json"};
import {
buildUlParams,
checkIfBestReturnLabelIsVisible,
Expand Down
2 changes: 1 addition & 1 deletion tests/testData/commonFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function checkTheNumberOfMenuItems(
}

export async function itemInMenu(page, option: string) {
await page.getByRole('menuitem', { name: option }).click({ timeout: 20000 });
await page.getByRole('menuitem', { name: option }).click();
}

export async function closeWelcomeScreen(page: Page) {
Expand Down
1 change: 0 additions & 1 deletion tests/themeManipulation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test } from '@playwright/test';
import {
closeWelcomeScreen,
openOrCloseMainMenu,
expectBackgroundColorToHaveCss,
} from './testData/commonFunctions';

Expand Down
11 changes: 11 additions & 0 deletions tests/wallet-setup/basic.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MetaMask, defineWalletSetup } from '@synthetixio/synpress';

const SEED_PHRASE =
'test test test test test test test test test test test junk';
const PASSWORD = 'SynpressIsAwesomeNow!!!';

export default defineWalletSetup(PASSWORD, async (context, walletPage) => {
const metamask = new MetaMask(context, walletPage, PASSWORD);

await metamask.importWallet(SEED_PHRASE);
});
25 changes: 25 additions & 0 deletions tests/wallet-setup/connected.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { MetaMask, getExtensionId ,defineWalletSetup } from '@synthetixio/synpress'
import 'dotenv/config'

export const SEED_PHRASE =
'test test test test test test test test test test test junk';
export const PASSWORD = 'Testing1234!'

export default defineWalletSetup(PASSWORD, async (context, walletPage) => {
// This is a workaround for the fact that the MetaMask extension ID changes.
// This workaround won't be needed in the near future! 😁
const extensionId = await getExtensionId(context, 'MetaMask')

const metamask = new MetaMask(context, walletPage, PASSWORD, extensionId)

await metamask.importWallet(SEED_PHRASE)

const page = await context.newPage()

// Go to a locally hosted MetaMask Test Dapp.
await page.goto('http://localhost:3000')

await page.locator('#connect-wallet-button').click()

// await metamask.connectToDapp(['Account 1'])
})
5 changes: 5 additions & 0 deletions tests/wallet-setup/synpress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { testWithSynpress, metaMaskFixtures } from '@synthetixio/synpress'

import connectedSetup from '../wallet-setup/connected.setup'

export default testWithSynpress(metaMaskFixtures(connectedSetup))
Loading
Loading