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

🪚 OmniGraph™ Use jest in utils-evm-test #80

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
"browser": true,
"commonjs": true,
"es6": true,
"mocha": true,
"node": true,
"jest": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "mocha", "prettier"],
"plugins": ["@typescript-eslint", "prettier"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
Expand All @@ -20,8 +19,6 @@
},
"ignorePatterns": ["node_modules/", "dist/", ".turbo/"],
"rules": {
"mocha/no-skipped-tests": "error",
"mocha/no-exclusive-tests": "error",
"prettier/prettier": "error",

// Intermediate deescalation to warnings
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-mocha": "10.2.0",
"eslint-plugin-n": "^16.3.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.0.1",
Expand Down
5 changes: 0 additions & 5 deletions packages/create-lz-oapp/.mocharc.json

This file was deleted.

17 changes: 17 additions & 0 deletions packages/create-lz-oapp/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testTimeout: 15000,
moduleNameMapper: {
"^@/(.*)\\.js$": "<rootDir>/src/$1",
},
transform: {
// ts-jest does not yet work great with node16 module resolution
// so we need to help it a little
//
// See https://github.com/kulshekhar/ts-jest/issues/4207 for the issue
// And https://github.com/kulshekhar/ts-jest/issues/4198 for another one
"^.+\\.tsx?$": ["ts-jest", { tsconfig: "tsconfig.test.json" }],
},
};
8 changes: 4 additions & 4 deletions packages/create-lz-oapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@
"dev": "npx tsup --watch",
"lint": "npx eslint '**/*.{js,ts,json}'",
"start": "./cli.cjs",
"test": "mocha --parallel"
"test": "jest --config jest.config.cjs"
},
"dependencies": {
"yoga-wasm-web": "~0.3.3"
},
"devDependencies": {
"@layerzerolabs/io-utils": "~0.0.1",
"@tanstack/react-query": "^5.8.4",
"@types/mocha": "^10.0.6",
"@types/jest": "^29.5.10",
"@types/prompts": "^2.4.9",
"@types/react": "^18.2.38",
"@types/which": "~3.0.3",
"chai": "^4.3.10",
"commander": "^11.1.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
Expand All @@ -48,11 +47,12 @@
"ink-select-input": "^5.0.0",
"ink-spinner": "^5.0.0",
"ink-text-input": "^5.0.1",
"mocha": "^10.0.0",
"jest": "^29.7.0",
"prompts": "^2.4.2",
"react": "^18.2.0",
"react-devtools-core": "^4.28.5",
"tiged": "^2.12.5",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"which": "~4.0.0"
Expand Down
24 changes: 11 additions & 13 deletions packages/create-lz-oapp/test/utilities/cloning.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import { expect } from 'chai'
import { describe, it } from 'mocha'
import { createExampleGitURL } from '../../src/utilities/cloning.js'
import { createExampleGitURL } from '@/utilities/cloning.js'

describe('utilities/cloning', () => {
describe('createExampleGitURL', () => {
const REPO_URL = '[email protected]:LayerZero-Labs/lz-utils'

it('should return the repository field if directory and ref are not specified', () => {
expect(createExampleGitURL({ repository: REPO_URL, id: 'dummy', label: 'Dummy' })).to.eql(REPO_URL)
expect(createExampleGitURL({ repository: REPO_URL, id: 'dummy', label: 'Dummy' })).toEqual(REPO_URL)
})

it('should return the repository field with directory if directory is specified', () => {
expect(createExampleGitURL({ repository: REPO_URL, directory: 'dir', id: 'dummy', label: 'Dummy' })).to.eql(
`${REPO_URL}/dir`
)
expect(
createExampleGitURL({ repository: REPO_URL, directory: 'dir', id: 'dummy', label: 'Dummy' })
).toEqual(`${REPO_URL}/dir`)
expect(
createExampleGitURL({ repository: REPO_URL, directory: '/dir', id: 'dummy', label: 'Dummy' })
).to.eql(`${REPO_URL}/dir`)
).toEqual(`${REPO_URL}/dir`)
expect(
createExampleGitURL({ repository: REPO_URL, directory: 'dir', ref: '', id: 'dummy', label: 'Dummy' })
).to.eql(`${REPO_URL}/dir`)
).toEqual(`${REPO_URL}/dir`)
})

it('should return the repository field with directory and ref if directory and ref are specified', () => {
expect(
createExampleGitURL({ repository: REPO_URL, directory: 'dir', ref: 'ref', id: 'dummy', label: 'Dummy' })
).to.eql(`${REPO_URL}/dir#ref`)
).toEqual(`${REPO_URL}/dir#ref`)
expect(
createExampleGitURL({
repository: REPO_URL,
Expand All @@ -34,14 +32,14 @@ describe('utilities/cloning', () => {
id: 'dummy',
label: 'Dummy',
})
).to.eql(`${REPO_URL}/dir#ref`)
).toEqual(`${REPO_URL}/dir#ref`)
})

it('should return the repository field with ref if only ref specified', () => {
expect(createExampleGitURL({ repository: REPO_URL, ref: 'ref', id: 'dummy', label: 'Dummy' })).to.eql(
expect(createExampleGitURL({ repository: REPO_URL, ref: 'ref', id: 'dummy', label: 'Dummy' })).toEqual(
`${REPO_URL}#ref`
)
expect(createExampleGitURL({ repository: REPO_URL, ref: '#ref', id: 'dummy', label: 'Dummy' })).to.eql(
expect(createExampleGitURL({ repository: REPO_URL, ref: '#ref', id: 'dummy', label: 'Dummy' })).toEqual(
`${REPO_URL}#ref`
)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/create-lz-oapp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lib": ["dom", "dom.Iterable", "es2022"],
"resolveJsonModule": false,
"target": "esnext",
"types": ["mocha", "node"],
"types": ["jest", "node"],
"paths": {
"@/*": ["./src/*"]
}
Expand Down
7 changes: 7 additions & 0 deletions packages/create-lz-oapp/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node10"
}
}
9 changes: 9 additions & 0 deletions packages/utils-evm-test/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 15000,
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
};
8 changes: 5 additions & 3 deletions packages/utils-evm-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"license": "MIT",
"scripts": {
"lint": "npx eslint '**/*.{js,ts,json}'",
"test": "npx hardhat test"
"pretest": "npx hardhat compile",
"test": "jest --passWithNoTests"
},
"devDependencies": {
"@ethersproject/abi": "^5.7.0",
Expand All @@ -25,11 +26,12 @@
"@layerzerolabs/utils-evm": "~0.0.1",
"@nomicfoundation/hardhat-ethers": "^3.0.2",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@types/mocha": "^10.0.6",
"chai": "^4.3.10",
"@types/jest": "^29.5.10",
"ethers": "^5.7.0",
"fast-check": "^3.14.0",
"hardhat": "^2.19.2",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
}
Expand Down
69 changes: 34 additions & 35 deletions packages/utils-evm-test/test/errors/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fc from 'fast-check'
import hre from 'hardhat'
import { expect } from 'chai'
import { Contract } from '@ethersproject/contracts'
import {
createErrorParser,
Expand Down Expand Up @@ -33,12 +32,12 @@ describe('errors/parser', () => {
const assertFailed = async (promise: Promise<unknown>): Promise<unknown> =>
promise.then(
(result) => {
expect.fail(`Expected a promise to always reject but it resolved with ${JSON.stringify(result)}`)
fail(`Expected a promise to always reject but it resolved with ${JSON.stringify(result)}`)
},
(error) => error
)

before(async () => {
beforeAll(async () => {
const contractFactory = await hre.ethers.getContractFactory(CONTRACT_NAME)

contract = await contractFactory.deploy()
Expand All @@ -53,9 +52,9 @@ describe('errors/parser', () => {
const omniError: OmniError = { error: new RevertError('A reason is worth a million bytes'), point }
const parsedError = await errorParser(omniError)

expect(parsedError.point).to.eql(point)
expect(parsedError.error).to.be.instanceOf(RevertError)
expect(parsedError.error.reason).to.equal('A reason is worth a million bytes')
expect(parsedError.point).toEqual(point)
expect(parsedError.error).toBeInstanceOf(RevertError)
expect(parsedError.error.reason).toBe('A reason is worth a million bytes')
})
)
})
Expand All @@ -69,9 +68,9 @@ describe('errors/parser', () => {
const omniError: OmniError = { error, point }
const parsedError = await errorParser(omniError)

expect(parsedError.point).to.eql(point)
expect(parsedError.error).to.be.instanceOf(PanicError)
expect(parsedError.error.reason).to.eql(BigInt(1))
expect(parsedError.point).toEqual(point)
expect(parsedError.error).toBeInstanceOf(PanicError)
expect(parsedError.error.reason).toEqual(BigInt(1))
})
)
})
Expand All @@ -85,9 +84,9 @@ describe('errors/parser', () => {
const omniError: OmniError = { error, point }
const parsedError = await errorParser(omniError)

expect(parsedError.point).to.eql(point)
expect(parsedError.error).to.be.instanceOf(RevertError)
expect(parsedError.error.reason).to.eql('my bad')
expect(parsedError.point).toEqual(point)
expect(parsedError.error).toBeInstanceOf(RevertError)
expect(parsedError.error.reason).toEqual('my bad')
})
)
})
Expand All @@ -101,9 +100,9 @@ describe('errors/parser', () => {
const omniError: OmniError = { error, point }
const parsedError = await errorParser(omniError)

expect(parsedError.point).to.eql(point)
expect(parsedError.error).to.be.instanceOf(RevertError)
expect(parsedError.error.reason).to.eql('my bad')
expect(parsedError.point).toEqual(point)
expect(parsedError.error).toBeInstanceOf(RevertError)
expect(parsedError.error.reason).toEqual('my bad')
})
)
})
Expand All @@ -117,10 +116,10 @@ describe('errors/parser', () => {
const omniError: OmniError = { error, point }
const parsedError = await errorParser(omniError)

expect(parsedError.point).to.eql(point)
expect(parsedError.error).to.be.instanceOf(CustomError)
expect(parsedError.error.reason).to.eql('CustomErrorWithNoArguments')
expect((parsedError.error as CustomError).args).to.eql([])
expect(parsedError.point).toEqual(point)
expect(parsedError.error).toBeInstanceOf(CustomError)
expect(parsedError.error.reason).toEqual('CustomErrorWithNoArguments')
expect((parsedError.error as CustomError).args).toEqual([])
})
)
})
Expand All @@ -134,10 +133,10 @@ describe('errors/parser', () => {
const omniError: OmniError = { error, point }
const parsedError = await errorParser(omniError)

expect(parsedError.point).to.eql(point)
expect(parsedError.error).to.be.instanceOf(CustomError)
expect(parsedError.error.reason).to.eql('CustomErrorWithAnArgument')
expect((parsedError.error as CustomError).args).to.eql(['my bad'])
expect(parsedError.point).toEqual(point)
expect(parsedError.error).toBeInstanceOf(CustomError)
expect(parsedError.error.reason).toEqual('CustomErrorWithAnArgument')
expect((parsedError.error as CustomError).args).toEqual(['my bad'])
})
)
})
Expand All @@ -150,10 +149,10 @@ describe('errors/parser', () => {
const omniError: OmniError = { error: 'some weird error', point }
const parsedError = await errorParser(omniError)

expect(parsedError.point).to.eql(point)
expect(parsedError.error).to.be.instanceOf(UnknownError)
expect(parsedError.error.reason).to.be.undefined
expect(parsedError.error.message).to.eql('Unknown error: some weird error')
expect(parsedError.point).toEqual(point)
expect(parsedError.error).toBeInstanceOf(UnknownError)
expect(parsedError.error.reason).toBeUndefined()
expect(parsedError.error.message).toEqual('Unknown error: some weird error')
})
)
})
Expand All @@ -166,10 +165,10 @@ describe('errors/parser', () => {
const omniError: OmniError = { error: new Error('some weird error'), point }
const parsedError = await errorParser(omniError)

expect(parsedError.point).to.eql(point)
expect(parsedError.error).to.be.instanceOf(UnknownError)
expect(parsedError.error.reason).to.be.undefined
expect(parsedError.error.message).to.eql('Unknown error: Error: some weird error')
expect(parsedError.point).toEqual(point)
expect(parsedError.error).toBeInstanceOf(UnknownError)
expect(parsedError.error.reason).toBeUndefined()
expect(parsedError.error.message).toEqual('Unknown error: Error: some weird error')
})
)
})
Expand All @@ -182,10 +181,10 @@ describe('errors/parser', () => {
const omniError: OmniError = { error, point }
const parsedError = await errorParser(omniError)

expect(parsedError.point).to.eql(point)
expect(parsedError.error).to.be.instanceOf(UnknownError)
expect(parsedError.error.reason).to.be.undefined
expect(parsedError.error.message).to.match(/Unknown error: /)
expect(parsedError.point).toEqual(point)
expect(parsedError.error).toBeInstanceOf(UnknownError)
expect(parsedError.error.reason).toBeUndefined()
expect(parsedError.error.message).toMatch(/Unknown error: /)
}),
// Test case for when toString method of the error is not defined
{
Expand Down
2 changes: 1 addition & 1 deletion packages/utils-evm-test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"include": ["src", "test", "*.config.ts"],
"compilerOptions": {
"module": "commonjs",
"types": ["node", "mocha"]
"types": ["node", "jest"]
}
}
Loading