Test (Cypress GitHub Backend): Introduce an option to record cypress tests data and run tests using recorded data by default #2674
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow up on the GraphQL PR, specifically this comment.
The main purpose of this PR it to allow running Cypress GitHub backend tests using mock/recorded data.
I've looked into several solutions:
http.request
andhttp.ClientRequest
).fetch
.The method I'm using is described in the Readme:
For recording - set up Cypress with a proxy (http://www.mock-server.com/), sanitize and transform the recorded data to an easier to process format.
For playback - Cypress exposes a sinon instance so I'm using that to stub
window.fetch
and match requests.Several problems I experienced in matching requests:
ts
parameter to bust browser caching. This is solved by using pattern matching on the URL.I initially solved it by entering a fixed date into the date field, but this wasn't good enough as slugs are formatted with the current date regardless of the post date.
Cypress has a
clock
function that mocks theDate
object, but it created another issue as some of the UI fields are de-bounced, thus ignoring value changes unless the the clock is advanced.The solution was to advanced the clock after updating posts just enough to trigger the de-bounced input field, while still keeping the slug generation consistent. We could also consider generating the slug based on the post date (if it has such a field).
can return entry to draft and delete it
was passing on Chrome but failing on Electron consistently (same behavior for REST and GraphQL). This revealed another race condition: When moving an entry fromIn Review
toDraft
while in open authoring mode, the PR that was created on the origin repo is closed (the forked repo branch is not deleted). One can click "Delete new entry" before the change status operation completes (moving fromIn Review
toDraft
), thus introducing the race. This doesn't have a negative effect on human users, but since the test validate toasts messages in order, it fails.indexedDB
between tests. This has to be done manually.Refactoring:
plugin/index.js
clean.Bug fixes:
new Date()
.this.api.reset
.Possible improvements:
Tests summary: