Record and replay network requests for Cypress
This repo is based on cypress-auto-stub-example with a few differences:
- you can specify folder and subfolder for fixture directory in
describe
block name, for exampledescribe('@userform/main', ...)
means that requests will be saved under fixtures/userform/main directory. Why? Because I found it easier to keep pathes for fixtures/snapshots/screenshots independent of test file path. Moreover, it allows you to create single file with all your tests imported for getting better performance. Check out this issue for more details - specified directory will be created with file
index.json
and<request>.json
. You can specifyurl2filename
function to deal with your own mapping. Why each request is in separate file? There is a limitation of 80kb max for request payload, but file fixtures solve this problem - each recorded request has associated fixture name. Check out
url2alias
function. It allows you towait('@fixture_name')
for requests.
yarn add -D Cloudo/cy-auto-stub
in cypress/support/index.js
import autoStub from 'cy-auto-stub'
// checkout src/defaults.js for default implementation
const options = {
// getFixtureDir,
// getFixturePath,
// url2filename,
// url2alias
}
autoStub.init(options)
- shared mocks (automatically looking up parent directory)
- modifying responses
- typescript support
- compilation to es5
- examples
- tests