Posts

Showing posts with the label ci/cd

Instruction to Deploy Contract Test between NextJS and NestJS with Pact

Image
Introduction Contract Testing is an integration testing method focused on verifying the interaction between a Consumer (the service user) and a Provider (the service provider). Instead of testing the entire system, Contract Testing ensures that both parties adhere to a shared covenant (contract). Key benefits include: early detection of non-compatible errors between Frontend and Backend, reduction of dependency on complex staging environments and enabling API changes to be made more confidently without breaking the partner's application. Pact is currently the most popular Consumer-Driven Contract Testing tool. It allows the Consumer to define expectations regarding the response from the Provider and then packages these expectations into a JSON file (Pact file). Pact's advantages lie in supporting multiple languages, automatically generating documentation based on test cases and having robust integration capabilities into CI/CD pipelines to ensure the Provider always meets the C...

Guide to Setting Up Playwright E2E Testing in NextJS

Image
Introduction Playwright is a powerful automated testing framework developed by Microsoft, allowing for End-to-End (E2E) testing across modern browsers such as Chromium, Firefox, and WebKit. Key advantages include fast execution speed due to its event-driven architecture, auto-wait capabilities that reduce "flaky" errors, default support for parallel execution, and the Codegen tool which helps generate automated test scripts by recording user interactions. Prerequisites This article is a continuation of my previous posts, so I will not provide the test code files again; please review them to have the source code ready before proceeding. Detail First, if your project does not have Playwright yet, you can set it up quickly as follows; this command will install the necessary packages and create a config file along with demo test files: yarn create playwright Or install the following packages manually: yarn add -D @playwright/test yarn playwright install Update playwright.c...

Setup Guide: Writing Tests in NextJS with Vitest

Image
Introduction Vitest is a modern testing framework built on Vite. It boasts incredibly fast execution speed by leveraging worker threads, perfect compatibility with the Jest ecosystem (in terms of syntax and API), and excellent support for TypeScript/JSX without complex configuration. In this article, I will guide you on writing unit tests, component tests, and integration tests. Unit Test: Checks independent functions or logic to ensure they work correctly with different inputs. Component Test: Checks the user interface and interactions of individual components. Integration Test: Checks the coordination between multiple components or between the client and the API (often mocked) to ensure smooth business logic flow. Prerequisites This article is implemented on a NextJS project, please initialize a project before continuing. Detail I will continue using content from the Demo AI Agent article to write tests for it, but will need to refactor the code to better support testing as follows: ...