New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Jest dependencies peer dependencies #331
Make Jest dependencies peer dependencies #331
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think making them peers are correct - it'll work with different versions of jest regardless of version mismatch. And either way I think you'll only need get-types
, I don't think the others are used
package.json
Outdated
"jest-watch-typeahead": "^0.2.0", | ||
"lint-staged": "^6.0.0", | ||
"prettier": "^1.7.4", | ||
"pretty-format": "^22.1.0" | ||
}, | ||
"dependencies": { | ||
"peerDependencies": { | ||
"@types/jest": "^22.0.0", | ||
"expect": "^24.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither expect
nor jest-matcher-utils
should need to be deps - what are they used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For expect
, several predicates have import { equals } from '../../utils';
, which in turn has
import { equals } from 'expect/build/jasmineUtils';
...
export { equals };
$ grep -l "from '../../utils'" src/matchers/*/*.js
src/matchers/toBeArrayOfSize/index.js
src/matchers/toBeEmpty/predicate.js
src/matchers/toBeOneOf/predicate.js
src/matchers/toContainAllEntries/predicate.js
src/matchers/toContainAllKeys/predicate.js
src/matchers/toContainAllValues/predicate.js
src/matchers/toContainAnyEntries/predicate.js
src/matchers/toContainAnyValues/predicate.js
src/matchers/toContainEntries/predicate.js
src/matchers/toContainEntry/predicate.js
src/matchers/toContainValue/predicate.js
src/matchers/toContainValues/predicate.js
src/matchers/toIncludeAllMembers/predicate.js
src/matchers/toIncludeAnyMembers/predicate.js
src/matchers/toIncludeSameMembers/predicate.js
I know there was some talk about whether this was needed, but I didn't honestly understand why.
For jest-matcher-utils
, most matchers import that
$ grep -l "from 'jest-matcher-utils'" src/matchers/*/*.js
src/matchers/toBeAfter/index.js
src/matchers/toBeArray/index.js
src/matchers/toBeArrayOfSize/index.js
src/matchers/toBeBefore/index.js
src/matchers/toBeBoolean/index.js
src/matchers/toBeDate/index.js
src/matchers/toBeEmpty/index.js
src/matchers/toBeEven/index.js
src/matchers/toBeExtensible/index.js
src/matchers/toBeFalse/index.js
src/matchers/toBeFinite/index.js
src/matchers/toBeFrozen/index.js
src/matchers/toBeFunction/index.js
src/matchers/toBeHexadecimal/index.js
src/matchers/toBeNaN/index.js
src/matchers/toBeNegative/index.js
src/matchers/toBeNil/index.js
src/matchers/toBeNumber/index.js
src/matchers/toBeObject/index.js
src/matchers/toBeOdd/index.js
src/matchers/toBeOneOf/index.js
src/matchers/toBePositive/index.js
src/matchers/toBeSealed/index.js
src/matchers/toBeString/index.js
src/matchers/toBeTrue/index.js
src/matchers/toBeValidDate/index.js
src/matchers/toBeWithin/index.js
src/matchers/toContainAllEntries/index.js
src/matchers/toContainAllKeys/index.js
src/matchers/toContainAllValues/index.js
src/matchers/toContainAnyEntries/index.js
src/matchers/toContainAnyKeys/index.js
src/matchers/toContainAnyValues/index.js
src/matchers/toContainEntries/index.js
src/matchers/toContainEntry/index.js
src/matchers/toContainKey/index.js
src/matchers/toContainKeys/index.js
src/matchers/toContainValue/index.js
src/matchers/toContainValues/index.js
src/matchers/toEndWith/index.js
src/matchers/toEqualCaseInsensitive/index.js
src/matchers/toHaveBeenCalledAfter/index.js
src/matchers/toHaveBeenCalledBefore/index.js
src/matchers/toInclude/index.js
src/matchers/toIncludeAllMembers/index.js
src/matchers/toIncludeAnyMembers/index.js
src/matchers/toIncludeMultiple/index.js
src/matchers/toIncludeRepeated/index.js
src/matchers/toIncludeSameMembers/index.js
src/matchers/toReject/index.js
src/matchers/toResolve/index.js
src/matchers/toSatisfy/index.js
src/matchers/toSatisfyAll/index.js
src/matchers/toStartWith/index.js
src/matchers/toThrowWithMessage/index.js
Correct me if I've misunderstood something here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All matchers are injected with this.equals
(and this.utils
): https://jestjs.io/docs/expect#thisequalsa-b
What do you mean? That we shouldn't have any peer dependencies (i.e. keep them as dependencies that will be transitively pulled into projects)? Or that the versions that I currently have in the peer dependencies aren't right? I do think we still need |
|
A separate PR removing the dependencies on |
But wouldn't removing jest-matcher-utils require a project using jest-extended to add Jest dependency to get the injections you mentioned? And those aren't currently dependencies... Just didn't want to leave it in an inconsistent state between the 2 PRs. |
I don't follow this sentence, sorry 😅 Maybe this is an answer anyways: When people use |
I reworded to be clearer, but I'll try again here. What I don't understand is if we just delete jest-matcher-utils as a dependency, how does that get hoisted for the person using jest-extended? It would seem like you're counting on them getting it from somewhere else, but if you've just done the delete alone and not added any peer dependency there's nothing explicitly stating they need to depend on anything else. Now odds are basically 100% that they will also depend on jest, and this will cause that dependency to be hoisted -- but shouldn't that be explicit in the dependencies (i.e. as a peer dependency)? |
We don't need anything to be hoisted. expect.extend({
myMatcher() {
console.log(typeof this.equals) // function
console.log(typeof this.utils.printExpected) // function
}
}) i.e. there is never any need to import the utils, |
An example of how this is not needed can be seen in testing-library/jest-dom#250 if that helps clarify the point I'm trying to make 🙂 |
I think I mis-used the term "hoist". Should we be replacing the imports |
Yeah, that's what I want us to do 👍 same for the |
Gotcha, thank you. Now what you said makes sense 😄 |
Made a draft until the dependency refactor mentioned is complete. |
Created #332 to address previous conversation here. |
Codecov Report
@@ Coverage Diff @@
## main #331 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 137 137
Lines 843 853 +10
Branches 143 143
=========================================
+ Hits 843 853 +10
Continue to review full report at Codecov.
|
Now that we're deleting expect and jest-matcher-utils, I think there's nothing left to do in this MR. Making |
What
Moving the Jest dependencies from dev dependencies to peer dependencies.
Why
Since jest-extended requires Jest dependencies to be hoisted by the project using it (since it's sort of like a plugin for Jest and doesn't have a have and shouldn't have a transitive dependency on Jest itself), we should make that requirement clear by marking Jest as a peer dependency. This should also serve as a resolution for the issue mentioned in #331.
Notes
dim
tags into a single tag. I'm guessing this was improved somewhere along the way in Jest and now that the dev dependencies are fully Jest 24, we have a newer Jest version used for tests that include this improvement.@types/jest
be marked as an optional peer since only the jest-extended types would require that to be hoisted?jest-get-type
be marked as an optional peer since onlytoBeValid
,toBeDate
, andtoBeObject
require that to be hoisted?Housekeeping