
You might be tempted to write XHR responses in Cypress’ server onResponse() hook, but this would result in Cypress returning an error: “Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.”
Writing the data in the after() hook circumvents this problem (and is probably a better option anyway).