rryter / hardhat-jest-plugin Goto Github PK
View Code? Open in Web Editor NEWA Jest plugin for Hardhat.
Home Page: https://hardhat.org/
License: MIT License
A Jest plugin for Hardhat.
Home Page: https://hardhat.org/
License: MIT License
I'm trying to use jest on all my packages in my monorepo. Thank you for creating this plugin!
Using this plugin I was able to make the tests work with hardhat. The issue I found is that when using the hardhat-gas-reporter plugin, the tests succeed but the plugin output, which should appear at the end, doesn't.
The plugin uses an environment variable to turn on. Using mocha, I have "gas-report": "env REPORT_GAS=true yarn run hardhat test"
on my packages.json
. What should I use for jest?
I'm using yarn 2 (berry).
hardhat test:jest --watch
should start Jest in "watch mode". It should also start a watcher for changes on the contract files, and recompile as soon as there are any changes. Since Jest is in "watch mode", it will automatically rerun the tests.
hardhat-watch-plugin
stack traces
or console.log
output from solidityI am getting this error while trying to run hardhat test:jest
on windows.
C:\repos\myProject\contracts>npr contracts:jest
> [email protected] contracts:jest
> hardhat test:jest --no-compile
You have both ethereum-waffle and @nomicfoundation/hardhat-chai-matchers installed. They don't work correctly together, so please make sure you only use one.
We recommend you migrate to @nomicfoundation/hardhat-chai-matchers. Learn how to do it here: https://hardhat.org/migrate-from-waffle
An unexpected error occurred:
Error: Can't find a root directory while resolving a config file path.
Provided path to resolve: C:\Users\Qwerty\repos\myProject\contracts/jest.config.js
cwd: C:\repos\myProject\contracts
at resolveConfigPath (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\node_modules\jest-config\build\resolveConfigPath.js:134:11)
at readConfig (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\node_modules\jest-config\build\index.js:228:49)
at readConfigs (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\node_modules\jest-config\build\index.js:420:32)
at runCLI (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\node_modules\@jest\core\build\cli\index.js:133:29)
at testFailures (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\src\index.ts:20:14)
at new Promise (<anonymous>)
at SimpleTaskDefinition.action (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\src\index.ts:15:32)
at async Environment._runTaskDefinition (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:14)
at async Environment.run (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat\src\internal\core\runtime-environment.ts:131:14)
at async SimpleTaskDefinition.action (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\src\index.ts:48:28)
(node:49648) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
But then when I run npx jest --showConfig
it does read my jest.config.ts
correctly, which can be seen from the output:
C:\repos\myProject\contracts>npx jest --showConfig
{
"configs": [
{
"cwd": "C:\\Users\\Qwerty\\repos\\myProject\\contracts",
"displayName": {
"name": "Contracts",
"color": "white"
},
This is my jest.config.ts
import type { Config } from '@jest/types'
const config: Config.InitialOptions = {
displayName: {
name: 'Contracts',
color: 'white',
},
testEnvironment: 'node',
testRegex: 'test/.*\\.(ts|tsx)$',
rootDir: '.',
moduleNameMapper: {
'^@abi/(.*)': '<rootDir>/abi/$1',
'^@typings$': '<rootDir>/typings',
'^@typings/(.*)': '<rootDir>/typings/$1',
},
silent: false,
verbose: false,
}
export default config
What I am finding odd is the weird forward slash where it should have been a backwards slash. And then it actually tries to load jest.config.js
instead of .ts
Provided path to resolve: C:\Users\Qwerty\repos\myProject\contracts/jest.config.js
What should I do?
how can I pass arguments to jest configs?
Is it possible that hardhat-jest-plugin
integrates solidity-coverage
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.