Skip to content

Commit

Permalink
- Finished tests for /react and /core
Browse files Browse the repository at this point in the history
- Added mock variables
- Fixed nx testing issues with css and global variables
- Replaced redundant crypto library
- Started adding data-testid's to UI components
- Updated configs for tsc exclusion and presets
- Added codecov.yml file for coverage Github action
- Adjust babel to not build test files
  • Loading branch information
codebycarson committed Oct 11, 2023
1 parent c32ec9e commit 58f7334
Show file tree
Hide file tree
Showing 73 changed files with 2,013 additions and 1,134 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- run: yarn
- run: yarn lint:all
- run: yarn test:all
- run: yarn build:all
- run: yarn test:all
46 changes: 46 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Run & Upload Test Coverage

on:
push:
branches:
- main
pull_request:
branches:
- main
- feature/**

jobs:
run-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 18

- name: Install dependencies
run: yarn install

- name: Build packages
run: yarn build:all

- name: Run Jest tests
run: yarn test:coverage

- name: List coverage files
run: |
ls -al ./packages/core
ls -al ./packages/core/coverage
ls -al ./packages/react/coverage
ls -al ./packages/proto/coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: ./packages/core/coverage/coverage-final.json,./packages/react/coverage/coverage-final.json,./packages/proto/coverage/coverage-final.json
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js 16.x
- name: Setup Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18

- name: Install Dependencies
run: yarn
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# testing
packages/react/coverage

packages/testing/src/lib/selenium/instance-data
packages/proto/coverage
packages/core/coverage

# compiled output
dist
Expand Down
26 changes: 26 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
flags:
core:
paths:
- packages/core/**
react:
paths:
- packages/react/**
proto:
paths:
- packages/proto/**

coverage:
status:
project:
core:
target: 80%
flags:
- core
react:
target: 80%
flags:
- react
proto:
target: 80%
flags:
- proto
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint:since": "nx affected --target=lint",
"test:all": "nx run-many --target=test",
"test:since": "nx affected --target=test",
"test:coverage": "nx affected:test --all --coverage --no-cache",
"release": "yarn build:all && changeset publish",
"release:internal": "yarn build:all && yarn changeset && yarn changeset version --snapshot internal && yarn changeset publish --no-git-tag --snapshot --tag internal",
"postrelease": "git push --follow-tags"
Expand All @@ -21,7 +22,8 @@
"@nrwl/eslint-plugin-nx": "15.5.1",
"@nrwl/nx-cloud": "latest",
"@nrwl/workspace": "15.5.1",
"@types/jest": "^29.4.0",
"@types/jest": "^29.5.5",
"@types/node": "20.8.2",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"eslint": "^8.33.0",
Expand All @@ -31,12 +33,12 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "7.31.11",
"eslint-plugin-react-hooks": "4.6.0",
"jest": "28.1.1",
"jest": "29.7.0",
"jest-environment-jsdom": "28.1.1",
"nx": "15.5.1",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"ts-jest": "28.0.5",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"typescript": "~4.8.4"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/core/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = (api) => {

return {
presets: isESM ? esmPresets : commonjsPresets,
plugins: ['@babel/plugin-transform-runtime']
plugins: ['@babel/plugin-transform-runtime'],
ignore: ['**/*.spec.ts', '**/*.spec.tsx', '**/*.spec.js', '**/*.spec.jsx', '**/__tests__/**/*', '**/__mocks__/**/*']
};
};
6 changes: 3 additions & 3 deletions packages/core/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['node_modules', 'dist'],
preset: 'ts-jest',
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['node_modules', 'dist']
};
7 changes: 3 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"prebuild": "rimraf dist",
"build": "yarn build:types && yarn build:cjs && yarn build:esm && yarn build:prettier",
"build:types": "tsc --project tsconfig.declarations.json",
"build:cjs": "BABEL_ENV=cjs babel src --out-dir dist/cjs --extensions '.js,.jsx,.ts,.tsx' --source-maps --copy-files",
"build:esm": "BABEL_ENV=esm babel src --out-dir dist/esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --copy-files",
"build:cjs": "BABEL_ENV=cjs babel src --out-dir dist/cjs --extensions '.js,.jsx,.ts,.tsx' --source-maps --copy-files --no-copy-ignored",
"build:esm": "BABEL_ENV=esm babel src --out-dir dist/esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --copy-files --no-copy-ignored",
"build:prettier": "prettier --write 'dist/**/*.js'",
"test": "jest"
},
Expand Down Expand Up @@ -41,8 +41,8 @@
"@ethersproject/keccak256": "^5.7.0",
"@keplr-wallet/types": "^0.11.41",
"@sei-js/proto": "^3.1.0",
"bech32": "^2.0.0",
"buffer": "^6.0.3",
"crypto-js": "^4.1.1",
"elliptic": "^6.5.4",
"process": "^0.11.10",
"readonly-date": "^1.0.0",
Expand All @@ -54,7 +54,6 @@
"@babel/plugin-transform-runtime": "^7.22.15",
"@babel/preset-env": "^7.22.20",
"@babel/preset-typescript": "^7.22.15",
"@types/crypto-js": "^4.1.1",
"@types/elliptic": "^6.4.14",
"@types/sha.js": "^2.4.1"
},
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/lib/queryClient/__tests__/queryClient.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { seiprotocol } from '@sei-js/proto';
import { getQueryClient } from '../queryClient';

