Skip to content
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: Map lines for script block #516

Merged
merged 1 commit into from Dec 11, 2022
Merged

fix: Map lines for script block #516

merged 1 commit into from Dec 11, 2022

Conversation

wolfgangwalther
Copy link
Contributor

I'm using vue2-jest and code coverage is broken for a while now. I noticed a difference between processScript in vue2-jest vs. vue3-jest:

vue2-jest:

function processScript(scriptPart, filePath, config) {
if (!scriptPart) {
return null
}
let externalSrc = null
if (scriptPart.src) {
scriptPart.content = loadSrc(scriptPart.src, filePath)
externalSrc = scriptPart.content
}
const vueJestConfig = getVueJestConfig(config)
const transformer = resolveTransformer(scriptPart.lang, vueJestConfig)
const result = transformer.process(scriptPart.content, filePath, config)
result.code = stripInlineSourceMap(result.code)
result.externalSrc = externalSrc
return result
}

vue3-jest:

function processScript(scriptPart, filePath, config) {
if (!scriptPart) {
return null
}
let content = scriptPart.content
let filename = filePath
if (scriptPart.src) {
content = loadSrc(scriptPart.src, filePath)
filename = scriptPart.src
}
const vueJestConfig = getVueJestConfig(config)
const transformer = resolveTransformer(scriptPart.lang, vueJestConfig)
const result = transformer.process(content, filename, config)
result.code = stripInlineSourceMap(result.code)
result.map = mapLines(scriptPart.map, result.map)
return result
}

The call to mapLines is missing for vue2-jest.

Adding the call, I can see two differences in the tests:

  • The changed snapshot in the diff. Previously the <template> and <style> block didn't show up at all in the html coverage output. Now they do.
  • Looking for example at the e2e/2.x/basic/coverage/lcov-report/basic/components/TemplateString.vue.html file, I see the covered lines now to be in the script block as expected. Before this change they were put somewhere on the template block, which didn't make sense.

The change also made code coverage in my repo work properly again, at least I think so from the output I get.

Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
@lmiller1990
Copy link
Member

Seems fine, thanks!

@lmiller1990 lmiller1990 merged commit 33daf44 into vuejs:master Dec 11, 2022
@lmiller1990
Copy link
Member

It's out in 29.2.2. https://github.com/vuejs/vue-jest/releases/tag/v29.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants