Structure fixtures so they can be easily tested for exclusivity #215
Merged
sindresorhus merged 2 commits intosindresorhus:mainfrom Jun 6, 2025
Merged
Structure fixtures so they can be easily tested for exclusivity #215sindresorhus merged 2 commits intosindresorhus:mainfrom
sindresorhus merged 2 commits intosindresorhus:mainfrom
Conversation
…nsive exclude declarations
sindresorhus
reviewed
Jun 5, 2025
Owner
I agree, that's more correct. |
Owner
|
Thanks :) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Without extensive exclude declarations as specified in the TODO message:
I identified each unique entry in the fixtures and, if they were reused across multiple types, hoisted them to the top and spread them into the fixtures. This allows us to filter out fixture values that have already been tested as being of the type under test. It becomes more declarative in the fixture definitions, rather than in the call site of the test.
I split the primitive type fixtures from the object type fixtures so that we can exclude all the entries that are not primitives without needing redundant properties in the fixture data.
Another structural change to the fixtures was changing the fixtures from a Map to a readonly object so that we can use the keys to access the
ismethods that we are testing. This removed 2 redundant lines from each fixture.I also iterate over the method names defined in the fixtures to ensure that everything listed is tested. Previously every fixture was used manually and needed to be added to a test after it was created.
If a method name has additional tests beyond the exclusive fixture based test, I labelled it as supplemental.
There was one tricky bit in there with
BufferandUint8Arraybeing the same thing so I added an exclusion there.Promisetype overObjectwhen it has the promise API. It seems strange that we would expect the typeDescription to bePromise, but the typeName would beObject. If you think we should leave it as is, I can probably create an exclusion for it.