Skip to content

Commit

Permalink
Merge branch 'master' into ag/fe/feat-1205
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurgeron authored Feb 5, 2025
2 parents 850d0ad + f653d59 commit 189957a
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 165 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-vans-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": patch
---

fix: jest unit tests
26 changes: 7 additions & 19 deletions .github/workflows/pr-tests-jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ concurrency:

jobs:
tests-jest:
name: Test
runs-on: buildjet-8vcpu-ubuntu-2204
name: Jest Tests [Shard ${{ matrix.shard }}]
runs-on: buildjet-8vcpu-ubuntu-2204-arm
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v4
- uses: FuelLabs/github-actions/setups/node@master
Expand All @@ -24,27 +28,11 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

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

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

# Unit tests running with JEST
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr

- name: Build libs
run: |
pnpm build:libs

- name: Run Jest Tests
run: |
pnpm test:ci
run: pnpm test:ci --shard ${{ matrix.shard }}/4
timeout-minutes: 10
env:
NODE_OPTIONS: "--max-old-space-size=4096"

- name: Stop Test Node
run: pnpm node:clean
2 changes: 1 addition & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
up:
docker compose -p dev --env-file .env up -d --build
DOCKER_BUILDKIT=1 docker compose -p dev --env-file .env up -d --build

down:
docker compose -p dev stop
Expand Down
1 change: 0 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ version: '3'

