Welcome to the Node Native Test Runner repository! This project contains code samples and unit tests utilizing Node.js's native test runner.
This repository serves as a practical guide for developers looking to leverage Node.js's built-in testing capabilities. Here, you'll find examples that demonstrate efficient testing practices, focusing on simplicity and integration.
Node.js version 18 (and later) includes a powerful, built-in test runner that simplifies the testing process. It offers features like:
- Test Suites (
describe
) - Test Cases (
it
ortest
) - Assertions (
assert
) - Mocking (
mock
) - Subtests
- Reporters
...and more! This means you can write robust tests without relying on external testing frameworks.
This repository provides code samples that demonstrate:
- Basic Test Setup: How to structure your test files and use the core features of
node:test
. - Mocking Dependencies: Techniques for isolating your code and simulating external dependencies using the built-in
mock
module.
- Node.js 20 or later
Yarn
-
Clone the Repository:
git clone https://github.com/DevInsightLab/node-native-test-runner.git
-
Navigate to the project directory
cd node-native-test-runner
-
Install dependencies
yarn install
Browse the different examples to see how node:test
is used in various scenarios.
-
Execute the following command to run the tests:
yarn test
-
Run tests with coverage
yarn run test:cov
Check out our blog post for a detailed explanation of the examples in this repository. It provides insights and additional context to help you get the most out of these resources.
Contributions are welcome! If you have an example that demonstrates a specific testing concept or best practice using Node.js's native test runner, feel free to open a pull request.
For questions or suggestions, please open an issue or contact us directly.
💙 If you find this project helpful, please give it a ⭐ and share it with others!