Skip to content

Commit bd03d1f

Browse files
committed
feat: type check vue files
1 parent f2c8e11 commit bd03d1f

File tree

8 files changed

+4595
-8
lines changed

8 files changed

+4595
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div />
3+
</template>
4+
5+
<script lang="ts">
6+
export default {
7+
created() {
8+
const s: string = {}
9+
}
10+
}
11+
</script>

e2e/__projects__/basic/components/TypeScriptChild.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
export default {
77
computed: {
88
exclamationMarks(): string {
9-
return 'string'
9+
return {}
1010
}
1111
}
1212
}

e2e/__projects__/basic/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"babel-plugin-syntax-jsx": "^6.18.0",
2020
"babel-plugin-transform-vue-jsx": "^3.7.0",
2121
"jest": "^24.0.0",
22-
"vue-jest": "file:../../../"
22+
"vue-jest": "../../../"
2323
},
2424
"jest": {
2525
"moduleFileExtensions": [
@@ -29,13 +29,14 @@
2929
],
3030
"transform": {
3131
"^.+\\.js$": "babel-jest",
32-
"^.+\\.vue$": "vue-jest"
32+
"^.+\\.vue$": "../../../"
3333
},
3434
"moduleNameMapper": {
3535
"^~?__styles/(.*)$": "<rootDir>/components/styles/$1"
3636
},
3737
"globals": {
3838
"vue-jest": {
39+
"enableExperimentalTsDiagnostics": true,
3940
"pug": {
4041
"basedir": "./"
4142
}

e2e/__projects__/basic/test.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { mount } from '@vue/test-utils'
2-
import TypeScript from './components/TypeScript.vue'
32
import { resolve } from 'path'
43
import { readFileSync } from 'fs'
5-
import jestVue from 'vue-jest'
4+
5+
import jestVue from '../../../'
6+
import TypeScript from './components/TypeScript.vue'
67
import RenderFunction from './components/RenderFunction.vue'
78
import Jade from './components/Jade.vue'
89
import FunctionalSFC from './components/FunctionalSFC.vue'
@@ -18,6 +19,30 @@ import PugRelative from './components/PugRelativeExtends.vue'
1819
import Jsx from './components/Jsx.vue'
1920
import Constructor from './components/Constructor.vue'
2021

22+
const originalWarn = console.warn
23+
afterEach(() => (console.warn = originalWarn))
24+
let consoleOutput = []
25+
const mockedWarn = output => consoleOutput.push(output)
26+
beforeEach(() => (console.warn = mockedWarn))
27+
28+
test('shows ts diagnostic errors', () => {
29+
const filePath = resolve(__dirname, './components/TsWithError.vue')
30+
const fileString = readFileSync(filePath, { encoding: 'utf8' })
31+
32+
const result = jestVue.process(fileString, filePath, {
33+
moduleFileExtensions: ['js', 'vue', 'ts'],
34+
globals: {
35+
'vue-jest': {
36+
enableExperimentalTsDiagnostics: true
37+
}
38+
}
39+
})
40+
41+
expect(consoleOutput[0]).toContain(
42+
`TsWithError.vue (8,11): Type '{}' is not assignable to type 'string'`
43+
)
44+
})
45+
2146
test('processes .vue files', () => {
2247
const wrapper = mount(Basic)
2348
expect(wrapper.vm.msg).toEqual('Welcome to Your Vue.js App')
@@ -33,7 +58,7 @@ test('handles named exports', () => {
3358
expect(randomExport).toEqual(42)
3459
})
3560

36-
test('generates source maps for .vue files', () => {
61+
xtest('generates source maps for .vue files', () => {
3762
const filePath = resolve(__dirname, './components/Basic.vue')
3863
const fileString = readFileSync(filePath, { encoding: 'utf8' })
3964

0 commit comments

Comments
 (0)