You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello there! It appears I'm having issues with collecting coverage from first-class component templates (<template>).
When running ember test with COVERAGE=true, Im getting the following error on the first .gts file:
.../components/misc/loading-indicator/loading-indicator.component.ts: Scope functions can only consist of a single return statement which returns an object expression containing references to in-scope valuesError: .../components/misc/loading-indicator/loading-indicator.component.ts: Scope functions can only consist of a single return statement which returns an object expression containing references to in-scope values
Is there a known incompatibility between ember-cli-code-coverage and gjs/gts files? Is there a workaround I'm not aware of?
@spuxx1701 I have 2 non-typescript projects on ember 4.12 and I'm running into this issue as well in one of the projects.
I've aligned the dependencies and configuration of both projects to be the same, so I'm not entirely sure what the issue is. The only thing that is different between the working and non-working project is that I migrated all of the files to .gjs at once in the working project.
Edit: I went back to the working project and added a few non-.gjs components and the tests still ran with coverage enabled.
Hi, I've been trying to get .gjs/.gts coverage working for a few days, I've done some digging and I think I've Identified the steps to get this working.
So there are a couple of things needed.
Add .gjs/.gts extension to babel-plugin-istanbul 's extension options (this is just so that it recognizes and instruments these files).
Add source map support for content-tag
Basically the code is first getting transpiled by content-tag from gjs/gts to ts/js and after that it is running through babel where the instrumentation happens, BUT when we transpile it with content-tag right now it doesn't generate source maps which are actually needed to map the transpiled code back to the original gjs/gts code, w/o this coverage lines will be off also it will report on some function that don't exist in the source code.
Created issues for this: [Feature request] source map generation embroider-build/content-tag#61
Remap the coverage data generated during test runs to the original code using istanbul-lib-source-maps and providing it the inputSourceMap that we get from step 2.
This last step basically means we need to add some additional functionality to ember-cli-code-coverage, after that in theory it should work (I will work on this and try to make a PR, also will raise a separate issue for this part)
@vstefanovic97 I have .gjs code coverage working in one of my projects. I just have no idea why it works in one project and not the other two projects. All of the projects are on Ember 4.12.3.
@spuxx1701 I figured out why this occurs. Both v1 and v2 of babel-plugin-ember-template-compilation were present in my package-lock.json (v1 is a dependency of @embroider/core). Adding an override in my package.json to force v2 has fixed the error.
@veelci just out of curiosity what version of ember-template-imports are you using and are the reports acurate (lines in the correct places etc.) ?
Also I assume it's a classic app build right?
Can you maybe provide an example of a .gjs component and it's report?
@vstefanovic97 I'm using ember-template-imports 3.4.2 w/ a classic build. After closer inspection, there reports are missing for .gjs components. However, running ember test with COVERAGE=true no longer fails.
@veelci yeah it was weird for me when you said .gjs coverage was working because of all the thing I listed that need to be done for the coverage to work properly.
But I'm working on a PR to get the coverage working hope to have it around next week
Activity
veelci commentedon Oct 18, 2023
@spuxx1701 I have 2 non-typescript projects on ember 4.12 and I'm running into this issue as well in one of the projects.
I've aligned the dependencies and configuration of both projects to be the same, so I'm not entirely sure what the issue is. The only thing that is different between the working and non-working project is that I migrated all of the files to
.gjsat once in the working project.Edit: I went back to the working project and added a few non-
.gjscomponents and the tests still ran with coverage enabled.vstefanovic97 commentedon Jan 23, 2024
Hi, I've been trying to get
.gjs/.gtscoverage working for a few days, I've done some digging and I think I've Identified the steps to get this working.So there are a couple of things needed.
.gjs/.gtsextension tobabel-plugin-istanbul's extension options (this is just so that it recognizes and instruments these files).content-tagBasically the code is first getting transpiled by
content-tagfromgjs/gtstots/jsand after that it is running through babel where the instrumentation happens, BUT when we transpile it withcontent-tagright now it doesn't generate source maps which are actually needed to map the transpiled code back to the originalgjs/gtscode, w/o this coverage lines will be off also it will report on some function that don't exist in the source code.Created issues for this:
[Feature request] source map generation embroider-build/content-tag#61
inputSourceMapthat we get from step 2.This last step basically means we need to add some additional functionality to
ember-cli-code-coverage, after that in theory it should work (I will work on this and try to make a PR, also will raise a separate issue for this part)veelci commentedon Jan 24, 2024
@vstefanovic97 I have
.gjscode coverage working in one of my projects. I just have no idea why it works in one project and not the other two projects. All of the projects are on Ember 4.12.3.veelci commentedon Jan 24, 2024
@spuxx1701 I figured out why this occurs. Both v1 and v2 of
babel-plugin-ember-template-compilationwere present in mypackage-lock.json(v1 is a dependency of @embroider/core). Adding an override in mypackage.jsonto force v2 has fixed the error.vstefanovic97 commentedon Jan 24, 2024
@veelci just out of curiosity what version of
ember-template-importsare you using and are the reports acurate (lines in the correct places etc.) ?Also I assume it's a classic app build right?
Can you maybe provide an example of a
.gjscomponent and it's report?veelci commentedon Jan 25, 2024
@vstefanovic97 I'm using ember-template-imports
3.4.2w/ a classic build. After closer inspection, there reports are missing for.gjscomponents. However, runningember testwithCOVERAGE=trueno longer fails.vstefanovic97 commentedon Jan 25, 2024
@veelci yeah it was weird for me when you said
.gjscoverage was working because of all the thing I listed that need to be done for the coverage to work properly.But I'm working on a PR to get the coverage working hope to have it around next week
vstefanovic97 commentedon Jan 29, 2024
I made a PR #405 which should make it work
vstefanovic97 commentedon Feb 22, 2024
#405 has been merged and release in
2.1.0@veelci, @spuxx1701 mind trying it out and see if it works for you guys?veelci commentedon Feb 22, 2024
I haven't tried 2.1.0, but 2.1.1 works for me for both classic and embroider builds.
vstefanovic97 commentedon Feb 22, 2024
That is great to hear @veelci.
@spuxx1701 can you try and then close the issue if all good?
spuxx-dev commentedon Feb 26, 2024
Tested again with
2.1.1and it appears to work. Thanks!