同学们,许久不见,难得有时间,决定还是给大家安利一个新技术
其核心是 Pollyjs
官网地址:https://netflix.github.io/pollyjs/#/
Why Polly?
Keeping fixtures and factories in parity with your APIs can be a time consuming process. Polly alleviates this by recording and maintaining actual server responses without foregoing flexibility.
Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
Use Polly's client-side server to modify or intercept requests and responses to simulate different application states (e.g. loading, error, etc.).
Features
Fetch & XHR Support
⚡️️ Simple, Powerful, & Intuitive API
First Class Mocha & QUnit Test Helpers
Intercept, Pass-Through, and Attach Events
Record to Disk or Local Storage
⏱ Slow Down or Speed Up Time
这应该是6月份才出的开源框架,网上资源很少,但其本身确相当好用,能很大程度解决前端mock数据的痛点。
1. 该方案可以将每个线上接口请求回来的json自动的下载到本地
2. 若想用下载到本地的数据进行不同情况数据的模拟,只需将「mode」改成 「replay」即可不走线上接口,直接走本地接口
我自己写了一个关于它的简单应用demo,希望对大家有所帮助。
demo地址:
https://github.com/gyfnice/perfect-mock
大家可以通过demo,理解其核心应用~
大家若有更好的方案,欢迎多多交流~
领取专属 10元无门槛券
私享最新 技术干货