-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Track and allow querying in-flight requests (#186)
* test(pending): add tests for pending requests - update middleware to support delayed responses * chore(types): update shape of `InterceptedRequest` - `addRequest` always sets `pending: false` - while `typeof null === 'object'`, clarify that body and response.body can be null. * feat(types): update type signatures for `getRequest`, `getRequests` - if not passing options object (all past code), will continue to receive completed requests only - if passing options object with includePending = false, will receive completed requests only - if passing options object with includePending = true, will receive all requests. * feat: add `hasPendingRequests` test method - refactor tests for pending requests into own describe block, and add explicit waits to avoid affecting following tests. * refactor(types): switch from property declaration to function declaration Support function overloads in future work * refactor(sessionStorage): add helper method for support checking, extract method for getting contents - add runtime check for incomplete polyfill scenario, where fetch is polyfilled but Promise.all is not. * feat(getRequest): attach pending property to incomplete retrieved requests & parse the response body only if marked as fulfilled * fix(tests): add missed awaits to `assert.rejects` usage - in sync mode, these were awaited implicitly. In async mode, however, they must be explicitly awaited. - Increase assertion strictness on the matched errors - due to an issue with how assert.rejects forwards a regexp containing an escaped regexp, use a validation function to directly invoke assert.matches with the regexp * feat(fetch-api): add basic support for pending request queries - add requests prior to invoking window._fetch - complete requests after the full response body is available * feat(xhr-api): add basic support for pending request queries - note: must stringify `lastURL` in case XHR#open is invoked with a URL object. * refactor(xhr-api): simplify parsePayload method - replace `if-else if` chain with `if + return` - log the serialization error, if any * feat(logs): prefix any emitted errors with `[wdio-intercept-service]` consumers should be able to easily identify the source of an issue when they are running tests Ideally these logs would be passed to the node / test context, rather than emitted in the tested browser, but depending on the test runner they may be surfaced without much additional work * test(getRequest): add test for includePending: false (default case) This is the existing behavior as of 4.1.10 and all earlier versions * feat(getRequest): wire up the `includePending` request option simplify assignment to `request` in node context * test(request-order): add tests for the order of retrieved requests The behavior in 4.1.10 and earlier versions is that requests are ordered by time of fulfillment (`orderBy: 'END'`). This should remain the default behavior, but users should be able to order by the time the request started as well (which is possibly more under their control, in terms of testing, too). When pending requests are requested, this default sort will place them last (as they are not yet "completed"). * feat(request-order): wire up `orderBy` parameter in interceptor lib * refactor: Avoid fetching full request list from browser to check if any request is pending * feat(assert-api): allow passing `orderBy` options to `assertRequests` methods - deprecate boolean param to assertExpectedRequestsOnly - pass `inOrder` as an option instead - don't suggest asserting on pending requests will work - Since a pending request has no response, it has no response status code. (Passing `includePending: true` would result in a TypeError in the library code). - A better approach will be to support an option that requires pending requests are completed before performing assertions. * test(firefox): bump slow delay to 1000 ms to account for slower FF driver * docs: update README with latest API changes * docs: update comment, formatting * refactor: add package prefix constant for logs, errors * docs: Update README to better describe configuration options for several methods * docs: update changelog with release summaries
- Loading branch information
Showing
9 changed files
with
703 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
errorShots | ||
node_modules | ||
test/logs | ||
test/**/logs | ||
test/**/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.