Learn how to write and run comprehensive unit tests for your Clarity smart contracts using the Clarinet JS SDK and Vitest.
Deployment plans minimize the inherent complexity of deployments, such as smart contract dependencies and interactions, transaction chaining limits, deployment costs, and more, while ensuring reproducible deployments critical for testing purposes.
In this guide, you will learn how to:
Generate and configure a deployment plan.
Set deployment plan specifications.
Add project contract requirements.
Customize your deployment plan.
The SDK requires Node.js >= 18.0 and NPM to be installed. Volta is a great tool to install and manage JS tooling.
Comprehensive Unit Tests for counter
Let us now write a higher coverage test suite by testing the decrement and get-counter functions.
These two code blocks can be added at the end of tests/counter.test.ts.
To help developers maximize their test coverage, the test framework can produce a lcov report, using --coverage flag. You can set it in the scripts in the project package.json:
Then run the script with the following command. It will produce a file named ./lcov.info.
From there, you can use the lcov tooling suite to produce HTML reports.
The test framework can also be used to optimize costs. When you execute a test suite, Clarinet keeps track of all costs being computed when executing the contract-call, and displays the most expensive ones in a table.
To help developers maximize their test coverage, the test framework can produce a lcov report, using --coverage flag. You can set it in the scripts in the project package.json:
And run the script with the following command. It will produce a file named ./costs-reports.json.
For now, there isn't much you can do out of the box with a costs report. But in future versions of the Clarinet JS SDK, we will implement features to help keep track of your costs, such as checking that function calls do not go above a certain threshold.