// Mock the createLCDClient method
jest.mock('@sei-js/proto', () => ({
seiprotocol: {
ClientFactory: {
createLCDClient: jest.fn()
}
}
}));

describe('getQueryClient', () => {
it('should call createLCDClient with the correct argument and return the result', async () => {
const restEndpoint = 'http://rest.atlantic-2.provider.com';

await getQueryClient(restEndpoint);

expect(seiprotocol.ClientFactory.createLCDClient).toHaveBeenCalledWith({ restEndpoint });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { CosmWasmClient, SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { OfflineSigner } from '@cosmjs/proto-signing';
import { getCosmWasmClient, getSigningCosmWasmClient } from '../cosmWasmClient';

jest.mock('@cosmjs/cosmwasm-stargate', () => ({
CosmWasmClient: {
connect: jest.fn()
},
SigningCosmWasmClient: {
connectWithSigner: jest.fn()
}
}));

describe('getCosmWasmClient', () => {
it('should call CosmWasmClient.connect with the correct rpcEndpoint', async () => {
const rpcEndpoint = 'http://localhost:26657';

await getCosmWasmClient(rpcEndpoint);

expect(CosmWasmClient.connect).toHaveBeenCalledWith(rpcEndpoint);
});
});

describe('getSigningCosmWasmClient', () => {
it('should call SigningCosmWasmClient.connectWithSigner with the correct parameters', async () => {
const rpcEndpoint = 'http://localhost:26657';
const signer = {} as OfflineSigner;
const options = {};

await getSigningCosmWasmClient(rpcEndpoint, signer, options);

expect(SigningCosmWasmClient.connectWithSigner).toHaveBeenCalledWith(
rpcEndpoint,
signer,
expect.objectContaining({
registry: expect.anything(),
aminoTypes: expect.anything()
})
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { StargateClient, SigningStargateClient, AminoTypes } from '@cosmjs/stargate';
import { OfflineSigner, Registry } from '@cosmjs/proto-signing';
import { createSeiAminoTypes, createSeiRegistry, getSigningClient, getStargateClient } from '../stargateClient';

jest.mock('@cosmjs/stargate', () => {
const originalModule = jest.requireActual('@cosmjs/stargate');

return {
...originalModule,
StargateClient: {
...originalModule.StargateClient,
connect: jest.fn()
},
SigningStargateClient: {
...originalModule.SigningStargateClient,
connectWithSigner: jest.fn()
}
};
});

describe('stargateClient', () => {
afterEach(() => {
jest.restoreAllMocks();
jest.clearAllMocks();
});

describe('createSeiRegistry', () => {
it('should return a Registry instance', () => {
const registry = createSeiRegistry();
expect(registry).toBeInstanceOf(Registry);
});
});

describe('createSeiAminoTypes', () => {
it('should return an AminoTypes instance', () => {
const aminoTypes = createSeiAminoTypes();
expect(aminoTypes).toBeInstanceOf(AminoTypes);
});
});

describe('getStargateClient', () => {
it('should call StargateClient.connect with the correct rpcEndpoint', async () => {
const rpcEndpoint = 'http://localhost:26657';

await getStargateClient(rpcEndpoint);

expect(StargateClient.connect).toHaveBeenCalledWith(rpcEndpoint, {});
});
});

describe('getSigningClient', () => {
it('should call SigningStargateClient.connectWithSigner with the correct parameters', async () => {
const rpcEndpoint = 'http://localhost:26657';
const signer = {} as OfflineSigner;
const options = {};

await getSigningClient(rpcEndpoint, signer, options);

expect(SigningStargateClient.connectWithSigner).toHaveBeenCalledWith(
rpcEndpoint,
signer,
expect.objectContaining({
registry: createSeiRegistry(),
aminoTypes: createSeiAminoTypes()
})
);
});
});
});
Loading

0 comments on commit 58f7334

Please sign in to comment.