jest-transform-svelte
jest-transform-svelte copied to clipboard
Coverage report not showing coverage for `.svelte` files at all
We've setup a default Sapper project using the very instructions straight from their web site, and are now trying to get testing with Jest working. The only difference that we have from the default Sapper template at the moment is that we've configured the project to use Sass for styling using the svelte-preprocessor
library as well. We don't believe this has anything to do with our issue, because we removed the sass from the component, and the sass configuration, and got the same results.
We have tests working, and we can even get a coverage report generated, but the only coverage that is reported is for files with a .js
extension. Our report shows no coverage at all for the one component that we wrote a test for, which is the default src/components/Nav.svelte
component that ships with the project boilerplate.
Below is the contents of our jest.config.js
file, and our package.json
file has a test
task that just runs jest
. Anyone have any idea why our configuration isn't generating any coverage for our .svelte
files? Any help is greatly appreciated, thank you.
// jest.config.js
module.exports = {
'transform': {
'^.+\\.js$': 'babel-jest',
'^.+\\.svelte$': ['jest-transform-svelte', {
preprocess: true
}]
},
'moduleFileExtensions': [
'js',
'json',
'svelte'
],
testMatch: [
'<rootDir>/(src/**/*.spec.js)'
],
'setupFilesAfterEnv': [
'@testing-library/jest-dom/extend-expect'
],
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{js,svelte}'],
coverageReporters: ['html', 'text-summary']
}
Can you check if coverage works for you in jest v24? For me it works, but it doesn't in v25.
@ksewo nice catch, thanks for the heads up on this. That actually does work. We get coverage now with jest 24.9.0, but...it seems to struggle to part the .svelte
files correctly. Not terrible, perhaps better than nothing, but the results are odd.
Notice that it says that only 7/11 branches are covered, but shows no indication of any "branches" of code that were missed, but only highlights the one line as being missed. I dunno, like I said, we're trying to decide if this is better than no coverage at all or not, because it doesn't seem to be very accurate. Understandable, I don't imagine .svelte
files are very easy to parse from a code coverage perspective.
Hi, I'm having the same issue with Jest 27, it won't detect any svelte file at all. Any fix for this other than downgrading to Jest 24?