services:
fuel-core:
platform: linux/amd64
container_name: '${PROJECT:-fuel-node}_fuel-core'
environment:
FUEL_IP: ${FUEL_IP}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"packages:version": "node ./scripts/version.js",
"storybook": "pnpm -r --filter=fuels-wallet storybook",
"test": "turbo run test --parallel",
"test:ci": "turbo run test --parallel -- --ci --testLocationInResults --json --coverage",
"test:ci": "turbo run test --parallel --concurrency=100% -- --ci --testLocationInResults --json",
"test:clear": "pnpm -r exec jest --clearCache",
"test:coverage": "turbo run test --parallel -- --coverage",
"test:e2e": "NODE_ENV=test pnpm build:crx && playwright test --config=packages/app/playwright.config.ts --project=chromium",
Expand Down
7 changes: 5 additions & 2 deletions packages/app/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const config: JestConfigWithTsJest = {
{
...tsjPreset[1],
useESM: true,
isolatedModules: true,
diagnostics: {
ignoreCodes: [1343],
warnOnly: true,
Expand All @@ -44,9 +45,8 @@ const config: JestConfigWithTsJest = {
transformIgnorePatterns: [`/node_modules/(?!${esModules})`],
testTimeout: 10000,
forceExit: false,
detectOpenHandles: true,
detectOpenHandles: !process.env.CI,
modulePathIgnorePatterns: ['/dist/', 'playwright', 'uuid/dist/esm-browser'],
maxWorkers: 1,
rootDir: __dirname,
displayName: pkg.name,
setupFilesAfterEnv: [
Expand All @@ -68,6 +68,9 @@ const config: JestConfigWithTsJest = {
'^uuid$': require.resolve('uuid'),
'^@web3modal/core$': require.resolve('@web3modal/core'),
},
collectCoverageFrom: [],

cache: true,
};

export default config;
117 changes: 1 addition & 116 deletions packages/app/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { webcrypto } from 'crypto';
// biome-ignore lint/style/useNodejsImportProtocol: <explanation>
import { TextDecoder, TextEncoder } from 'util';
import { rest } from 'msw';
import { setupServer } from 'msw/node';

import { localStorageMock } from './src/mocks/localStorage';

// biome-ignore lint/suspicious/noExplicitAny: <explanation>
Expand All @@ -22,120 +21,6 @@ import 'whatwg-fetch';

import { act } from 'react';

// Initialize the MSW server with the necessary request handlers
const server = setupServer(
rest.get('/assets.json', (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.json([
{
name: 'Ethereum',
symbol: 'ETH',
icon: 'https://verified-assets.fuel.network/images/eth.svg',
networks: [
{
type: 'ethereum',
chain: 'sepolia',
decimals: 18,
chainId: 11155111,
},
{
type: 'ethereum',
chain: 'foundry',
decimals: 18,
chainId: 31337,
},
{
type: 'ethereum',
chain: 'mainnet',
decimals: 18,
chainId: 1,
},
{
type: 'fuel',
chain: 'devnet',
decimals: 9,
assetId:
'0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07',
chainId: 0,
},
{
type: 'fuel',
chain: 'testnet',
decimals: 9,
assetId:
'0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07',
chainId: 0,
},
{
type: 'fuel',
chain: 'mainnet',
decimals: 9,
assetId:
'0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07',
chainId: 9889,
},
],
},
{
name: 'Fuel',
symbol: 'FUEL',
icon: 'https://verified-assets.fuel.network/images/fuel.svg',
networks: [
{
type: 'ethereum',
chain: 'sepolia',
address: '0xd7fc4e8fb2c05567c313f4c9b9e07641a361a550',
decimals: 9,
chainId: 11155111,
},
{
type: 'ethereum',
chain: 'mainnet',
address: '0x675b68aa4d9c2d3bb3f0397048e62e6b7192079c',
decimals: 9,
chainId: 1,
},
{
type: 'fuel',
chain: 'testnet',
decimals: 9,
chainId: 0,
contractId:
'0xd02112ef9c39f1cea7c8527c26242ca1f5d26bcfe8d1564bee054d3b04175471',
subId:
'0xede43647e2aad1c0f1696201d6ba913aa67c917c3ac9a4a7d95662962ab25c5b',
assetId:
'0x324d0c35a4299ef88138a656d5272c5a3a9ccde2630ae055dacaf9d13443d53b',
},
{
type: 'fuel',
chain: 'mainnet',
decimals: 9,
chainId: 9889,
contractId:
'0x4ea6ccef1215d9479f1024dff70fc055ca538215d2c8c348beddffd54583d0e8',
subId:
'0xe81c89b8cf795c7c25e79f6c4f2f1cd233290b58e217ed4e9b6b18538badddaf',
assetId:
'0x1d5d97005e41cae2187a895fd8eab0506111e0e2f3331cd3912c15c24e3c1d82',
},
],
},
])
);
})
);

// Establish API mocking before all tests
beforeAll(() => server.listen());

// Reset any request handlers that are declared as a part of our tests (i.e., for testing one-time error scenarios)
afterEach(() => server.resetHandlers());

// Clean up after the tests are finished
afterAll(() => server.close());

// Replace ReactDOMTestUtils.act with React.act
jest.mock('react-dom/test-utils', () => {
const originalModule = jest.requireActual('react-dom/test-utils');
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dev:storybook": "storybook dev -p 6006",
"preview": "vite preview",
"test": "jest --verbose",
"test:ci": "pnpm ts:check && pnpm test",
"test:ci": "pnpm ts:check && jest --verbose",
"test:watch": "jest --watch",
"ts:check": "pnpm xstate:typegen && tsc --noEmit",
"xstate:typegen": "xstate typegen 'src/**/*.ts?(x)'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MOCK_ACCOUNTS } from '../../__mocks__';
import type { AccountWithBalance } from '@fuel-wallet/types';
import { Address, bn } from 'fuels';
import { act } from 'react';
import { mockServer } from '~/systems/Core/__tests__/utils/msw';
import { BalanceWidget } from './BalanceWidget';

const ACCOUNT: AccountWithBalance = {
Expand All @@ -21,6 +22,11 @@ const ACCOUNT: AccountWithBalance = {
};

describe('BalanceWidget', () => {
const server = mockServer();
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

it('a11y', async () => {
await testA11y(<BalanceWidget account={ACCOUNT} />, {
wrapper: TestWrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expectStateMatch, mockVault } from '~/systems/Core/__tests__/utils';

import { AccountService } from '../services';

import { mockServer } from '~/systems/Core/__tests__/utils/msw';
import type { AddAccountMachineService } from './addAccountMachine';
import { addAccountMachine } from './addAccountMachine';

Expand All @@ -14,16 +15,19 @@ const machine = addAccountMachine.withContext({}).withConfig({

describe('addAccountMachine', () => {
let service: AddAccountMachineService;
const server = mockServer();
beforeAll(() => server.listen());
afterEach(() => {
server.resetHandlers();
service?.stop();
});
afterAll(() => server.close());

beforeEach(async () => {
await mockVault();
service = interpret(machine).start();
});

afterEach(() => {
service.stop();
});

describe('add', () => {
it('should be able to add an account', async () => {
await expectStateMatch(service, 'idle');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expectStateMatch, mockVault } from '~/systems/Core/__tests__/utils';

import { AccountService } from '../services';

import { mockServer } from '~/systems/Core/__tests__/utils/msw';
import type { ImportAccountMachineService } from './importAccountMachine';
import { importAccountMachine } from './importAccountMachine';

Expand All @@ -15,16 +16,19 @@ const machine = importAccountMachine.withContext({}).withConfig({

describe('importAccountMachine', () => {
let service: ImportAccountMachineService;
const server = mockServer();
beforeAll(() => server.listen());
afterEach(() => {
server.resetHandlers();
service?.stop();
});
afterAll(() => server.close());

beforeEach(async () => {
await mockVault();
service = interpret(machine).start();
});

afterEach(() => {
service.stop();
});

describe('import', () => {
async function importAccount(name: string) {
await expectStateMatch(service, 'idle');
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/systems/Account/services/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AccountService } from './account';
const _providerUrl = import.meta.env.VITE_FUEL_PROVIDER_URL;
const MOCK_ACCOUNT = MOCK_ACCOUNTS[0];

const MOCK_BALANCES = [
const _MOCK_BALANCES = [
{
node: {
assetId: MOCK_BASE_ASSET_ID,
Expand All @@ -22,7 +22,7 @@ const MOCK_BALANCES = [
},
];

mockServer([mockBalancesOnGraphQL(MOCK_BALANCES)]);
// mockServer([mockBalancesOnGraphQL(MOCK_BALANCES)]);

describe('AccountService', () => {
beforeEach(async () => {
Expand Down
Loading

0 comments on commit 189957a

Please sign in to comment.