Skip to content

This project is designed as a learning resource for understanding how to implement end-to-end (E2E) testing for a Node.js API. It provides a practical, hands-on approach to learning E2E testing concepts and techniques.

License

AndresDiagoM/curso-e2e-testing-nodejs-api

Repository files navigation

End-to-End Testing Course for REST APIs with Node.js

Table of Contents

End-to-End Testing

This project uses Jest and Supertest for end-to-end testing of the API. The tests simulate real user interactions with the API and check that it behaves as expected.

To run the end-to-end tests, use the following command:

npm run test:e2e

This will start Jest and run all test files in the e2e directory. Each test file corresponds to a different part of the API.

End-to-end tests are a great way to ensure that your API works as expected and that it continues to work as you make changes to it. They can help you catch bugs early and avoid regressions in your code.

This kind of testing is essential for any production application, as it helps you try out the services and database connections in a real-world scenario.

Logo

Tech Stack

Tech Stack Badge
Node.js NodeJS.org
Express.js ExpressJS.com
Docker Docker.com
PostgreSQL PostgreSQL.com
Jest JestJS.io
Supertest Supertest.io

Install the project

To install the project, run the following command:

npm install

After that is necessary to create the .env file with the following content:

PORT = 3000
DATABASE_URL= postgres://<use>:<pass>@localhost:5432/my_store
API_KEY= 12345
JWT_SECRET='secret123456'
SMTP_EMAIL=your@email.com
SMTP_PASSWORD=password-email

Database Setup

In this case we are using docker to create the postgres database, so you need to have docker installed on your machine.

Then you can connect to the database and create the database with the following command:

docker-compose exec postgres bash
psql -h localhost -d my_store -U <user>
\d+
SELECT * FROM users;
DELETE FROM users WHERE id=<id>;

Migrations

npm run migrations:run

How to generate coverage report

npm run test:coverage

Which is the npm task that runs the jest with the --coverage flag. This will generate a coverage folder with the index.html file that you can open in your browser to see the coverage report. The entire task is configured in the package.json file.

The folder name was configured in the jest-e2e.json file, so its name is coverage-e2e.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

This project is designed as a learning resource for understanding how to implement end-to-end (E2E) testing for a Node.js API. It provides a practical, hands-on approach to learning E2E testing concepts and techniques.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published