Skip to content

Commit

Permalink
fix: flaky e2e tests (#1290)
Browse files Browse the repository at this point in the history
Closes #1298 
Closes #1262 
- Re-enabled E2E contract tests
- Fixed biome trying to validate files generated by playwright test runs
- Fixed Playwright tests starting up before CRX files are available, now
runs `build` beforehand.
- Fixed CRX dev server reloading during playwright tests, causing
instabilities
- Fixed NODE_ENV being set to default (production) on local E2E tests,
leading to the wrong version (i.e. production) being installed
- Fixed bug where only the first test file in a suite run would use the
local CRX build, it'd then download and use a production build of the
Wallet for the rest

---------

Co-authored-by: Luiz Gomes - LuizAsFight.eth <8636507+LuizAsFight@users.noreply.github.com>
Co-authored-by: fuel-service-user <134328775+fuel-service-user@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed May 28, 2024
1 parent 6e94172 commit 57f87f8
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 72 deletions.
10 changes: 10 additions & 0 deletions .changeset/witty-boxes-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"fuels-wallet": patch
---

- Re-enabled E2E contract tests
- Fixed biome trying to validate files generated by playwright test runs
- Fixed Playwright tests starting up before CRX files are available, now runs `build` beforehand.
- Fixed CRX dev server reloading during playwright tests, causing instabilities
- Fixed NODE_ENV being set to default (production) on local E2E tests, leading to the wrong version (i.e. production) being installed
- Fixed bug where only the first test file in a suite run would use the local CRX build, it'd then download and use a production build of the Wallet for the rest
116 changes: 58 additions & 58 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,64 +110,64 @@ jobs:
- name: Stop Test Node
run: pnpm node:clean

# tests-e2e-contracts:
# name: E2E Contract Tests
# runs-on: buildjet-4vcpu-ubuntu-2204
# steps:
# - uses: actions/checkout@v3
# - uses: FuelLabs/github-actions/setups/node@master
# with:
# node-version: 18.14.1
# pnpm-version: 8.15.7
# - uses: FuelLabs/github-actions/setups/docker@master
# with:
# username: ${{ github.repository_owner }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - name: Run PNPM install
# id: pnpm-cache
# run:
# pnpm recursive install --frozen-lockfile

# - name: Start Test Node
# run: pnpm node:up
tests-e2e-contracts:
name: E2E Contract Tests
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v3
- uses: FuelLabs/github-actions/setups/node@master
with:
node-version: 18.14.1
pnpm-version: 8.15.7
- uses: FuelLabs/github-actions/setups/docker@master
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run PNPM install
id: pnpm-cache
run:
pnpm recursive install --frozen-lockfile

- name: Start Test Node
run: pnpm node:up

# - name: Generate .env app
# run: cp packages/app/.env.example packages/app/.env
- name: Generate .env app
run: cp packages/app/.env.example packages/app/.env

# - name: Generate .env e2e-contracts
# run: cp packages/e2e-contract-tests/.env.example packages/e2e-contract-tests/.env

# - name: Build Application
# run: pnpm build:all
# env:
# ## increase node.js m memory limit for building
# ## with sourcemaps
# NODE_OPTIONS: "--max-old-space-size=4096"
# NODE_ENV: test

# - name: Build & Deploy Contracts
# run: pnpm deploy:contracts
# working-directory: ./packages/e2e-contract-tests

# # E2E tests running with Playwright
# - name: Install Playwright Browsers
# run: npx playwright install --with-deps chromium

# - name: Run E2E Contract Tests
# run: xvfb-run --auto-servernum -- pnpm test:e2e:contracts
# env:
# NODE_ENV: test

# - uses: actions/upload-artifact@v4
# if: always()
# with:
# name: playwright-report
# path: |
# packages/app/playwright-report/
# packages/app/playwright-html/
# retention-days: 30

# - name: Stop Test Node
# run: pnpm node:clean
- name: Generate .env e2e-contracts
run: cp packages/e2e-contract-tests/.env.example packages/e2e-contract-tests/.env

- name: Build Application
run: pnpm build:all
env:
## increase node.js m memory limit for building
## with sourcemaps
NODE_OPTIONS: "--max-old-space-size=4096"
NODE_ENV: test

- name: Build & Deploy Contracts
run: pnpm deploy:contracts
working-directory: ./packages/e2e-contract-tests

# E2E tests running with Playwright
- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium

- name: Run E2E Contract Tests
run: xvfb-run --auto-servernum -- pnpm test:e2e:contracts
env:
NODE_ENV: test

- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: |
packages/app/playwright-report/
packages/app/playwright-html/
retention-days: 30

- name: Stop Test Node
run: pnpm node:clean

1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"**/dist",
"**/dist-crx",
"**/contracts/**",
"**/playwright-report",
"pnpm-lock.yaml"
]
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"test:ci": "turbo run test --parallel -- --ci --testLocationInResults --json --coverage",
"test:clear": "pnpm -r exec jest --clearCache",
"test:coverage": "turbo run test --parallel -- --coverage",
"test:e2e": "playwright test --config=packages/app/playwright.config.ts",
"test:e2e:contracts": "playwright test --config=packages/e2e-contract-tests/playwright.config.ts",
"test:e2e": "NODE_ENV=test run-s build:crx && playwright test --config=packages/app/playwright.config.ts",
"test:e2e:contracts": "NODE_ENV=test run-s build:crx && playwright test --config=packages/e2e-contract-tests/playwright.config.ts",
"test:appfile": "pnpm --filter=fuels-wallet test --",
"ts:check": "turbo run ts:check",
"prepare": "husky install",
Expand Down
1 change: 1 addition & 0 deletions packages/app/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineConfig({
command: 'pnpm dev:crx',
port: Number(PORT),
reuseExistingServer: true,
timeout: 20000,
},
use: {
baseURL: `http://localhost:${PORT}/`,
Expand Down
3 changes: 3 additions & 0 deletions packages/app/vite-utils/vite.base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const baseConfig: UserConfig = {
server: {
port: Number(process.env.PORT),
strictPort: true,
watch: {
ignored: ['**/playwright-html/**'], // Ignore changes in any 'playwright' folder
},
},
optimizeDeps: {
esbuildOptions: {
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-contract-tests/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const config: PlaywrightTestConfig = defineConfig({
command: `pnpm dev:e2e-contracts --port ${process.env.PORT}`,
port: Number(process.env.PORT),
reuseExistingServer: true,
timeout: 20000,
},
use: {
baseURL: `http://localhost:${process.env.PORT}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import { getBaseAssetId, shortAddress } from '../../src/utils';
import { testSetup } from '../utils';

import { MAIN_CONTRACT_ID } from './config';
import { test } from './test';
import { test, useLocalCRX } from './test';
import { checkAddresses, checkFee, connect } from './utils';

useLocalCRX();

test.describe('Deposit Half ETH', () => {
let fuelWalletTestHelper: FuelWalletTestHelper;
let fuelWallet: WalletUnlocked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
import { testSetup } from '../utils';

import { MAIN_CONTRACT_ID } from './config';
import { test } from './test';
import { test, useLocalCRX } from './test';
import { checkAddresses, checkFee, connect } from './utils';

useLocalCRX();

test.describe('Forward and Mint Multicall', () => {
let fuelWalletTestHelper: FuelWalletTestHelper;
let fuelWallet: WalletUnlocked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import {
import { testSetup } from '../utils';

import { MAIN_CONTRACT_ID } from './config';
import { test } from './test';
import { test, useLocalCRX } from './test';
import { checkAddresses, checkFee, connect } from './utils';

useLocalCRX();

test.describe('Forward Custom Asset', () => {
let fuelWallet: WalletUnlocked;
let fuelWalletTestHelper: FuelWalletTestHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import { getBaseAssetId, shortAddress } from '../../src/utils';
import { testSetup } from '../utils';

import { MAIN_CONTRACT_ID } from './config';
import { test } from './test';
import { test, useLocalCRX } from './test';
import { checkAddresses, checkFee, connect } from './utils';

useLocalCRX();

test.describe('Forward Eth', () => {
let fuelWalletTestHelper: FuelWalletTestHelper;
let fuelWallet: WalletUnlocked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
import { testSetup } from '../utils';

import { EXTERNAL_CONTRACT_ID, MAIN_CONTRACT_ID } from './config';
import { test } from './test';
import { test, useLocalCRX } from './test';
import { checkAddresses, checkFee, connect } from './utils';

useLocalCRX();

test.describe('Forward Half ETH and Mint External Custom Asset', () => {
let fuelWalletTestHelper: FuelWalletTestHelper;
let fuelWallet: WalletUnlocked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
import { testSetup } from '../utils';

import { MAIN_CONTRACT_ID } from './config';
import { test } from './test';
import { test, useLocalCRX } from './test';
import { checkAddresses, checkFee, connect } from './utils';

useLocalCRX();

test.describe('Forward Half ETH and Mint Custom Asset', () => {
let fuelWalletTestHelper: FuelWalletTestHelper;
let fuelWallet: WalletUnlocked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import {
import { testSetup } from '../utils';

import { MAIN_CONTRACT_ID } from './config';
import { test } from './test';
import { checkAddresses, checkFee, connect } from './utils';
import { test, useLocalCRX } from './test';
import { checkAddresses, connect } from './utils';

useLocalCRX();
test.describe('Forward Half Custom Asset', () => {
let fuelWallet: WalletUnlocked;
let fuelWalletTestHelper: FuelWalletTestHelper;
Expand Down
4 changes: 3 additions & 1 deletion packages/e2e-contract-tests/playwright/e2e/MintAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
import { testSetup } from '../utils';

import { MAIN_CONTRACT_ID } from './config';
import { test } from './test';
import { test, useLocalCRX } from './test';
import { checkAddresses, checkFee, connect } from './utils';

useLocalCRX();

test.describe('Mint Assets', () => {
let fuelWalletTestHelper: FuelWalletTestHelper;
let fuelWallet: WalletUnlocked;
Expand Down
10 changes: 7 additions & 3 deletions packages/e2e-contract-tests/playwright/e2e/test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { join } from 'node:path';
import { test as testConfig } from '@fuels/playwright-utils';

testConfig.use({
pathToExtension: join(__dirname, '../../../app/dist-crx'),
});
// This must be called so that the local crx is used, otherwise a production build will be downloaded and used
// This must be called once for each test file
export function useLocalCRX() {
testConfig.use({
pathToExtension: join(__dirname, '../../../app/dist-crx'),
});
}

export const test = testConfig;

0 comments on commit 57f87f8

Please sign in to comment.