swc
swc copied to clipboard
Coverage reports include <<jsx-config-pragma.js>>, causing errors
looks like this is still an issue in 1.2.198. for me it causes problems when generating lcov reports from test runs with @swc/jest. my config looks like this:
"^.+\\.(t|j)s$": ["@swc/jest", {
sourceMaps: "inline",
module: {
strict: false,
strictMode: false
},
jsc: {
target: "es5",
parser: {
syntax: "typescript",
dynamicImport: true
}
}
}]
the lcov.info file ends with this:
SF:source\core\asyncCore\actions\<<jsx-config-pragma.js>>
FNF:0
FNH:0
DA:1,1
LF:1
LH:1
BRF:0
BRH:0
end_of_record
and the coverage report fails with
Error: ENOENT: no such file or directory, open 'C:\project\packages\my-package\test-results\lcov-report\core\asyncCore\actions\<<jsx-config-pragma.js>>.html'
at Object.openSync (node:fs:585:3)
at FileWriter.writeFile (C:\project\node_modules\.pnpm\[email protected]\node_modules\istanbul-lib-report\lib\file-writer.js:185:41)
at HtmlReport.onDetail (C:\project\node_modules\.pnpm\[email protected]\node_modules\istanbul-reports\lib\html\index.js:411:44)
at LcovReport.<computed> [as onDetail] (C:\project\node_modules\.pnpm\[email protected]\node_modules\istanbul-reports\lib\lcov\index.js:28:23)
at Visitor.value (C:\project\node_modules\.pnpm\[email protected]\node_modules\istanbul-lib-report\lib\tree.js:38:38)
at ReportNode.visit (C:\project\node_modules\.pnpm\[email protected]\node_modules\istanbul-lib-report\lib\tree.js:88:21)
at C:\project\node_modules\.pnpm\[email protected]\node_modules\istanbul-lib-report\lib\tree.js:92:19
at Array.forEach (<anonymous>)
at ReportNode.visit (C:\project\node_modules\.pnpm\[email protected]\node_modules\istanbul-lib-report\lib\tree.js:91:28)
at C:\project\node_modules\.pnpm\[email protected]\node_modules\istanbul-lib-report\lib\tree.js:92:19
unfortunately i don't have the option to switch to es2021 because lots of tests fail then (i'm not exactly sure why, probably related to some patched polyfill that won't initialize on that target...)
i found a bit more details in the cobertura report (which is also broken because of these <<jsx-config-pragma.js>> references). it seems that the coverage reporters really see that file in some directories, not all. the rest of the files of those directories are reported fine, but it still creates a report entry for those weird files too:
<class name="<<jsx-config-pragma.js>>" filename="source\core\asyncCore\actions\<<jsx-config-pragma.js>>" line-rate="1" branch-rate="1">
<methods>
</methods>
<lines>
<line number="1" hits="1" branch="false"/>
</lines>
</class>
edit: excluding this weird file from coverage doesn't work either.
Originally posted by @DerGernTod in https://github.com/swc-project/swc/issues/4691#issuecomment-1191343209
Please post input
which input exactly? unfortunately i can't share the whole project. the input is a few hundred files, so i can hardly find out which ones caused it. there's also no index file in source/core/asyncCore/actions. can you give me instructions on how i could narrow this down? maybe i can build a reproducer repo if i can find out what causes it
Maybe a file with jsx pragma?
(Not sure as I'm on mobile atm)
i don't have any jsx in this project, that's the fun thing 😅
took a wild guess and managed to build a tiny reproducer, looks like it's related to classes?
https://github.com/DerGernTod/swc-jsx-pragma
Thank you!
@DerGernTod I failed to reproduce using @swc/cli
, and your swc config is wrong because it does not have module.type
i updated the config to use module.type="commonjs"
, but still the same problem. i just ran npm run test
which runs jest with coverage. the <<jsx-config-pragma.js>>
entries can be found in test-results/cobertura-coverage.xml
(where they cause issues)
Oh, thanks! I'll retry it
@kdy1 did you have time to take a look yet? or any suggestions where in the code i could check? i'm not very familiar with rust but well, may be worth a try 😅
I'm busy.
https://github.com/swc-project/swc/blob/c619007841381f05d8b9abbbf79d8e0d7b74e86e/crates/swc/src/lib.rs#L608-L614 being not applied is a cause, but I don't know the reason.
thanks a lot, i'll see if i find time to dig into this
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.