From 6f150deb5f04167124a1c726dea9476d4fd86d09 Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Wed, 11 May 2022 08:44:18 +0900 Subject: [PATCH 1/8] chore(deps): add `tsconfig` package on @vue/vue2-jest --- packages/vue2-jest/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/vue2-jest/package.json b/packages/vue2-jest/package.json index 12e70bfc..6d1a9f7d 100644 --- a/packages/vue2-jest/package.json +++ b/packages/vue2-jest/package.json @@ -55,7 +55,8 @@ "@vue/component-compiler-utils": "^3.1.0", "chalk": "^2.1.0", "css-tree": "^2.0.1", - "source-map": "0.5.6" + "source-map": "0.5.6", + "tsconfig": "^7.0.0" }, "repository": { "type": "git", From 44b3afb4e6e22f2f410f3309fdaaad4c8929b776 Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Wed, 11 May 2022 09:34:49 +0900 Subject: [PATCH 2/8] feat: add `getTypeScriptConfig` util function --- packages/vue2-jest/lib/utils.js | 22 ++++++++++++++++++++++ packages/vue3-jest/lib/utils.js | 27 ++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/vue2-jest/lib/utils.js b/packages/vue2-jest/lib/utils.js index db58d806..ed81ced9 100644 --- a/packages/vue2-jest/lib/utils.js +++ b/packages/vue2-jest/lib/utils.js @@ -1,5 +1,6 @@ const constants = require('./constants') const loadPartialConfig = require('@babel/core').loadPartialConfig +const { loadSync: loadTsConfigSync } = require('tsconfig') const chalk = require('chalk') const path = require('path') const fs = require('fs') @@ -76,6 +77,26 @@ const getTsJestConfig = function getTsJestConfig(config) { } } +/** + * Load TypeScript config from tsconfig.json. + * @param {string | undefined} path tsconfig.json file path (default: root) + * @returns {import('typescript').TranspileOptions | null} TypeScript compilerOptions or null + */ +const getTypeScriptConfig = function getTypeScriptConfig(path) { + const tsconfig = loadTsConfigSync(process.cwd(), path || '') + if (!tsconfig.path) { + info(`Not found tsconfig.json.`) + return null + } + info(`Loaded TypeScript config from "${tsconfig.path}".`) + const compilerOptions = + (tsconfig.config && tsconfig.config.compilerOptions) || {} + + return { + compilerOptions: { ...compilerOptions, module: 'commonjs' } + } +} + function isValidTransformer(transformer) { return ( isFunction(transformer.process) || @@ -153,6 +174,7 @@ module.exports = { logResultErrors, getCustomTransformer, getTsJestConfig, + getTypeScriptConfig, getBabelOptions, getVueJestConfig, transformContent, diff --git a/packages/vue3-jest/lib/utils.js b/packages/vue3-jest/lib/utils.js index e55dfe1c..2db4a577 100644 --- a/packages/vue3-jest/lib/utils.js +++ b/packages/vue3-jest/lib/utils.js @@ -1,6 +1,9 @@ const constants = require('./constants') const loadPartialConfig = require('@babel/core').loadPartialConfig -const { resolveSync: resolveTsConfigSync } = require('tsconfig') +const { + loadSync: loadTsConfigSync, + resolveSync: resolveTsConfigSync +} = require('tsconfig') const chalk = require('chalk') const path = require('path') const fs = require('fs') @@ -84,6 +87,27 @@ const getTsJestConfig = function getTsJestConfig(config) { } } +/** + * Load TypeScript config from tsconfig.json. + * @param {string | undefined} path tsconfig.json file path (default: root) + * @returns {import('typescript').TranspileOptions | null} TypeScript compilerOptions or null + */ +const getTypeScriptConfig = function getTypeScriptConfig(path) { + const tsconfig = loadTsConfigSync(process.cwd(), path || '') + if (!tsconfig.path) { + info(`Not found tsconfig.json.`) + return null + } + info(`Loaded TypeScript config from "${tsconfig.path}".`) + const compilerOptions = + (tsconfig.config && tsconfig.config.compilerOptions) || {} + + // Force es5 to prevent const vue_1 = require('vue') from conflicting + return { + compilerOptions: { ...compilerOptions, target: 'es5', module: 'commonjs' } + } +} + function isValidTransformer(transformer) { return ( isFunction(transformer.process) || @@ -162,6 +186,7 @@ module.exports = { logResultErrors, getCustomTransformer, getTsJestConfig, + getTypeScriptConfig, getBabelOptions, getVueJestConfig, transformContent, From 8cbf401b4f687f0da4f1fea54308a7eaa961f823 Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Wed, 11 May 2022 09:42:26 +0900 Subject: [PATCH 3/8] feat: use `getTypeScriptConfig` on typescript transformer --- packages/vue2-jest/lib/transformers/typescript.js | 4 ++-- packages/vue3-jest/lib/process.js | 4 ++-- packages/vue3-jest/lib/transformers/typescript.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/vue2-jest/lib/transformers/typescript.js b/packages/vue2-jest/lib/transformers/typescript.js index 22f6b3b9..18be5f41 100644 --- a/packages/vue2-jest/lib/transformers/typescript.js +++ b/packages/vue2-jest/lib/transformers/typescript.js @@ -1,9 +1,9 @@ const ensureRequire = require('../ensure-require') const babelJest = require('babel-jest').default const { - getTsJestConfig, stripInlineSourceMap, getCustomTransformer, + getTypeScriptConfig, getVueJestConfig } = require('../utils') @@ -12,7 +12,7 @@ module.exports = scriptLang => ({ ensureRequire('typescript', ['typescript']) const typescript = require('typescript') const vueJestConfig = getVueJestConfig(config) - const tsconfig = getTsJestConfig(config) + const tsconfig = getTypeScriptConfig(vueJestConfig.tsConfig) const res = typescript.transpileModule(scriptContent, { ...tsconfig, diff --git a/packages/vue3-jest/lib/process.js b/packages/vue3-jest/lib/process.js index 91c56e48..735546a1 100644 --- a/packages/vue3-jest/lib/process.js +++ b/packages/vue3-jest/lib/process.js @@ -6,8 +6,8 @@ const typescriptTransformer = require('./transformers/typescript') const coffeescriptTransformer = require('./transformers/coffee') const _processStyle = require('./process-style') const processCustomBlocks = require('./process-custom-blocks') +const getTypeScriptConfig = require('./utils').getTypeScriptConfig const getVueJestConfig = require('./utils').getVueJestConfig -const getTsJestConfig = require('./utils').getTsJestConfig const logResultErrors = require('./utils').logResultErrors const stripInlineSourceMap = require('./utils').stripInlineSourceMap const getCustomTransformer = require('./utils').getCustomTransformer @@ -118,7 +118,7 @@ function processTemplate(descriptor, filename, config) { logResultErrors(result) - const tsconfig = getTsJestConfig(config) + const tsconfig = getTypeScriptConfig(vueJestConfig.tsConfig) if (tsconfig) { // they are using TypeScript. diff --git a/packages/vue3-jest/lib/transformers/typescript.js b/packages/vue3-jest/lib/transformers/typescript.js index 275cc75f..e59a2429 100644 --- a/packages/vue3-jest/lib/transformers/typescript.js +++ b/packages/vue3-jest/lib/transformers/typescript.js @@ -1,9 +1,9 @@ const ensureRequire = require('../ensure-require') const babelJest = require('babel-jest').default const { - getTsJestConfig, stripInlineSourceMap, getCustomTransformer, + getTypeScriptConfig, getVueJestConfig } = require('../utils') @@ -12,7 +12,7 @@ module.exports = { ensureRequire('typescript', ['typescript']) const typescript = require('typescript') const vueJestConfig = getVueJestConfig(config) - const tsconfig = getTsJestConfig(config) + const tsconfig = getTypeScriptConfig(vueJestConfig.tsConfig) const res = typescript.transpileModule(scriptContent, { ...tsconfig, From d409559f0bf7ca58085d498da994c1ed8aecd7f8 Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Wed, 11 May 2022 09:49:39 +0900 Subject: [PATCH 4/8] feat: remove `getTsJestConfig` function --- packages/vue2-jest/lib/utils.js | 10 ---------- packages/vue3-jest/lib/utils.js | 22 +--------------------- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/packages/vue2-jest/lib/utils.js b/packages/vue2-jest/lib/utils.js index ed81ced9..9a1f714c 100644 --- a/packages/vue2-jest/lib/utils.js +++ b/packages/vue2-jest/lib/utils.js @@ -68,15 +68,6 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) { return loadPartialConfig(opts).options } -const getTsJestConfig = function getTsJestConfig(config) { - const { ConfigSet } = require('ts-jest/dist/legacy/config/config-set') - const configSet = new ConfigSet(config.config) - var tsConfig = configSet.typescript || configSet.parsedTsConfig - return { - compilerOptions: { ...tsConfig.options, module: 'commonjs' } - } -} - /** * Load TypeScript config from tsconfig.json. * @param {string | undefined} path tsconfig.json file path (default: root) @@ -173,7 +164,6 @@ module.exports = { throwError, logResultErrors, getCustomTransformer, - getTsJestConfig, getTypeScriptConfig, getBabelOptions, getVueJestConfig, diff --git a/packages/vue3-jest/lib/utils.js b/packages/vue3-jest/lib/utils.js index 2db4a577..37403cd2 100644 --- a/packages/vue3-jest/lib/utils.js +++ b/packages/vue3-jest/lib/utils.js @@ -1,9 +1,6 @@ const constants = require('./constants') const loadPartialConfig = require('@babel/core').loadPartialConfig -const { - loadSync: loadTsConfigSync, - resolveSync: resolveTsConfigSync -} = require('tsconfig') +const { loadSync: loadTsConfigSync } = require('tsconfig') const chalk = require('chalk') const path = require('path') const fs = require('fs') @@ -71,22 +68,6 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) { return loadPartialConfig(opts).options } -const getTsJestConfig = function getTsJestConfig(config) { - const tsConfigPath = getVueJestConfig(config).tsConfig || '' - const isUsingTs = resolveTsConfigSync(process.cwd(), tsConfigPath) - if (!isUsingTs) { - return null - } - - const { ConfigSet } = require('ts-jest/dist/legacy/config/config-set') - const configSet = new ConfigSet(config.config) - const tsConfig = configSet.typescript || configSet.parsedTsConfig - // Force es5 to prevent const vue_1 = require('vue') from conflicting - return { - compilerOptions: { ...tsConfig.options, target: 'es5', module: 'commonjs' } - } -} - /** * Load TypeScript config from tsconfig.json. * @param {string | undefined} path tsconfig.json file path (default: root) @@ -185,7 +166,6 @@ module.exports = { throwError, logResultErrors, getCustomTransformer, - getTsJestConfig, getTypeScriptConfig, getBabelOptions, getVueJestConfig, From 9a3a82f2adea2308c9708ff28741ccf03c71e3b6 Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Wed, 11 May 2022 11:35:31 +0900 Subject: [PATCH 5/8] chore(deps): remove ts-jest dependencies --- packages/vue2-jest/package.json | 5 ++--- packages/vue3-jest/package.json | 5 ----- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/vue2-jest/package.json b/packages/vue2-jest/package.json index 6d1a9f7d..be74843a 100644 --- a/packages/vue2-jest/package.json +++ b/packages/vue2-jest/package.json @@ -32,7 +32,6 @@ "conventional-changelog": "^1.1.5", "jest": "^28.0.2", "semantic-release": "^15.13.2", - "ts-jest": "^28.0.1", "typescript": "^4.6.4", "vue": "^2.4.2", "vue-template-compiler": "^2.4.2" @@ -41,12 +40,12 @@ "@babel/core": "7.x", "babel-jest": ">= 28 < 29", "jest": "28.x", - "ts-jest": ">= 28 < 29", + "typescript": ">= 4.3", "vue": "^2.x", "vue-template-compiler": "^2.x" }, "peerDependenciesMeta": { - "ts-jest": { + "typescript": { "optional": true } }, diff --git a/packages/vue3-jest/package.json b/packages/vue3-jest/package.json index 613dbe04..2126c714 100644 --- a/packages/vue3-jest/package.json +++ b/packages/vue3-jest/package.json @@ -31,7 +31,6 @@ "jest": "^28.0.2", "jest-cli": "^28.0.2", "semantic-release": "^15.13.2", - "ts-jest": "^28.0.1", "typescript": "^4.6.4", "vue": "^3.2.22" }, @@ -39,14 +38,10 @@ "@babel/core": "7.x", "babel-jest": "28.x", "jest": "28.x", - "ts-jest": "28.x", "typescript": ">= 4.3", "vue": "^3.0.0-0" }, "peerDependenciesMeta": { - "ts-jest": { - "optional": true - }, "typescript": { "optional": true } From 207fd53d96507267d3c94cd177d546fa4471daaf Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Wed, 11 May 2022 11:42:37 +0900 Subject: [PATCH 6/8] chore(deps-dev): remove ts-jest from e2e projects --- e2e/2.x/babel-in-package/package.json | 1 - e2e/2.x/basic/package.json | 5 ++--- e2e/3.x/babel-in-package/package.json | 4 ++-- e2e/3.x/basic/package.json | 2 +- e2e/3.x/typescript-with-babel/package.json | 5 ++--- e2e/3.x/typescript-with-compiler-options/package.json | 4 ++-- e2e/3.x/typescript/package.json | 4 ++-- 7 files changed, 11 insertions(+), 14 deletions(-) diff --git a/e2e/2.x/babel-in-package/package.json b/e2e/2.x/babel-in-package/package.json index e0a47850..9b96294f 100644 --- a/e2e/2.x/babel-in-package/package.json +++ b/e2e/2.x/babel-in-package/package.json @@ -20,7 +20,6 @@ "coffeescript": "^2.3.2", "jest": "28.x", "jest-environment-jsdom": "28.0.2", - "ts-jest": "^28.0.1", "typescript": "^4.6.4" }, "jest": { diff --git a/e2e/2.x/basic/package.json b/e2e/2.x/basic/package.json index 569e29da..d8178e49 100644 --- a/e2e/2.x/basic/package.json +++ b/e2e/2.x/basic/package.json @@ -14,6 +14,7 @@ "@babel/core": "^7.9.0", "@babel/preset-env": "^7.9.0", "@vue/test-utils": "^1.1.0", + "@vue/vue2-jest": "^28.0.0", "babel-helper-vue-jsx-merge-props": "^2.0.3", "babel-plugin-syntax-jsx": "^6.18.0", "babel-plugin-transform-vue-jsx": "^3.7.0", @@ -23,9 +24,7 @@ "jest-environment-jsdom": "28.0.2", "pug": "^3.0.1", "sass": "^1.23.7", - "ts-jest": "^28.0.1", - "typescript": "^4.6.4", - "@vue/vue2-jest": "^28.0.0" + "typescript": "^4.6.4" }, "jest": { "testEnvironment": "jsdom", diff --git a/e2e/3.x/babel-in-package/package.json b/e2e/3.x/babel-in-package/package.json index 28649315..839bb49a 100644 --- a/e2e/3.x/babel-in-package/package.json +++ b/e2e/3.x/babel-in-package/package.json @@ -12,12 +12,12 @@ "devDependencies": { "@babel/core": "^7.9.0", "@babel/preset-env": "^7.9.0", + "@vue/vue3-jest": "^28.0.0", "coffeescript": "^2.3.2", "jest": "^28.0.0", "jest-environment-jsdom": "28.0.2", "ts-jest": "^28.0.1", - "typescript": "^4.6.4", - "@vue/vue3-jest": "^28.0.0" + "typescript": "^4.6.4" }, "jest": { "testEnvironment": "jsdom", diff --git a/e2e/3.x/basic/package.json b/e2e/3.x/basic/package.json index 58a31566..641cdf3e 100644 --- a/e2e/3.x/basic/package.json +++ b/e2e/3.x/basic/package.json @@ -12,6 +12,7 @@ "devDependencies": { "@babel/core": "^7.9.0", "@babel/preset-env": "^7.9.0", + "@vue/vue3-jest": "^28.0.0", "babel-helper-vue-jsx-merge-props": "^2.0.3", "babel-plugin-syntax-jsx": "^6.18.0", "babel-plugin-transform-vue-jsx": "^3.7.0", @@ -23,7 +24,6 @@ "ts-jest": "^28.0.1", "typescript": "^4.6.4", "vue-class-component": "^8.0.0-beta.4", - "@vue/vue3-jest": "^28.0.0", "vue-property-decorator": "^10.0.0-rc.3" } } diff --git a/e2e/3.x/typescript-with-babel/package.json b/e2e/3.x/typescript-with-babel/package.json index 80328ea6..e7ee3657 100644 --- a/e2e/3.x/typescript-with-babel/package.json +++ b/e2e/3.x/typescript-with-babel/package.json @@ -12,11 +12,10 @@ "devDependencies": { "@babel/core": "^7.9.0", "@babel/preset-env": "^7.9.0", + "@vue/vue3-jest": "^28.0.0", "jest": "^28.0.2", "jest-environment-jsdom": "28.0.2", - "ts-jest": "^28.0.1", - "typescript": "^4.6.4", - "@vue/vue3-jest": "^28.0.0" + "typescript": "^4.6.4" }, "jest": { "testEnvironment": "jsdom", diff --git a/e2e/3.x/typescript-with-compiler-options/package.json b/e2e/3.x/typescript-with-compiler-options/package.json index 39c96201..27f56ecb 100644 --- a/e2e/3.x/typescript-with-compiler-options/package.json +++ b/e2e/3.x/typescript-with-compiler-options/package.json @@ -11,11 +11,11 @@ }, "devDependencies": { "@types/jest": "16.0.10", + "@vue/vue3-jest": "^28.0.0", "jest": "^28.0.2", "jest-environment-jsdom": "28.0.2", "ts-jest": "^28.0.1", - "typescript": "^4.6.4", - "@vue/vue3-jest": "^28.0.0" + "typescript": "^4.6.4" }, "jest": { "testEnvironment": "jsdom", diff --git a/e2e/3.x/typescript/package.json b/e2e/3.x/typescript/package.json index 37ef8dec..b3075790 100644 --- a/e2e/3.x/typescript/package.json +++ b/e2e/3.x/typescript/package.json @@ -11,11 +11,11 @@ }, "devDependencies": { "@types/jest": "16.0.10", + "@vue/vue3-jest": "^28.0.0", "jest": "^28.0.2", "jest-environment-jsdom": "28.0.2", "ts-jest": "^28.0.1", - "typescript": "^4.6.4", - "@vue/vue3-jest": "^28.0.0" + "typescript": "^4.6.4" }, "jest": { "testEnvironment": "jsdom", From ac0884f98b0f0efd9ea6003cdcf05461af48fae6 Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Wed, 11 May 2022 11:45:17 +0900 Subject: [PATCH 7/8] feat: remove info log --- packages/vue2-jest/lib/utils.js | 3 +-- packages/vue3-jest/lib/utils.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/vue2-jest/lib/utils.js b/packages/vue2-jest/lib/utils.js index 9a1f714c..86563878 100644 --- a/packages/vue2-jest/lib/utils.js +++ b/packages/vue2-jest/lib/utils.js @@ -76,10 +76,9 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) { const getTypeScriptConfig = function getTypeScriptConfig(path) { const tsconfig = loadTsConfigSync(process.cwd(), path || '') if (!tsconfig.path) { - info(`Not found tsconfig.json.`) + warn(`Not found tsconfig.json.`) return null } - info(`Loaded TypeScript config from "${tsconfig.path}".`) const compilerOptions = (tsconfig.config && tsconfig.config.compilerOptions) || {} diff --git a/packages/vue3-jest/lib/utils.js b/packages/vue3-jest/lib/utils.js index 37403cd2..1cbd4bcf 100644 --- a/packages/vue3-jest/lib/utils.js +++ b/packages/vue3-jest/lib/utils.js @@ -76,10 +76,9 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) { const getTypeScriptConfig = function getTypeScriptConfig(path) { const tsconfig = loadTsConfigSync(process.cwd(), path || '') if (!tsconfig.path) { - info(`Not found tsconfig.json.`) + warn(`Not found tsconfig.json.`) return null } - info(`Loaded TypeScript config from "${tsconfig.path}".`) const compilerOptions = (tsconfig.config && tsconfig.config.compilerOptions) || {} From 83fbdc1f35e60315c0d7ffc8f6c397bc67e4d3ab Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Wed, 11 May 2022 13:03:33 +0900 Subject: [PATCH 8/8] feat: support `createTransformer()` on customTransformer --- packages/vue2-jest/lib/utils.js | 8 +++++--- packages/vue3-jest/lib/utils.js | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/vue2-jest/lib/utils.js b/packages/vue2-jest/lib/utils.js index 86563878..25b8a5fa 100644 --- a/packages/vue2-jest/lib/utils.js +++ b/packages/vue2-jest/lib/utils.js @@ -89,6 +89,7 @@ const getTypeScriptConfig = function getTypeScriptConfig(path) { function isValidTransformer(transformer) { return ( + isFunction(transformer.createTransformer) || isFunction(transformer.process) || isFunction(transformer.postprocess) || isFunction(transformer.preprocess) @@ -121,12 +122,13 @@ const getCustomTransformer = function getCustomTransformer( if (!isValidTransformer(transformer)) { throwError( - `transformer must contain at least one process, preprocess, or ` + - `postprocess method` + `transformer must contain at least one createTransformer(), process(), preprocess(), or postprocess() method` ) } - return transformer + return isFunction(transformer.createTransformer) + ? transformer.createTransformer() + : transformer } const throwError = function error(msg) { diff --git a/packages/vue3-jest/lib/utils.js b/packages/vue3-jest/lib/utils.js index 1cbd4bcf..cbd7fd7a 100644 --- a/packages/vue3-jest/lib/utils.js +++ b/packages/vue3-jest/lib/utils.js @@ -90,6 +90,7 @@ const getTypeScriptConfig = function getTypeScriptConfig(path) { function isValidTransformer(transformer) { return ( + isFunction(transformer.createTransformer) || isFunction(transformer.process) || isFunction(transformer.postprocess) || isFunction(transformer.preprocess) @@ -123,12 +124,13 @@ const getCustomTransformer = function getCustomTransformer( if (!isValidTransformer(transformer)) { throwError( - `transformer must contain at least one process, preprocess, or ` + - `postprocess method` + `transformer must contain at least one createTransformer(), process(), preprocess(), or postprocess() method` ) } - return transformer + return isFunction(transformer.createTransformer) + ? transformer.createTransformer() + : transformer } const throwError = function error(msg) {