Posts

Showing posts with the label automation

Guide to Seeding Mock Data for PostgreSQL Using Prisma and Snaplet Seed

Image
Introduction @snaplet/seed is a highly powerful library that supports automatic mock data generation for databases based on the Prisma schema. Instead of manually writing hundreds of lines of complex insert code, @snaplet/seed automatically analyzes relations in the database to generate logical, consistent and data-integrity-assured data. Standout advantages include the ability to automatically reset the database, inherently understand foreign key constraints and support concise syntax for easily creating nested data structures. Prerequisites This article is used alongside Prisma in a NestJS project, I will not specifically mention how to set up Prisma anymore, you can review the previous article to have the necessary preparation before proceeding Detail First, install the package yarn add -D @snaplet/seed Then, add the following scripts to package.json { "scripts" : { "seed:init" : "npx @snaplet/seed init prisma/seed" , "seed:sync...

Process of applying TDD to a NextJS project

Image
Introduction Test-Driven Development (TDD) is an advanced software development methodology where tests are written before the actual source code is implemented. This process operates in a repetitive cycle: Red (Write a failing test) -> Green (Write the minimum source code to make the test pass) -> Refactor (Optimize the code structure). Advantages : Improve source code quality: Minimize potential bugs right from the initial development phase. Better system design: Thinking about testing first helps you build highly modular, loosely coupled and easy-to-maintain modules. Confident Refactoring: You can comfortably improve and optimize code without fear of breaking existing features, thanks to the automated test system protection. Living documentation: Test cases act as precise specification documentation, helping team members clearly understand how the system operates. Reduce Debugging Time : TDD helps detect errors right at the moment "just finished typing". 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...