chore(openapi-fetch): Split apart tests #1895
Merged
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.
Changes
Fixes #1852. Splits apart tests from one mega file into easier-to-manage smaller files.
There are also a few other changes which don’t affect runtime at all, and should just ensure better test accuracy.
Updates TS to
5.5.4
There are some type errors that may take more work to catch, but this at least updates the test suite to the latest version.
Changes
moduleResolution: "NodeNext"
This changes to
NodeNext
based on some feedback about using this in Node.js. Even though this utility is universal, and works in-browser and Node, enablingmoduleResolution: "NodeNext"
should just guarantee Node.js compatibility without losing browser compat.Replacing MSW with custom fetch
This PR also reduces a lot of boilerplate and footguns by swapping MSW with custom fetch:
Most API integraiton tests consist of the following steps:
Most tests involving mock servers are more focused on step 4 (and beyond), so this is where MSW (and other fetch mock libraries) shine. In fact, one of the largest reasons for mocking libraries existing is to specifically remove the boilerplate of steps 1–3 (example: MSW). But our tests focus on steps 1 and 2 (rarely step 3 when testing middleware). This makes sense because most test needs are for applications, not fetch libraries! But the unintended side-effect of trying to get back the boilerplate that these libraries try to save you from is (you guessed it) more boilerplate.
Simply replacing
fetch
using the custom fetch API is the ideal solution. It not only lets us not worry about a centrally-mocked server reaching across all tests; it also gives us the thing we want which is the “boilerplate” of direct introspection—the thing that mocking libraries intentionally try and save you from. The end result is tests that are easier to write, easier to predict, and completely remove shared state and setup. And run faster and with less overhead.There’s not really a danger we’re reducing coverage by not using
globalThis.fetch
; we’re just moving indirection. But even if there was some regression caused by this, we still have E2E tests in a headless browser that would catch it.How to Review
Checklist