Skip to content

feat: add support for specific tsconfig file path inside of vue-jest jest.config.js options #324

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

Merged
merged 3 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
39 changes: 39 additions & 0 deletions e2e/__projects__/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "typescript",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"scripts": {
"test": "jest --no-cache ./sub-project/test.js"
},
"dependencies": {
"vue": "3.0.0-alpha.10"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"jest": "^24.0.0"
},
"jest": {
"globals": {
"vue-jest": {
"tsConfig": "./sub-project/tsconfig.json"
}
},
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "../../../lib/index.js"
}
},
"babel": {
"presets": [
"@babel/env"
]
}
}
48 changes: 48 additions & 0 deletions e2e/__projects__/typescript/sub-project/components/Basic.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<div class="hello">
<h1 :class="headingClasses">{{ msg }}</h1>
</div>
</template>

<style module="css">
.testA {
background-color: red;
}
</style>
<style module>
.testB {
background-color: blue;
}
</style>
<style>
.testC {
background-color: blue;
}
</style>

<script lang="ts">
export default {
name: 'basic',
computed: {
headingClasses: function headingClasses() {
return {
red: this.isCrazy,
blue: !this.isCrazy,
shadow: this.isCrazy
}
}
},
data: function data() {
const msg: string = 'Welcome to Your Vue.js App'
return {
msg,
isCrazy: false
}
},
methods: {
toggleClass: function toggleClass() {
this.isCrazy = !this.isCrazy
}
}
}
</script>
23 changes: 23 additions & 0 deletions e2e/__projects__/typescript/sub-project/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createApp, h } from 'vue'

import Basic from './components/Basic.vue'

function mount(Component, props, slots) {
document.getElementsByTagName('html')[0].innerHTML = ''
const el = document.createElement('div')
el.id = 'app'
document.body.appendChild(el)
const Parent = {
render() {
return h(Component, props, slots)
}
}
createApp(Parent).mount(el)
}

test('processes .vue files', () => {
mount(Basic)
expect(document.querySelector('h1').textContent).toBe(
'Welcome to Your Vue.js App'
)
})
20 changes: 20 additions & 0 deletions e2e/__projects__/typescript/sub-project/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "es6"],
"module": "es2015",
"moduleResolution": "node",
"types": ["vue-typescript-import-dts", "node"],
"isolatedModules": false,
"experimentalDecorators": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"allowJs": true
}
}
6 changes: 5 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) {
}

const getTsJestConfig = function getTsJestConfig(config) {
const isUsingTs = resolveTsConfigSync(process.cwd())
const tsConfigPath = path.resolve(
process.cwd(),
config.globals?.['vue-jest']?.tsConfig ?? ''
)
const isUsingTs = resolveTsConfigSync(tsConfigPath)
if (!isUsingTs) {
return null
}
Expand Down