Skip to content

Commit 2b52598

Browse files
authored
Merge pull request #43 from smartcontractkit/chore/separate-tests
Separate tests, fix linting, and utilize CI
2 parents 3d41d89 + 9c691e4 commit 2b52598

File tree

17 files changed

+289
-54
lines changed

17 files changed

+289
-54
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ jobs:
3535
run: pnpm run build
3636
shell: bash
3737

38+
- name: Lint
39+
run: pnpm run lint
40+
shell: bash
41+
42+
- name: Run unit tests
43+
run: pnpm run test:unit
44+
shell: bash

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
"build-components": "pnpm --filter ccip-react-components run build",
77
"dev-example": "pnpm --filter example-nextjs run dev",
88
"clean": "rm -rf node_modules packages/*/node_modules packages/*/dist examples/nextjs/node_modules examples/nextjs/.next",
9+
"test:unit": "pnpm --filter ccip-js run t:unit",
10+
"test:int": "pnpm --filter ccip-js run t:int",
11+
"test:int:hedera": "pnpm --filter ccip-js run t:int:hedera",
912
"test-ccip-js": "pnpm --filter ccip-js run t:int",
13+
"lint": "pnpm --filter ccip-js run lint && pnpm --filter ccip-react-components run lint",
1014
"test-components": "pnpm --filter ccip-react-components run test"
1115
},
1216
"devDependencies": {

packages/ccip-js/.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/ccip-js/eslint.config.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Flat config for ESLint v9+
2+
import tseslint from '@typescript-eslint/eslint-plugin'
3+
import tsParser from '@typescript-eslint/parser'
4+
import prettier from 'eslint-plugin-prettier'
5+
6+
export default [
7+
{
8+
ignores: ['dist/**', 'node_modules/**', 'coverage/**', 'artifacts/**', 'artifacts-compile/**', 'cache/**'],
9+
},
10+
{
11+
files: ['src/**/*.{ts,js}', 'test/**/*.{ts,js}'],
12+
languageOptions: {
13+
parser: tsParser,
14+
ecmaVersion: 2022,
15+
sourceType: 'module',
16+
globals: {
17+
node: true,
18+
es2022: true,
19+
browser: true,
20+
},
21+
},
22+
plugins: {
23+
'@typescript-eslint': tseslint,
24+
prettier,
25+
},
26+
rules: {
27+
...tseslint.configs.recommended.rules,
28+
'prettier/prettier': 'error',
29+
'@typescript-eslint/no-explicit-any': 'off',
30+
'@typescript-eslint/ban-ts-comment': 'off',
31+
'@typescript-eslint/no-non-null-assertion': 'off',
32+
'@typescript-eslint/no-unused-vars': [
33+
'error',
34+
{
35+
argsIgnorePattern: '^_',
36+
varsIgnorePattern: '^_',
37+
ignoreRestSiblings: true,
38+
},
39+
],
40+
'@typescript-eslint/explicit-module-boundary-types': 'off',
41+
},
42+
},
43+
{
44+
files: ['test/**/*.{ts,js}'],
45+
rules: {
46+
'@typescript-eslint/no-unused-vars': 'off',
47+
},
48+
},
49+
]
50+
51+

packages/ccip-js/jest.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
export default {
33
testEnvironment: 'node',
44
transform: {
5-
'^.+.tsx?$': ['ts-jest', {}],
5+
'^.+\\.tsx?$': ['ts-jest', { useESM: true }],
66
},
7-
workerThreads: true,
7+
extensionsToTreatAsEsm: ['.ts'],
88
testTimeout: 180000,
9+
setupFilesAfterEnv: ['<rootDir>/test/jest.setup.ts'],
910
}

packages/ccip-js/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
"check": "tsc --noEmit",
1313
"build:watch": "tsc -w",
1414
"build": "tsc && hardhat compile",
15-
"lint": "eslint 'src/**/*.{ts,js}'",
15+
"lint": "eslint 'src/**/*.{ts,js}' 'test/**/*.{ts,js}'",
1616
"format": "prettier --write 'src/**/*.{ts,js,json,md}'",
17-
"t:int": "jest --coverage -u --testMatch=\"**/integration-testnet**.test.ts\" --detectOpenHandles",
18-
"t:int:viem": "jest --coverage -u --testMatch=\"**/integration-testnet.test.ts\" --detectOpenHandles",
19-
"t:int:ethers": "jest --coverage -u --testMatch=\"**/integration-testnet-ethers.test.ts\" --detectOpenHandles",
20-
"t:unit": "jest --coverage -u --testMatch=\"**/unit.test.ts\" ",
17+
"t:int": "jest --coverage -u --testMatch=\"**/integration-testnet**.test.ts\" --runInBand --detectOpenHandles --forceExit",
18+
"t:int:viem": "jest --coverage -u --testMatch=\"**/integration-testnet.test.ts\" --runInBand --detectOpenHandles --forceExit",
19+
"t:int:ethers": "jest --coverage -u --testMatch=\"**/integration-testnet-ethers.test.ts\" --runInBand --detectOpenHandles --forceExit",
20+
"t:int:hedera": "jest --coverage -u --testMatch=\"**/integration-hedera.test.ts\" --runInBand --detectOpenHandles --forceExit",
21+
"t:unit": "jest --coverage -u --testMatch=\"**/unit.test.ts\" --runInBand --detectOpenHandles --forceExit",
2122
"test:hh": "hardhat test"
2223
},
2324
"devDependencies": {

packages/ccip-js/src/ethers-adapters.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Provider, Signer, TypedDataField } from 'ethers'
2-
import type {Address, Hash, Transport, WalletClient, PublicClient } from 'viem'
2+
import type { Address, Hash, Transport, WalletClient, PublicClient } from 'viem'
33

