Skip to content

Commit

Permalink
chore: clarify that tests are exercising our fetch wrapper (#1393)
Browse files Browse the repository at this point in the history
* chore: clarify that tests are exercising our fetch wrapper

* comment

* comment
  • Loading branch information
pauldambra authored Aug 29, 2024
1 parent 434318d commit e04ba42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions cypress/e2e/session-recording.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,29 @@ describe('Session recording', () => {
cy.phCaptures({ full: true }).then((captures) => {
const snapshots = captures.filter((c) => c.event === '$snapshot')

const snapshotTypes: number[] = []
const capturedRequests: Record<string, any>[] = []
for (const snapshot of snapshots) {
for (const snapshotData of snapshot.properties['$snapshot_data']) {
snapshotTypes.push(snapshotData.type)
if (snapshotData.type === 6) {
for (const req of snapshotData.data.payload.requests) {
capturedRequests.push(req)
}
}
}
}

// yay, includes type 6 network data
expect(snapshotTypes.filter((x) => x === 6)).to.have.length.above(0)
expect(capturedRequests).to.have.length.above(0)

// the HTML file that cypress is operating on (playground/cypress/index.html)
// when the button for this test is click makes a post to https://example.com
const capturedFetchRequest = capturedRequests.find((cr) => cr.name === 'https://example.com/')

expect(capturedFetchRequest.fetchStart).to.be.greaterThan(0) // proxy for including network timing info

expect(capturedFetchRequest.initiatorType).to.eql('fetch')
expect(capturedFetchRequest.isInitial).to.be.undefined
expect(capturedFetchRequest.requestBody).to.eq('i am the fetch body')
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion playground/cypress/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Send custom event
</button>

<button data-cy-network-call-button onclick="fetch('https://example.com')">
<button data-cy-network-call-button onclick="fetch('https://example.com', {body: 'i am the fetch body', method: 'POST'})">
Make network call
</button>

Expand Down

0 comments on commit e04ba42

Please sign in to comment.