-
Notifications
You must be signed in to change notification settings - Fork 459
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
fix for decorator coverage #488
Changes from 5 commits
e4fd8d1
dcd3432
f92a728
60dac3c
d8d096f
0253ac2
522385a
039cb69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,14 +55,28 @@ export function process( | |
fileName: filePath, | ||
}); | ||
|
||
let tsTranspiledText = tsTranspiled.outputText; | ||
if (tsJestConfig.ignoreCoverageForAllDecorators === true) { | ||
tsTranspiledText = tsTranspiledText.replace( | ||
/__decorate/g, | ||
'/* istanbul ignore next */__decorate', | ||
); | ||
} | ||
if (tsJestConfig.ignoreCoverageForDecorators === true) { | ||
tsTranspiledText = tsTranspiledText.replace( | ||
/(__decorate\(\[\r?\n[^\n\r]*)\/\*\s*istanbul\s*ignore\s*decorator(.*)\*\//g, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the comment is actually processed by istanbul and not by ts-jest so the current form is correct |
||
'/* istanbul ignore next$2*/$1', | ||
); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you tell me what this else block is doing? Ideally, this shouldn't change any behavior for folks who haven't set this flag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I made two options to ignore decorators. One is with setting the config param ignoreCoverageForAllDecorators. Thi swill ignore all decorators and it's useful for Angular where you don't have control over the code. This is described in #454. But the other option is to add the /* istanbul ignore decorator */ and it will ignore only this decorator. I prefer the second option because I like to have control over which part of code I want to ignore in coverage. Both are optional and if you don't use them it will not modify anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant was that if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add another config for that. There are basically 3 scenarios. First is for users who don't want to change anything, second is for someone like me who want's to control which decorators are ignored and the third is for users who want to ignore all decorators. The last one is enabled by ignoreCoverageForAllDecorators config param. The first and second I didn't make any config setting but you control it by providing (or not) the /* istanbul ignore decorator */ comment. But I can add another config param for that if you believe it is necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think that would be the way to go to avoid any side effects for users who aren't setting the flag at all. I'll take a look at this again after work and merge it if it's ready (flags, docs and updated version patch). Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Updated the readme too. |
||
const postHook = getPostProcessHook( | ||
compilerOptions, | ||
jestConfig, | ||
tsJestConfig, | ||
); | ||
|
||
const outputText = postHook( | ||
tsTranspiled.outputText, | ||
tsTranspiledText, | ||
filePath, | ||
jestConfig, | ||
transformOptions, | ||
|
@@ -71,7 +85,7 @@ export function process( | |
const modified = | ||
tsJestConfig.disableSourceMapSupport === true | ||
? outputText | ||
: injectSourcemapHook(filePath, tsTranspiled.outputText, outputText); | ||
: injectSourcemapHook(filePath, tsTranspiledText, outputText); | ||
|
||
flushLogs(); | ||
|
||
|
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 think the name for this configuration option is a bad choice. I'd recommend something such as
enableDecoratorIgnoreComment
. Maybe this should simply betrue
always and not configurable.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.
As this is basically a fix for using typescript with istanbul I think both should default to
true
.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 not set to true by default because ts-jest is not the right place for this. It is only being put in here because it seems like the fastest option to help address this issue and this shouldn't affect users who don't care about this part