44
import { custom, createPublicClient, createWalletClient } from 'viem'
55
import { toAccount } from 'viem/accounts'
@@ -46,7 +46,10 @@ export async function ethersSignerToAccount(signer: Signer) {
4646

4747
/** Create a viem PublicClient from an ethers provider. */
4848
export function ethersProviderToPublicClient(provider: Provider, chain: any): PublicClient {
49-
return createPublicClient({ chain: chain as any, transport: ethersProviderToTransport(provider) }) as unknown as PublicClient
49+
return createPublicClient({
50+
chain: chain as any,
51+
transport: ethersProviderToTransport(provider),
52+
}) as unknown as PublicClient
5053
}
5154

5255
/** Create a viem WalletClient from an ethers signer. */

packages/ccip-js/test/helpers/accounts.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export const getBalance = async ({ isFork }: BalanceOptions) => {
6262
return balance
6363
}
6464

65-
6665
// export const setAllowance = async ({ isFork, amount, contract }: AllowanceOptions) => {
6766
// const client = isFork ? forkClient : testClient
6867

packages/ccip-js/test/helpers/clients.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { account } from './constants'
22
import { createTestClient, http, publicActions, walletActions } from 'viem'
3-
import { sepolia, anvil } from 'viem/chains'
3+
import { sepolia, anvil } from 'viem/chains'
44

55
export const testClient = createTestClient({
66
chain: anvil,
7-
transport: http(),
7+
transport: http(undefined, { fetchOptions: { keepalive: false } }),
88
mode: 'anvil',
99
account,
1010
})
@@ -13,7 +13,7 @@ export const testClient = createTestClient({
1313

1414
export const forkClient = createTestClient({
1515
chain: sepolia,
16-
transport: http(),
16+
transport: http(undefined, { fetchOptions: { keepalive: false } }),
1717
mode: 'anvil',
1818
account,
1919
})

packages/ccip-js/test/helpers/constants.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ import feeQuoterJson from '../../artifacts-compile/FeeQuoter.json'
1212
// replace with your own private key (optional)
1313
dotenv.config()
1414

15-
if (process.env.PRIVATE_KEY?.slice(0, 2) !== '0x') {
15+
if (process.env.PRIVATE_KEY && !process.env.PRIVATE_KEY.startsWith('0x')) {
1616
process.env.PRIVATE_KEY = `0x${process.env.PRIVATE_KEY}`
1717
}
1818

19-
export const DEFAULT_ANVIL_PRIVATE_KEY =
20-
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' as Hex
19+
export const DEFAULT_ANVIL_PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' as Hex
2120
export const account = privateKeyToAccount(DEFAULT_ANVIL_PRIVATE_KEY)
2221

2322
// bridge token contract

0 commit comments

Comments
 (0)