Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arianXdev/hardhat-jest
A Hardhat plugin that allows you to use Jest easily!
https://github.com/arianXdev/hardhat-jest
blockchain ethereum hardhat hardhat-jest hardhat-plugin jest solidity web3
Last synced: 14 days ago
JSON representation
A Hardhat plugin that allows you to use Jest easily!
- Host: GitHub
- URL: https://github.com/arianXdev/hardhat-jest
- Owner: arianXdev
- License: mit
- Created: 2022-12-30T14:20:50.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-16T14:10:01.000Z (over 1 year ago)
- Last Synced: 2024-12-13T22:57:15.367Z (15 days ago)
- Topics: blockchain, ethereum, hardhat, hardhat-jest, hardhat-plugin, jest, solidity, web3
- Language: JavaScript
- Homepage: https://npmjs.com/package/hardhat-jest
- Size: 378 KB
- Stars: 9
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hardhat-jest [![hardhat](https://hardhat.org/buidler-plugin-badge.svg?1)](https://hardhat.org)
[![Npm package version](https://badgen.net/npm/v/hardhat-jest)](https://npmjs.com/package/hardhat-jest)
[![hardhat](https://hardhat.org/buidler-plugin-badge.svg?1)](https://hardhat.org/plugins)> **Warning**:
> If you're using < v1.0.6, Please update the package to the latest version ASAP! It may cause errors.Have you always wanted to use **Jest** instead of Mocha + Chai in your Hardhat Projects? 😉 Good News!
`hardhat-jest` allows you to use **Jest** easily 😃✌️
- [Installation](#installation)
- [Usage](#usage)
- [Options](#options): See all the available options
- [Hardhat Tasks](#hardhat-tasks): See all the Hardhat tasks## Installation
First of all, Make sure that you have `jest` already installed!
**Step 1:** Install the package
```
npm i hardhat-jest
```**Step 2:** Add to your `hardhat.config.js` file
```
require("hardhat-jest");
```If you're using Typescript, to your `hardhat.config.ts` file
```
import "hardhat-jest"; // Typescript
```## Usage
It's so easy, You can run your Jest tests by
```
npx hardhat jest
```You've been using `npx hardhat test` to run your Mocha tests so far, but NOW you only need to use `jest` instead of `test` and Done!
### Options
If you're looking to see all the options, you can do it by running `npx hardhat help jest`:
```shell
Usage: hardhat [GLOBAL OPTIONS] jest [--bail] [--no-compile] [--show-config] [--use-verbose ] [--watch] [--watch-all]OPTIONS:
--bail Stop running tests after the first test failure.
--no-compile Do NOT compile before running this task.
--show-config Print your jest config and then exits.
--watch Watch files for changes and rerun tests related to changed files.
--watch-all Watch files for changes and rerun all tests.
--use-verbose Display individual test results with the test suite hierarchy. | Enable / Disable [boolean] (default: false)jest: Runs Jest tests
For global options help run: hardhat help
```to use options, you can easily run
```shell
npx hardhat jest// for example
npx hardhat jest --no-compile --watch
```#### --use-verbose
If you want Jest to display individual test results with the test suite hierarchy, you can use `--use-verbose` this way:
```
npx hardhat jest --use-verbose true // enables verbose mode only for this projectnpx hardhat jest --use-verbose false // disables verbose mode for the project
```Remember: the default value is `false` and disabled, so you must enable it if you want.
#### Specific files to test (testFiles)
If you want Jest to run only specific files instead of all test files, you can do that by:
```shell
npx hardhat jest test/Test3.test.js test/Test4.test.js
```NOTE: You must specify files with their full path (from the project root directory)
### Hardhat-tasks
You can see all the available Hardhat tasks by running `npx hardhat`
```shell
AVAILABLE TASKS:check Check whatever you need
clean Clears the cache and deletes all artifacts
compile Compiles the entire project, building all artifacts
console Opens a hardhat console
coverage Generates a code coverage report for tests
flatten Flattens and prints contracts and their dependencies
gas-reporter:merge
help Prints this message
> jest Runs Jest tests
node Starts a JSON-RPC server on top of Hardhat Network
run Runs a user-defined script after compiling the project
test Runs mocha tests
typechain Generate Typechain typings for compiled contracts
verify Verifies contract on Etherscan
```and There it is, `jest` task is added successfully! it means that you can run **`npx hardhat jest`** and your tests will be run!
## Final thoughts
Finally, show us some love by **starring** the repository on GitHub!️ 😊
Happy hacking!