diff --git a/e2e/__projects__/typescript/package.json b/e2e/__projects__/typescript/package.json new file mode 100644 index 00000000..d69db841 --- /dev/null +++ b/e2e/__projects__/typescript/package.json @@ -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" + ] + } +} diff --git a/e2e/__projects__/typescript/sub-project/components/Basic.vue b/e2e/__projects__/typescript/sub-project/components/Basic.vue new file mode 100644 index 00000000..7e5a8d1f --- /dev/null +++ b/e2e/__projects__/typescript/sub-project/components/Basic.vue @@ -0,0 +1,48 @@ + + + + + + + diff --git a/e2e/__projects__/typescript/sub-project/test.js b/e2e/__projects__/typescript/sub-project/test.js new file mode 100644 index 00000000..e2a326ae --- /dev/null +++ b/e2e/__projects__/typescript/sub-project/test.js @@ -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' + ) +}) diff --git a/e2e/__projects__/typescript/sub-project/tsconfig.json b/e2e/__projects__/typescript/sub-project/tsconfig.json new file mode 100644 index 00000000..8073706e --- /dev/null +++ b/e2e/__projects__/typescript/sub-project/tsconfig.json @@ -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 + } +} diff --git a/lib/utils.js b/lib/utils.js index d7aa05ac..2949ed21 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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(), + getVueJestConfig(config).tsConfig || '' + ) + const isUsingTs = resolveTsConfigSync(tsConfigPath) if (!isUsingTs) { return null }