Skip to content

Commit

Permalink
Fix coverage reports for typescript for vue3 (#331)
Browse files Browse the repository at this point in the history
* Fix coverage reports for typescript

* Add unit test for TsSrc
  • Loading branch information
jolting authored Apr 6, 2021
1 parent acab463 commit af80ab0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
23 changes: 23 additions & 0 deletions e2e/__projects__/basic/components/TsSrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default {
name: 'basic',
computed: {
headingClasses: function headingClasses() {
return {
red: this.isCrazy,
blue: !this.isCrazy,
shadow: this.isCrazy
}
}
},
data: function data() {
return {
msg: 'Welcome to Your Vue.js App',
isCrazy: false
}
},
methods: {
toggleClass: function toggleClass() {
this.isCrazy = !this.isCrazy
}
}
}
3 changes: 3 additions & 0 deletions e2e/__projects__/basic/components/TsSrc.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template src="./BasicSrc.html"></template>

<script lang="ts" src="./TsSrc.ts"></script>
10 changes: 9 additions & 1 deletion e2e/__projects__/basic/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolve } from 'path'
import { readFileSync } from 'fs'

import BasicSrc from './components/BasicSrc.vue'
import TsSrc from './components/TsSrc.vue'
import Pug from './components/Pug.vue'
import Coffee from './components/Coffee.vue'
import Basic from './components/Basic.vue'
Expand Down Expand Up @@ -47,13 +48,20 @@ test('processes .vue files', () => {
)
})

test('processes .vue files with src attributes', () => {
test('processes .vue files with js src attributes', () => {
mount(BasicSrc)
expect(document.querySelector('h1').textContent).toBe(
'Welcome to Your Vue.js App'
)
})

test('processes .vue files with ts src attributes', () => {
mount(TsSrc)
expect(document.querySelector('h1').textContent).toBe(
'Welcome to Your Vue.js App'
)
})

test('handles named exports', () => {
expect(randomExport).toEqual(42)
})
Expand Down
5 changes: 4 additions & 1 deletion lib/transformers/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module.exports = {
const tsconfig = getTsJestConfig(config)
const babelOptions = getBabelOptions(filePath)

const res = typescript.transpileModule(scriptContent, tsconfig)
const res = typescript.transpileModule(scriptContent, {
...tsconfig,
fileName: filePath
})

res.outputText = stripInlineSourceMap(res.outputText)

Expand Down

0 comments on commit af80ab0

Please sign in to comment.