RepositoryJavaScript
scottschafer

scottschafer/cypressautomocker

cypress-based library for capturing APIs and replaying them as mocks

130sao
17fork
6issue
2lượt xem

🎯 Tự động mock API trong Cypress bằng cách ghi lại và phát lại

Ghi lại phản hồi API thật vào lần đầu, sau đó tự động dùng chúng để mock mà không cần chỉnh sửa test.

cypressautomocker là một thư viện dựa trên Cypress.io giúp bạn ghi lại kết quả gọi API khi chạy test lần đầu, rồu sau đó tự động phát lại như mock server mỗi lần chạy tiếp theo. Cách hoạt động giống như bản ghi âm — lần đầu ghi, các lần sau phát.

✨ Điểm nổi bật

  • Ghi và phát lại tự động: Lần đầu chạy sẽ ghi API vào file JSON, lần sau sẽ dùng file đó để mock.
  • Cấu hình linh hoạt: Dùng trường automocker trong cypress.json để bật/tắt record hoặc playback.
  • Hỗ trợ resolveMockFunc: Cho phép tùy chỉnh logic chọn mock nếu có nhiều phản hồi khác nhau.
  • Không dùng fixtures: Dùng cy.automockWaitOnPendingAPIs() để chờ API hoàn tất thay vì alias route.
  • Tích hợp dễ dàng: Chỉ cần thêm installCypressHooks() vào web app và registerAutoMockCommands() vào test.
  • Cài đặt nhanh: Hỗ trợ cài qua npm và chạy ngay với ví dụ mẫu.

💡 Vì sao đáng chú ý

Thay vì phải thủ công tạo fixture và cấu hình mock cho từng endpoint, cypressautomocker tự động hóa cả quá trình. Điều này đặc biệt hữu ích khi test các API có phản hồi thay đổi theo trạng thái hoặc thời gian. Tuy nhiên, do ghi lại theo thứ tự, nếu test gọi API theo thứ tự khác, mock có thể sai — cần xóa file ghi đã nếu thay đổi logic test.


#Cypress #Testing #MockAPI #AutoMocker #TiniX

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryJavaScript
abramenal/cypress-file-upload

File upload testing made easy

493
May 30, 2023
RepositoryPython
donnemartin/system-design-primer

Learn how to design large-scale systems. Prep for the system design interview. Includes Anki flashcards.

379.9k
Sep 15, 2026
RepositoryTypeScript
morluto/rea

Reverse engineer anything with agents, from app behavior down to native binaries.

487.0k
Dec 2, 2026
RepositoryTypeScript
n8n-io/n8n

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

212.9k
Dec 2, 2026
RepositoryPython
microsoft/markitdown

Python tool for converting files and office documents to Markdown.

199.5k
Dec 2, 2026
RepositoryTypeScript
microsoft/vscode

Visual Studio Code

195.9k
Nov 30, 2026
RepositoryShell
ohmyzsh/ohmyzsh

🙃 A delightful, community-driven framework for managing your zsh configuration. Built by 2,600+ contributors, with hundreds of plugins (git, rails, laravel, node, python, docker, kubectl, aws, and more), themes to spice up your terminal, and automatic updates to keep your command line feeling like home.

191.0k
Nov 29, 2026
Repository
getify/You-Dont-Know-JS

A book series (2 published editions) on the JS language.

184.8k
Oct 31, 2026
RepositoryJavaScript
louislam/uptime-kuma

A fancy self-hosted monitoring tool

95.1k
Nov 30, 2026