From 553e90c59d6a316a4508785533a6b377f9af5e40 Mon Sep 17 00:00:00 2001 From: xiaohulu Date: Wed, 10 Mar 2021 21:22:24 +0800 Subject: [PATCH 1/3] feat: add support for specific tsconfig file path inside of vue-jest jest.config.js options (#309) --- e2e/__projects__/typescript/package.json | 39 +++++++++++++++ .../sub-project/components/Basic.vue | 48 +++++++++++++++++++ .../typescript/sub-project/test.js | 23 +++++++++ .../typescript/sub-project/tsconfig.json | 20 ++++++++ lib/utils.js | 6 ++- 5 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 e2e/__projects__/typescript/package.json create mode 100644 e2e/__projects__/typescript/sub-project/components/Basic.vue create mode 100644 e2e/__projects__/typescript/sub-project/test.js create mode 100644 e2e/__projects__/typescript/sub-project/tsconfig.json diff --git a/e2e/__projects__/typescript/package.json b/e2e/__projects__/typescript/package.json new file mode 100644 index 00000000..da086ac0 --- /dev/null +++ b/e2e/__projects__/typescript/package.json @@ -0,0 +1,39 @@ +{ + "name": "javascript", + "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..1dbd83b0 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(), + config.globals?.['vue-jest']?.tsConfig ?? '' + ) + const isUsingTs = resolveTsConfigSync(tsConfigPath) if (!isUsingTs) { return null } From 73c79d299c0aa4c19411e655e5078bee29aa604e Mon Sep 17 00:00:00 2001 From: xiaohulu Date: Wed, 10 Mar 2021 21:26:11 +0800 Subject: [PATCH 2/3] chore: modify package name property --- e2e/__projects__/typescript/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/__projects__/typescript/package.json b/e2e/__projects__/typescript/package.json index da086ac0..d69db841 100644 --- a/e2e/__projects__/typescript/package.json +++ b/e2e/__projects__/typescript/package.json @@ -1,5 +1,5 @@ { - "name": "javascript", + "name": "typescript", "version": "1.0.0", "main": "index.js", "license": "MIT", From 3f857daac7dc8d76ae6d47820851b1262907ab7e Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Mon, 29 Mar 2021 10:50:01 +0900 Subject: [PATCH 3/3] style: avoid use Optional Chaining --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 1dbd83b0..2949ed21 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -67,7 +67,7 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) { const getTsJestConfig = function getTsJestConfig(config) { const tsConfigPath = path.resolve( process.cwd(), - config.globals?.['vue-jest']?.tsConfig ?? '' + getVueJestConfig(config).tsConfig || '' ) const isUsingTs = resolveTsConfigSync(tsConfigPath) if (!isUsingTs) {