This project is a template for demonstrating the capabilities and features of the native Node.js test runner with minimal dependencies. It leverages the latest features of Node.js to provide a modular, scalable, and efficient testing framework suitable for modern JavaScript applications.
- Modular Architecture: The project is structured in a modular way to improve readability and maintainability. Each module is responsible for a specific functionality, making the codebase easier to understand and extend.
- Scalability: The project structure is designed to be easily scalable. New features and tests can be added without disrupting the existing codebase.
- Separation of Concerns: The project separates unit tests and integration tests to ensure that each type of test is focused on its specific purpose.
- Efficient HTTP Client: The project uses
undici
for HTTP requests due to its speed and memory efficiency.undici
is maintained by the Node.js development team, ensuring compatibility and performance. - Continuous Integration: The project includes a CI/CD pipeline using GitHub Actions to automatically run tests on each push or pull request, ensuring code quality and reliability.
node-testrunner/
├── .env
├── .eslintrc.json
├── .github/
│ └── workflows/
│ └── nodetest.yml
├── .gitignore
├── .prettierrc
├── logger.cjs
├── Makefile
├── package.json
├── README.md
├── test-settings.json
├── tests/
│ ├── integration/
│ │ └── auth/
│ │ ├── login.test.cjs
│ │ └── register.test.cjs
│ ├── unit/
│ │ ├── data-generators.test.cjs
│ │ ├── http-utils.test.cjs
│ │ └── user-utils.test.cjs
│ └── utils/
│ ├── crypto/
│ │ └── crypto.cjs
│ ├── data/
│ │ └── data-generators.cjs
│ ├── env.cjs
│ ├── http/
│ │ └── http-utils.cjs
│ └── user/
│ └── user-utils.cjs
- Utilizes the native Node.js test runner introduced in recent versions of Node.js, eliminating the need for external testing libraries.
- Provides a simple and efficient way to write and run tests using the built-in
node:test
module. - Demonstrates the capabilities of the Node.js test runner for both unit tests and integration tests.
- Focuses on minimizing external dependencies to reduce overhead and simplify the project.
- Relies mainly on Node.js core modules and a few carefully selected packages.
- Employs a modular project structure to improve the readability and maintainability of tests.
- Easily scalable to accommodate additional tests and features as the project grows.
- Uses
undici
as the HTTP client for its exceptional speed and memory efficiency. undici
is maintained by the Node.js development team, ensuring compatibility and performance.- Simplifies HTTP request handling in tests with modern APIs.
- Includes a CI/CD pipeline using GitHub Actions.
- Automatically runs tests on each push or pull request, ensuring code quality and reliability.
- Plans to add Docker support to run tests inside an isolated, containerized environment.
- Aims to improve portability and ease of deployment across different systems.
- Node.js v23 or later is required to utilize the latest features.
- npm is needed for package management.
Clone the repository and install the dependencies:
git clone https://github.com/yourusername/node-testrunner.git
cd node-testrunner
make install-dependencies
Run all tests using the makefile:
make run-all-tests
Or run specific tests:
-
Unit Tests:
make run-unit-tests
-
Integration Tests:
make run-integration-tests
- tests/: Contains all test files organized into unit and integration tests.
- unit/: Holds unit tests for individual modules.
- data-generators.test.cjs: Tests for data generation utilities.
- http-utils.test.cjs: Tests for HTTP utility functions.
- user-utils.test.cjs: Tests for user-related utilities.
- integration/: Contains integration tests that test the interaction between different modules and external APIs.
- auth/:
- login.test.cjs: Integration tests for the login functionality.
- register.test.cjs: Integration tests for the user registration functionality.
- auth/:
- utils/: Includes utility modules used across tests.
- crypto/:
- crypto.cjs: Cryptographic utility functions.
- data/:
- data-generators.cjs: Functions to generate random test data.
- env.cjs: Environment configuration loader.
- http/:
- http-utils.cjs: HTTP request utility functions using
undici
.
- http-utils.cjs: HTTP request utility functions using
- user/:
- user-utils.cjs: Utility functions for user operations in tests.
- crypto/:
- unit/: Holds unit tests for individual modules.
- Makefile: Provides convenient commands for installing dependencies and running tests.
- package.json: Manages project metadata and scripts.
- .github/workflows/nodetest.yml: Defines the GitHub Actions workflow for CI/CD.
- logger.cjs: Sets up application logging using
pino
andpino-pretty
for readable console output. - test-settings.json: Stores configuration settings for tests, such as test user data.
- .env: Loads environment variables from the
.env
file.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or suggestions.
This project is licensed under the MIT License.