-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage logic for gjs/gts files
Update pnpm version to fix invalid string error Fix emroider comparibility bump @embroider/addon-dev and assert sorcemap remap is working Add a comment why we need to cleanup .embroider folder between test runs Improve docs and add more comment explanations remove explicit extensions from test app bring back babel transpilation plugin Fix type Co-authored-by: Sergey Astapov <SergeAstapov@gmail.com> Fix typo 2 Co-authored-by: Sergey Astapov <SergeAstapov@gmail.com>
- Loading branch information
1 parent
ab83a79
commit c568ae9
Showing
81 changed files
with
21,078 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
65 changes: 65 additions & 0 deletions
65
packages/ember-cli-code-coverage/lib/gjs-gts-istanbul-ignore-template-plugin.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* When gjs/gts is converted to js it looks like this | ||
* | ||
* @example | ||
* template(` | ||
* <div> | ||
* template code | ||
* </div>` | ||
* , { | ||
* eval() { | ||
* return eval(arguments[0]); | ||
* } | ||
*}); | ||
* | ||
* The problem is Istanbul's babel plugin will try to instrument the `eval` method which can skew coverage results. | ||
* In order to avoid this we add this plugin to add Istanbul ignore comments above `eval` to make sure it won't be instrumented by babel | ||
*/ | ||
const gjsGtsTemplateIgnoreVisitor = { | ||
CallExpression(path) { | ||
const { node } = path; | ||
let { callee } = node; | ||
|
||
if (callee.name !== 'template') { | ||
return; | ||
} | ||
|
||
const callScopeBinding = path.scope.getBinding('template'); | ||
|
||
if ( | ||
callScopeBinding.kind === 'module' && | ||
callScopeBinding.path.parent.source.value === '@ember/template-compiler' | ||
) { | ||
const babelIgnoreComment = { | ||
type: 'CommentBlock', | ||
value: ' istanbul ignore next ', | ||
}; | ||
|
||
if (!path.findParent((path) => path.isStatement()).node.leadingComments) { | ||
path.findParent((path) => path.isStatement()).node.leadingComments = []; | ||
} | ||
path | ||
.findParent((path) => path.isStatement()) | ||
.node.leadingComments.push(babelIgnoreComment); | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = function () { | ||
return { | ||
visitor: { | ||
Program: { | ||
enter(path, state) { | ||
const filename = state.file.opts.filename; | ||
|
||
if (!filename?.match(/\.g[tj]s$/)) { | ||
return; | ||
} | ||
|
||
// We need to do early traverse to make sure this runs before istanbuls plugin | ||
path.traverse(gjsGtsTemplateIgnoreVisitor, state); | ||
}, | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.