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

feat: type check vue files #239

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions e2e/__projects__/basic/components/TsWithError.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div />
</template>

<script lang="ts">
export default {
created() {
const s: string = {}
}
}
</script>
5 changes: 3 additions & 2 deletions e2e/__projects__/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-vue-jsx": "^3.7.0",
"jest": "^24.0.0",
"vue-jest": "file:../../../"
"vue-jest": "../../../"
},
"jest": {
"moduleFileExtensions": [
Expand All @@ -29,13 +29,14 @@
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue-jest"
"^.+\\.vue$": "../../../"
},
"moduleNameMapper": {
"^~?__styles/(.*)$": "<rootDir>/components/styles/$1"
},
"globals": {
"vue-jest": {
"enableExperimentalTsDiagnostics": true,
"pug": {
"basedir": "./"
}
Expand Down
29 changes: 27 additions & 2 deletions e2e/__projects__/basic/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { mount } from '@vue/test-utils'
import TypeScript from './components/TypeScript.vue'
import { resolve } from 'path'
import { readFileSync } from 'fs'
import jestVue from 'vue-jest'

import jestVue from '../../../'
import TypeScript from './components/TypeScript.vue'
import RenderFunction from './components/RenderFunction.vue'
import Jade from './components/Jade.vue'
import FunctionalSFC from './components/FunctionalSFC.vue'
Expand All @@ -18,6 +19,30 @@ import PugRelative from './components/PugRelativeExtends.vue'
import Jsx from './components/Jsx.vue'
import Constructor from './components/Constructor.vue'

const originalWarn = console.warn
afterEach(() => (console.warn = originalWarn))
let consoleOutput = []
const mockedWarn = output => consoleOutput.push(output)
beforeEach(() => (console.warn = mockedWarn))

test('shows ts diagnostic errors', () => {
const filePath = resolve(__dirname, './components/TsWithError.vue')
const fileString = readFileSync(filePath, { encoding: 'utf8' })

jestVue.process(fileString, filePath, {
moduleFileExtensions: ['js', 'vue', 'ts'],
globals: {
'vue-jest': {
enableExperimentalTsDiagnostics: true
}
}
})

expect(consoleOutput[0]).toContain(
`TsWithError.vue (8,11): Type '{}' is not assignable to type 'string'`
)
})

test('processes .vue files', () => {
const wrapper = mount(Basic)
expect(wrapper.vm.msg).toEqual('Welcome to Your Vue.js App')
Expand Down
Loading