-
Notifications
You must be signed in to change notification settings - Fork 455
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
Cache tsconfig when generating per-file cache key. #286
Conversation
Fixes #280. |
@tvald Thanks for the PR! This looks good to me. Would it help to do this for calls to |
We'll need to keep in mind that caching might make #238 more difficult - however I definitely think it's worth it. Would like a comment explaining the reason for caching it though. |
@GeeWee yeah. That was the reason I was okay (tsconfig was being cached in the I also tried this setup when investigating #280. While there was some improvement, it wasn't enough that I'd consider #280 fixed by this. It would still be slower than mocha due to what I think is some kinda jest overhead |
|
But also, I do agree that this is merely a quick patch to make ts-jest usable. I didn't dig into your architecture enough to determine the appropriate way to cache |
I think this is the right way. The only concern is that there might be projects with multiple tsconfigs in different directories. But since we're not handling that use case currently and because that doesn't seem to be a very common use case, this change makes sense. |
@tvald Could you also
|
I moved caching inside
Neither |
|
src/utils.ts
Outdated
export function getTSConfig(globals, collectCoverage: boolean = false) { | ||
let config = getTSConfigOptionFromConfig(globals); | ||
const skipBabel = getTSJestConfig(globals).skipBabel; | ||
const isReferencedExternalFile = typeof config === 'string'; | ||
|
||
// check cache before resolving configuration | ||
// NB: config is a string unless taken from __TS_CONFIG__, which should be immutable (and is deprecated anyways) | ||
const tsConfigCacheKey = JSON.stringify([skipBabel, collectCoverage, isReferencedExternalFile ? config : undefined]); |
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.
Are we using a stringified JSON object as an object key here? That seems rather.. odd. Is there a reason we don't simply hash it?
At least I'd like a comment here explaining why JSON.stringify was chosen, as it's reasonably unintuitive, at least to me.
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.
Unless I'm misunderstanding, then please clarify.
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.
JSON.stringify
is available without imports and will produce a consistent, unique key from the parameters. It didn't seem worth the extra effort to generate a uniform key via crypto
. Can do that if it's desired, though.
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.
It's a fair point, it might be faster as well. I'd like a comment pointing it out though, generally the 'what' factor of it is pretty high - it's definitely not what you expect a json serialized object to be 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.
Ah, I thought you meant that you wanted a comment here on GitHub. I've just added the explanation in the code.
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.
Wonderful
I just have some minor nitpickery and we're good to go! |
Merging - thanks for the contribution! |
No description provided.