A basic eCommerce application developed with Node.js, focusing on CRUD operations and showcasing automated testing using Jest. The application integrates a MongoDB database and demonstrates robust testing practices to ensure functionality.
- Basic eCommerce functionality: -Create, read, update, and delete (CRUD) operations for products.
- MongoDB Integration:
- Stores and retrieves product data efficiently.
- Testing with Jest:
- Comprehensive testing for routes and database operations.
- Environment-Specific Configurations:
- Uses dotenv and cross-env for environment management.
- Node.js
- Express.js
- MongoDB (via
mongoose
) - Jest (testing framework)
- Supertest (for HTTP assertions)
- cross-env (for environment variable management)
- dotenv (to manage environment variables)
Ensure you have the following installed:
- Node.js (v14 or higher)
- MongoDB (local or hosted)
- npm (comes with Node.js)
-
Clone the repository:
git clone /~https://github.com/kxng0109/test-app-using-jest.git cd test-app-using-jest
-
Install dependencies:
npm install
-
Set up environment variables (see Environment Variables).
-
Start the development server:
npm run dev
Create a .env file in the root directory with the following variables:
MONGODB_URI=<link_to_mongodb_database>
PORT=3000
Replace <link_to_mongodb_database> with the path to your mongoDB database Note: Never push your .env file to version control.
- Start the server:
npm start
-
Use tools like Postman or curl to test API endpoints, or use the integrated Jest tests to validate functionality.
-
Access the application via:
http://localhost:PORT
Note: "PORT" is set to 3000 by default.
- Use tools like Postman to test API endpoints.
The primary focus of this application is its testing capabilities. Testing is implemented using Jest and Supertest.
- To run all tests:
npm test
- Test scripts:
- Unit tests: Validate individual functions and components.
- Integration tests: Verify API endpoints and database interactions.
The test
script sets the environment to test
and executes Jest:
cross-env NODE_ENV=test jest --testTimeout=5000
This project is licensed under the MIT License - see the LICENSE file for details.