From 7f2287cf71d0f40f0a53d3e4e3d60604a9b26f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20P=C3=A9rez?= Date: Thu, 15 Sep 2022 02:32:54 +0200 Subject: [PATCH 01/19] feat: support diff --git a/e2e/2.x/basic/package.json b/e2e/2.x/basic/package.json index a657c3ec..152b804c 100644 --- a/e2e/2.x/basic/package.json +++ b/e2e/2.x/basic/package.json @@ -7,8 +7,8 @@ "test": "jest --no-cache --coverage test.js" }, "dependencies": { - "vue": "^2.5.21", - "vue-template-compiler": "^2.5.21" + "vue": "^2.7.7", + "vue-template-compiler": "^2.7.7" }, "devDependencies": { "@babel/core": "^7.9.0", diff --git a/e2e/2.x/basic/test.js b/e2e/2.x/basic/test.js index c81e3292..7ec85043 100644 --- a/e2e/2.x/basic/test.js +++ b/e2e/2.x/basic/test.js @@ -20,6 +20,7 @@ import PugRelative from './components/PugRelativeExtends.vue' import Jsx from './components/Jsx.vue' import Constructor from './components/Constructor.vue' import { compileStyle } from '@vue/component-compiler-utils' +import ScriptSetup from './components/ScriptSetup' jest.mock('@vue/component-compiler-utils', () => ({ ...jest.requireActual('@vue/component-compiler-utils'), compileStyle: jest.fn(() => ({ errors: [], code: '' })) @@ -156,6 +157,12 @@ test('processes SFC with no template', () => { expect(wrapper.element.tagName).toBe('SECTION') }) +test('processes SFC with + + +{ + "en": { + "hello": "Hello!" + }, + "ja": { + "hello": "こんにちは!" + } +} + diff --git a/e2e/2.x/custom-block/components/Multiple.vue b/e2e/2.x/custom-block/components/Multiple.vue new file mode 100644 index 00000000..f204d041 --- /dev/null +++ b/e2e/2.x/custom-block/components/Multiple.vue @@ -0,0 +1,26 @@ + + + + + +{ + "en": { + "hello": "Hello!" + }, + "ja": { + "hello": "こんにちは!" + } +} + + + +{ + "foo": "foo" +} + diff --git a/e2e/2.x/custom-block/package.json b/e2e/2.x/custom-block/package.json new file mode 100644 index 00000000..0b0442f6 --- /dev/null +++ b/e2e/2.x/custom-block/package.json @@ -0,0 +1,41 @@ +{ + "name": "vue2-custom-block", + "version": "1.0.0", + "license": "MIT", + "private": true, + "scripts": { + "test": "jest --no-cache --coverage test.js" + }, + "dependencies": { + "vue": "^2.7.7", + "vue-template-compiler": "^2.7.7" + }, + "devDependencies": { + "@babel/core": "^7.9.0", + "@babel/preset-env": "^7.9.0", + "@vue/vue2-jest": "^29.0.0", + "jest": "29.x", + "jest-environment-jsdom": "29.x" + }, + "jest": { + "moduleFileExtensions": [ + "js", + "json", + "vue" + ], + "transform": { + "^.+\\.js$": "babel-jest", + "^.+\\.vue$": "@vue/vue2-jest" + }, + "moduleNameMapper": { + "^~?__styles/(.*)$": "/components/styles/$1" + }, + "globals": { + "vue-jest": { + "transform": { + "custom": "./transformer.js" + } + } + } + } +} diff --git a/e2e/2.x/custom-block/test.js b/e2e/2.x/custom-block/test.js new file mode 100644 index 00000000..79556a9c --- /dev/null +++ b/e2e/2.x/custom-block/test.js @@ -0,0 +1,33 @@ +import Basic from './components/Basic.vue' +import Multiple from './components/Multiple.vue' + +test('Basic', () => { + expect(Basic.__custom).toMatchObject([ + { + en: { + hello: 'Hello!' + }, + ja: { + hello: 'こんにちは!' + } + } + ]) + expect(Basic.__custom).toMatchSnapshot() +}) + +test('Multiple blocks', () => { + expect(Multiple.__custom).toMatchObject([ + { + en: { + hello: 'Hello!' + }, + ja: { + hello: 'こんにちは!' + } + }, + { + foo: 'foo' + } + ]) + expect(Multiple.__custom).toMatchSnapshot() +}) diff --git a/e2e/2.x/custom-block/transformer.js b/e2e/2.x/custom-block/transformer.js new file mode 100644 index 00000000..b0266930 --- /dev/null +++ b/e2e/2.x/custom-block/transformer.js @@ -0,0 +1,21 @@ +function convert(content) { + return JSON.stringify(JSON.parse(content)) + .replace(/\u2028/g, '\\u2028') // LINE SEPARATOR + .replace(/\u2029/g, '\\u2029') // PARAGRAPH SEPARATOR + .replace(/\\/g, '\\\\') + .replace(/'/g, "\\'") +} + +module.exports = { + process({ blocks, vueOptionsNamespace, filename, config }) { + const ret = blocks.reduce((codes, block) => { + codes.push( + `${vueOptionsNamespace}.__custom = ${vueOptionsNamespace}.__custom || [];${vueOptionsNamespace}.__custom.push(${convert( + block.content + )});` + ) + return codes + }, []) + return ret.join('') + } +} diff --git a/e2e/2.x/custom-transformers/components/Scss.vue b/e2e/2.x/custom-transformers/components/Scss.vue index 6b88eb24..474edea9 100644 --- a/e2e/2.x/custom-transformers/components/Scss.vue +++ b/e2e/2.x/custom-transformers/components/Scss.vue @@ -1,7 +1,7 @@ diff --git a/packages/vue2-jest/lib/process-custom-blocks.js b/packages/vue2-jest/lib/process-custom-blocks.js index a7e75fff..17516fa5 100644 --- a/packages/vue2-jest/lib/process-custom-blocks.js +++ b/packages/vue2-jest/lib/process-custom-blocks.js @@ -1,4 +1,5 @@ const { getVueJestConfig, getCustomTransformer } = require('./utils') +const vueOptionsNamespace = require('./constants').vueOptionsNamespace function applyTransformer( transformer, @@ -16,7 +17,7 @@ function groupByType(acc, block) { return acc } -module.exports = function(allBlocks, filename, componentNamespace, config) { +module.exports = function(allBlocks, filename, config) { const blocksByType = allBlocks.reduce(groupByType, {}) const code = [] for (const [type, blocks] of Object.entries(blocksByType)) { @@ -28,7 +29,7 @@ module.exports = function(allBlocks, filename, componentNamespace, config) { const codeStr = applyTransformer( transformer, blocks, - componentNamespace, + vueOptionsNamespace, filename, config ) diff --git a/packages/vue2-jest/lib/process.js b/packages/vue2-jest/lib/process.js index 6256144c..ebcdfdd8 100644 --- a/packages/vue2-jest/lib/process.js +++ b/packages/vue2-jest/lib/process.js @@ -10,7 +10,6 @@ const loadSrc = require('./utils').loadSrc const babelTransformer = require('babel-jest').default const generateCode = require('./generate-code') const mapLines = require('./map-lines') -const vueComponentNamespace = require('./constants').vueComponentNamespace let isVue27 = false let compilerUtils @@ -143,9 +142,6 @@ module.exports = function(src, filename, config) { filename }) - const componentNamespace = - getVueJestConfig(config)['componentNamespace'] || vueComponentNamespace - const templateResult = processTemplate(descriptor, filename, config) const scriptResult = processScript(descriptor.script, filename, config) const scriptSetupResult = processScriptSetup(descriptor, filename, config) @@ -153,7 +149,6 @@ module.exports = function(src, filename, config) { const customBlocksResult = processCustomBlocks( descriptor.customBlocks, filename, - componentNamespace, config ) From 62d6ebcc7b9c23dc9af2301cec73caf4e6a79071 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Mon, 26 Sep 2022 10:50:30 +1000 Subject: [PATCH 04/19] publish: 29.1.1 --- packages/vue2-jest/package.json | 2 +- packages/vue3-jest/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vue2-jest/package.json b/packages/vue2-jest/package.json index 559801d4..b9bb1a75 100644 --- a/packages/vue2-jest/package.json +++ b/packages/vue2-jest/package.json @@ -1,6 +1,6 @@ { "name": "@vue/vue2-jest", - "version": "29.1.0", + "version": "29.1.1", "description": "Jest transformer for Vue 2", "main": "lib/index.js", "files": [ diff --git a/packages/vue3-jest/package.json b/packages/vue3-jest/package.json index aa8cc824..fb96c4a8 100644 --- a/packages/vue3-jest/package.json +++ b/packages/vue3-jest/package.json @@ -1,6 +1,6 @@ { "name": "@vue/vue3-jest", - "version": "29.1.0", + "version": "29.1.1", "description": "Jest Vue transform", "main": "lib/index.js", "files": [ From bb516dad94c88ec08ffbfc0680973953358cd89b Mon Sep 17 00:00:00 2001 From: Adam Hines Date: Wed, 2 Nov 2022 22:49:12 -0600 Subject: [PATCH 05/19] fix: parse extended tsconfigs when transpiling script blocks (#502) * fix(tsconfig): parse extended tsconfigs when transpiling script blocks A change introduced in v28.1.0 in PR #471 unintentionally changed the behavior of the tsconfig parsing such that configs using "extends" were no longer being considered. Fixes: #495 * chore(cache): cache tsconfig parsing to avoid the cost per vue file / interpolated string Co-authored-by: Adam Hines --- e2e/2.x/basic/components/ExtendedTsConfig.vue | 34 ++++++++++++ .../ModuleRequiringEsModuleInterop.js | 1 + e2e/2.x/basic/test.js | 7 +++ e2e/2.x/basic/tsconfig.base.json | 21 +++++++ e2e/2.x/basic/tsconfig.json | 19 +------ e2e/3.x/basic/components/ExtendedTsConfig.vue | 34 ++++++++++++ .../ModuleRequiringEsModuleInterop.js | 1 + e2e/3.x/basic/test.js | 7 +++ e2e/3.x/basic/tsconfig.base.json | 21 +++++++ e2e/3.x/basic/tsconfig.json | 19 +------ packages/vue2-jest/lib/ensure-require.js | 2 +- packages/vue2-jest/lib/throw-error.js | 3 + packages/vue2-jest/lib/utils.js | 52 ++++++++++++++---- packages/vue3-jest/lib/ensure-require.js | 2 +- packages/vue3-jest/lib/throw-error.js | 3 + packages/vue3-jest/lib/utils.js | 55 +++++++++++++++---- 16 files changed, 220 insertions(+), 61 deletions(-) create mode 100644 e2e/2.x/basic/components/ExtendedTsConfig.vue create mode 100644 e2e/2.x/basic/components/ModuleRequiringEsModuleInterop.js create mode 100644 e2e/2.x/basic/tsconfig.base.json create mode 100644 e2e/3.x/basic/components/ExtendedTsConfig.vue create mode 100644 e2e/3.x/basic/components/ModuleRequiringEsModuleInterop.js create mode 100644 e2e/3.x/basic/tsconfig.base.json create mode 100644 packages/vue2-jest/lib/throw-error.js create mode 100644 packages/vue3-jest/lib/throw-error.js diff --git a/e2e/2.x/basic/components/ExtendedTsConfig.vue b/e2e/2.x/basic/components/ExtendedTsConfig.vue new file mode 100644 index 00000000..8dc7001f --- /dev/null +++ b/e2e/2.x/basic/components/ExtendedTsConfig.vue @@ -0,0 +1,34 @@ + + + diff --git a/e2e/2.x/basic/components/ModuleRequiringEsModuleInterop.js b/e2e/2.x/basic/components/ModuleRequiringEsModuleInterop.js new file mode 100644 index 00000000..fed7caa7 --- /dev/null +++ b/e2e/2.x/basic/components/ModuleRequiringEsModuleInterop.js @@ -0,0 +1 @@ +module.exports = () => false diff --git a/e2e/2.x/basic/test.js b/e2e/2.x/basic/test.js index 7ec85043..a340be9c 100644 --- a/e2e/2.x/basic/test.js +++ b/e2e/2.x/basic/test.js @@ -21,6 +21,8 @@ import Jsx from './components/Jsx.vue' import Constructor from './components/Constructor.vue' import { compileStyle } from '@vue/component-compiler-utils' import ScriptSetup from './components/ScriptSetup' +import ExtendedTsConfig from './components/ExtendedTsConfig.vue' + jest.mock('@vue/component-compiler-utils', () => ({ ...jest.requireActual('@vue/component-compiler-utils'), compileStyle: jest.fn(() => ({ errors: [], code: '' })) @@ -163,6 +165,11 @@ test('processes SFC with diff --git a/e2e/3.x/basic/components/ModuleRequiringEsModuleInterop.js b/e2e/3.x/basic/components/ModuleRequiringEsModuleInterop.js new file mode 100644 index 00000000..fed7caa7 --- /dev/null +++ b/e2e/3.x/basic/components/ModuleRequiringEsModuleInterop.js @@ -0,0 +1 @@ +module.exports = () => false diff --git a/e2e/3.x/basic/test.js b/e2e/3.x/basic/test.js index 553ec119..3a5dddaa 100644 --- a/e2e/3.x/basic/test.js +++ b/e2e/3.x/basic/test.js @@ -23,6 +23,7 @@ import ScriptSetup from './components/ScriptSetup.vue' import ScriptSetupSugarRef from './components/ScriptSetupSugarRef.vue' import FunctionalRenderFn from './components/FunctionalRenderFn.vue' import CompilerDirective from './components/CompilerDirective.vue' +import ExtendedTsConfig from './components/ExtendedTsConfig.vue' // TODO: JSX for Vue 3? TSX? import Jsx from './components/Jsx.vue' @@ -207,3 +208,9 @@ test('ensure compilerOptions is passed down', () => { const elm = document.querySelector('h1') expect(elm.hasAttribute('data-test')).toBe(false) }) + +test('handles extended tsconfig.json files', () => { + mount(ExtendedTsConfig) + const elm = document.querySelector('div') + expect(elm).toBeDefined() +}) diff --git a/e2e/3.x/basic/tsconfig.base.json b/e2e/3.x/basic/tsconfig.base.json new file mode 100644 index 00000000..0b98e194 --- /dev/null +++ b/e2e/3.x/basic/tsconfig.base.json @@ -0,0 +1,21 @@ +{ + "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, + "esModuleInterop": true, + "allowJs": true + } +} diff --git a/e2e/3.x/basic/tsconfig.json b/e2e/3.x/basic/tsconfig.json index 8073706e..ffcbb947 100644 --- a/e2e/3.x/basic/tsconfig.json +++ b/e2e/3.x/basic/tsconfig.json @@ -1,20 +1,3 @@ { - "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 - } + "extends": "./tsconfig.base.json" } diff --git a/packages/vue2-jest/lib/ensure-require.js b/packages/vue2-jest/lib/ensure-require.js index 17f40920..dd945ee2 100644 --- a/packages/vue2-jest/lib/ensure-require.js +++ b/packages/vue2-jest/lib/ensure-require.js @@ -1,4 +1,4 @@ -const throwError = require('./utils').throwError +const throwError = require('./throw-error') module.exports = function(name, deps) { let i, len diff --git a/packages/vue2-jest/lib/throw-error.js b/packages/vue2-jest/lib/throw-error.js new file mode 100644 index 00000000..5d1272e3 --- /dev/null +++ b/packages/vue2-jest/lib/throw-error.js @@ -0,0 +1,3 @@ +module.exports = function throwError(msg) { + throw new Error('\n[vue-jest] Error: ' + msg + '\n') +} diff --git a/packages/vue2-jest/lib/utils.js b/packages/vue2-jest/lib/utils.js index 25b8a5fa..f68d79ec 100644 --- a/packages/vue2-jest/lib/utils.js +++ b/packages/vue2-jest/lib/utils.js @@ -1,6 +1,8 @@ +const ensureRequire = require('./ensure-require') +const throwError = require('./throw-error') const constants = require('./constants') const loadPartialConfig = require('@babel/core').loadPartialConfig -const { loadSync: loadTsConfigSync } = require('tsconfig') +const { resolveSync: resolveTsConfigSync } = require('tsconfig') const chalk = require('chalk') const path = require('path') const fs = require('fs') @@ -68,23 +70,55 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) { return loadPartialConfig(opts).options } +const tsConfigCache = new Map() + /** * 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) { + if (tsConfigCache.has(path)) { + return tsConfigCache.get(path) + } + + ensureRequire('typescript', ['typescript']) + const typescript = require('typescript') + + const tsconfigPath = resolveTsConfigSync(process.cwd(), path || '') + if (!tsconfigPath) { warn(`Not found tsconfig.json.`) return null } - const compilerOptions = - (tsconfig.config && tsconfig.config.compilerOptions) || {} - return { - compilerOptions: { ...compilerOptions, module: 'commonjs' } + const parsedConfig = typescript.getParsedCommandLineOfConfigFile( + tsconfigPath, + {}, + { + ...typescript.sys, + onUnRecoverableConfigFileDiagnostic: e => { + const errorMessage = typescript.formatDiagnostic(e, { + getCurrentDirectory: () => process.cwd(), + getNewLine: () => `\n`, + getCanonicalFileName: file => file.replace(/\\/g, '/') + }) + warn(errorMessage) + } + } + ) + + const compilerOptions = parsedConfig ? parsedConfig.options : {} + + const transpileConfig = { + compilerOptions: { + ...compilerOptions, + module: typescript.ModuleKind.CommonJS + } } + + tsConfigCache.set(path, transpileConfig) + + return transpileConfig } function isValidTransformer(transformer) { @@ -131,10 +165,6 @@ const getCustomTransformer = function getCustomTransformer( : transformer } -const throwError = function error(msg) { - throw new Error('\n[vue-jest] Error: ' + msg + '\n') -} - const stripInlineSourceMap = function(str) { return str.slice(0, str.indexOf('//# sourceMappingURL')) } diff --git a/packages/vue3-jest/lib/ensure-require.js b/packages/vue3-jest/lib/ensure-require.js index 17f40920..dd945ee2 100644 --- a/packages/vue3-jest/lib/ensure-require.js +++ b/packages/vue3-jest/lib/ensure-require.js @@ -1,4 +1,4 @@ -const throwError = require('./utils').throwError +const throwError = require('./throw-error') module.exports = function(name, deps) { let i, len diff --git a/packages/vue3-jest/lib/throw-error.js b/packages/vue3-jest/lib/throw-error.js new file mode 100644 index 00000000..5d1272e3 --- /dev/null +++ b/packages/vue3-jest/lib/throw-error.js @@ -0,0 +1,3 @@ +module.exports = function throwError(msg) { + throw new Error('\n[vue-jest] Error: ' + msg + '\n') +} diff --git a/packages/vue3-jest/lib/utils.js b/packages/vue3-jest/lib/utils.js index cbd7fd7a..5b1e70ee 100644 --- a/packages/vue3-jest/lib/utils.js +++ b/packages/vue3-jest/lib/utils.js @@ -1,6 +1,8 @@ +const ensureRequire = require('./ensure-require') +const throwError = require('./throw-error') const constants = require('./constants') const loadPartialConfig = require('@babel/core').loadPartialConfig -const { loadSync: loadTsConfigSync } = require('tsconfig') +const { resolveSync: resolveTsConfigSync } = require('tsconfig') const chalk = require('chalk') const path = require('path') const fs = require('fs') @@ -68,24 +70,57 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) { return loadPartialConfig(opts).options } +const tsConfigCache = new Map() + /** * 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) { + if (tsConfigCache.has(path)) { + return tsConfigCache.get(path) + } + + ensureRequire('typescript', ['typescript']) + const typescript = require('typescript') + + const tsconfigPath = resolveTsConfigSync(process.cwd(), path || '') + if (!tsconfigPath) { warn(`Not found tsconfig.json.`) return null } - 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' } + const parsedConfig = typescript.getParsedCommandLineOfConfigFile( + tsconfigPath, + {}, + { + ...typescript.sys, + onUnRecoverableConfigFileDiagnostic: e => { + const errorMessage = typescript.formatDiagnostic(e, { + getCurrentDirectory: () => process.cwd(), + getNewLine: () => `\n`, + getCanonicalFileName: file => file.replace(/\\/g, '/') + }) + warn(errorMessage) + } + } + ) + + const compilerOptions = parsedConfig ? parsedConfig.options : {} + + const transpileConfig = { + compilerOptions: { + ...compilerOptions, + // Force es5 to prevent const vue_1 = require('vue') from conflicting + target: typescript.ScriptTarget.ES5, + module: typescript.ModuleKind.CommonJS + } } + + tsConfigCache.set(path, transpileConfig) + + return transpileConfig } function isValidTransformer(transformer) { @@ -133,10 +168,6 @@ const getCustomTransformer = function getCustomTransformer( : transformer } -const throwError = function error(msg) { - throw new Error('\n[vue-jest] Error: ' + msg + '\n') -} - const stripInlineSourceMap = function(str) { return str.slice(0, str.indexOf('//# sourceMappingURL')) } From 8c0e8bcf7c9589b027d17ee2e1da9183be60a4ab Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 28 Nov 2022 04:35:18 +0100 Subject: [PATCH 06/19] fix: "ReferenceError: true__options__ is not defined" (#509) --- packages/vue2-jest/lib/generate-code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vue2-jest/lib/generate-code.js b/packages/vue2-jest/lib/generate-code.js index 5ef91438..a3f9d13c 100644 --- a/packages/vue2-jest/lib/generate-code.js +++ b/packages/vue2-jest/lib/generate-code.js @@ -54,7 +54,7 @@ module.exports = function generateCode( ) node.add( - `__options__.render = render\n` + + `\n__options__.render = render\n` + `${namespace}.staticRenderFns = staticRenderFns\n` ) From dbe8022c59407b7474e78d2514c317685680c15e Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Mon, 28 Nov 2022 13:38:09 +1000 Subject: [PATCH 07/19] publish: 29.2.1 --- packages/vue2-jest/package.json | 2 +- packages/vue3-jest/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vue2-jest/package.json b/packages/vue2-jest/package.json index b9bb1a75..bec989c2 100644 --- a/packages/vue2-jest/package.json +++ b/packages/vue2-jest/package.json @@ -1,6 +1,6 @@ { "name": "@vue/vue2-jest", - "version": "29.1.1", + "version": "29.2.1", "description": "Jest transformer for Vue 2", "main": "lib/index.js", "files": [ diff --git a/packages/vue3-jest/package.json b/packages/vue3-jest/package.json index fb96c4a8..27615ce3 100644 --- a/packages/vue3-jest/package.json +++ b/packages/vue3-jest/package.json @@ -1,6 +1,6 @@ { "name": "@vue/vue3-jest", - "version": "29.1.1", + "version": "29.2.1", "description": "Jest Vue transform", "main": "lib/index.js", "files": [ From 33daf4423f07408131fe5d641eb6eb85aa66d139 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sun, 11 Dec 2022 23:56:41 +0100 Subject: [PATCH 08/19] fix: Map lines for script block (#516) Signed-off-by: Wolfgang Walther Signed-off-by: Wolfgang Walther --- e2e/2.x/basic/__snapshots__/test.js.snap | 43 +++++++++++++++--------- packages/vue2-jest/lib/process.js | 1 + 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/e2e/2.x/basic/__snapshots__/test.js.snap b/e2e/2.x/basic/__snapshots__/test.js.snap index 018258ad..f8f9c647 100644 --- a/e2e/2.x/basic/__snapshots__/test.js.snap +++ b/e2e/2.x/basic/__snapshots__/test.js.snap @@ -3,25 +3,35 @@ exports[`generates source maps for .vue files 1`] = ` { "file": "./components/Basic.vue", - "mappings": ";;;;;;eACe;AACbA,MAAI,EAAE,OADO;AAEbC,UAAQ,EAAE;AACRC,kBAAc,EAAE,SAASA,cAAT,GAA0B;AACxC,aAAO;AACLC,WAAG,EAAE,KAAKC,OADL;AAELC,YAAI,EAAE,CAAC,KAAKD,OAFP;AAGLE,cAAM,EAAE,KAAKF;AAHR,OAAP;AAKD;AAPO,GAFG;AAWbG,MAAI,EAAE,SAASA,IAAT,GAAgB;AACpB,WAAO;AACLC,SAAG,EAAE,4BADA;AAELJ,aAAO,EAAE;AAFJ,KAAP;AAID,GAhBY;AAiBbK,SAAO,EAAE;AACPC,eAAW,EAAE,SAASA,WAAT,GAAuB;AAClC,WAAKN,OAAL,GAAe,CAAC,KAAKA,OAArB;AACD;AAHM;AAjBI,C", - "names": [ - "name", - "computed", - "headingClasses", - "red", - "isCrazy", - "blue", - "shadow", - "data", - "msg", - "methods", - "toggleClass", - ], + "mappings": ";;;;;;eAuBe;AACb,MAAI,EAAE,OADO;AAEb,UAAQ,EAAE;AACR,kBAAc,EAAE,SAAS,cAAT,GAA0B;AACxC,aAAO;AACL,WAAG,EAAE,KAAK,OADL;AAEL,YAAI,EAAE,CAAC,KAAK,OAFP;AAGL,cAAM,EAAE,KAAK;AAHR,OAAP;AAKD;AAPO,GAFG;AAWb,MAAI,EAAE,SAAS,IAAT,GAAgB;AACpB,WAAO;AACL,SAAG,EAAE,4BADA;AAEL,aAAO,EAAE;AAFJ,KAAP;AAID,GAhBY;AAiBb,SAAO,EAAE;AACP,eAAW,EAAE,SAAS,WAAT,GAAuB;AAClC,WAAK,OAAL,GAAe,CAAC,KAAK,OAArB;AACD;AAHM;AAjBI", + "names": [], "sources": [ - "Basic.vue", + "components/Basic.vue", ], "sourcesContent": [ - " + " + + + + + + ", ], "version": 3, diff --git a/packages/vue2-jest/lib/process.js b/packages/vue2-jest/lib/process.js index ebcdfdd8..cbb63b3a 100644 --- a/packages/vue2-jest/lib/process.js +++ b/packages/vue2-jest/lib/process.js @@ -48,6 +48,7 @@ function processScript(scriptPart, filePath, config) { const result = transformer.process(scriptPart.content, filePath, config) result.code = stripInlineSourceMap(result.code) + result.map = mapLines(scriptPart.map, result.map) result.externalSrc = externalSrc return result } From 3dc76ff8491d149d89a8ba5deb02f517f1535f98 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Mon, 12 Dec 2022 08:58:50 +1000 Subject: [PATCH 09/19] publish: 29.2.2 --- packages/vue2-jest/package.json | 2 +- packages/vue3-jest/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vue2-jest/package.json b/packages/vue2-jest/package.json index bec989c2..865bdad5 100644 --- a/packages/vue2-jest/package.json +++ b/packages/vue2-jest/package.json @@ -1,6 +1,6 @@ { "name": "@vue/vue2-jest", - "version": "29.2.1", + "version": "29.2.2", "description": "Jest transformer for Vue 2", "main": "lib/index.js", "files": [ diff --git a/packages/vue3-jest/package.json b/packages/vue3-jest/package.json index 27615ce3..a06233f5 100644 --- a/packages/vue3-jest/package.json +++ b/packages/vue3-jest/package.json @@ -1,6 +1,6 @@ { "name": "@vue/vue3-jest", - "version": "29.2.1", + "version": "29.2.2", "description": "Jest Vue transform", "main": "lib/index.js", "files": [ From 36c6d970ed3cd29797791fa4e8c6b2fc2b5c34d4 Mon Sep 17 00:00:00 2001 From: Renan Andrade Date: Thu, 2 Mar 2023 23:02:36 +0100 Subject: [PATCH 10/19] fix: script and script setup in same vue file (#536) --- .../basic/components/ScriptAndScriptSetup.vue | 23 +++++++++++++++++++ e2e/2.x/basic/test.js | 7 ++++++ packages/vue2-jest/lib/process.js | 9 ++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 e2e/2.x/basic/components/ScriptAndScriptSetup.vue diff --git a/e2e/2.x/basic/components/ScriptAndScriptSetup.vue b/e2e/2.x/basic/components/ScriptAndScriptSetup.vue new file mode 100644 index 00000000..e3aa2fcb --- /dev/null +++ b/e2e/2.x/basic/components/ScriptAndScriptSetup.vue @@ -0,0 +1,23 @@ + + + + + diff --git a/e2e/2.x/basic/test.js b/e2e/2.x/basic/test.js index a340be9c..9eb6b525 100644 --- a/e2e/2.x/basic/test.js +++ b/e2e/2.x/basic/test.js @@ -21,6 +21,7 @@ import Jsx from './components/Jsx.vue' import Constructor from './components/Constructor.vue' import { compileStyle } from '@vue/component-compiler-utils' import ScriptSetup from './components/ScriptSetup' +import ScriptAndScriptSetup from './components/ScriptAndScriptSetup' import ExtendedTsConfig from './components/ExtendedTsConfig.vue' jest.mock('@vue/component-compiler-utils', () => ({ @@ -165,6 +166,12 @@ test('processes SFC with + + diff --git a/e2e/3.x/basic/test.js b/e2e/3.x/basic/test.js index 3a5dddaa..504c44c7 100644 --- a/e2e/3.x/basic/test.js +++ b/e2e/3.x/basic/test.js @@ -24,6 +24,7 @@ import ScriptSetupSugarRef from './components/ScriptSetupSugarRef.vue' import FunctionalRenderFn from './components/FunctionalRenderFn.vue' import CompilerDirective from './components/CompilerDirective.vue' import ExtendedTsConfig from './components/ExtendedTsConfig.vue' +import ScriptAndScriptSetup from './components/ScriptAndScriptSetup.vue' // TODO: JSX for Vue 3? TSX? import Jsx from './components/Jsx.vue' @@ -214,3 +215,9 @@ test('handles extended tsconfig.json files', () => { const elm = document.querySelector('div') expect(elm).toBeDefined() }) + +test('processes SFC with both diff --git a/e2e/3.x/babel-in-package/package.json b/e2e/3.x/babel-in-package/package.json index 3e0881ed..5c2ffe0f 100644 --- a/e2e/3.x/babel-in-package/package.json +++ b/e2e/3.x/babel-in-package/package.json @@ -12,6 +12,7 @@ "devDependencies": { "@babel/core": "^7.9.0", "@babel/preset-env": "^7.9.0", + "@vue/babel-plugin-jsx": "^1.1.5", "@vue/vue3-jest": "^29.0.0", "coffeescript": "^2.3.2", "jest": "29.x", @@ -34,6 +35,9 @@ "babel": { "presets": [ "@babel/env" + ], + "plugins": [ + "@vue/babel-plugin-jsx" ] } } diff --git a/e2e/3.x/babel-in-package/test.js b/e2e/3.x/babel-in-package/test.js index 8bc52e74..e5b7d33d 100644 --- a/e2e/3.x/babel-in-package/test.js +++ b/e2e/3.x/babel-in-package/test.js @@ -3,6 +3,7 @@ import { createApp, h } from 'vue' import TypeScript from './components/TypeScript.vue' import Basic from './components/Basic.vue' import Coffee from './components/Coffee.vue' +import Tsx from './components/Tsx.vue' function mount(Component, props, slots) { document.getElementsByTagName('html')[0].innerHTML = '' @@ -34,3 +35,8 @@ test('processes .vue files with lang set to typescript', () => { expect(document.querySelector('#parent').textContent).toBe('Parent') expect(document.querySelector('#child').textContent).toBe('Child') }) + +test('processes .vue files with lang set to tsx(typescript)', () => { + mount(Tsx) + expect(document.querySelector('div').textContent).toContain('tsx components') +}) diff --git a/packages/vue3-jest/lib/process.js b/packages/vue3-jest/lib/process.js index ff1e3de6..6e4dbdb0 100644 --- a/packages/vue3-jest/lib/process.js +++ b/packages/vue3-jest/lib/process.js @@ -19,7 +19,7 @@ const vueComponentNamespace = require('./constants').vueComponentNamespace function resolveTransformer(lang = 'js', vueJestConfig) { const transformer = getCustomTransformer(vueJestConfig['transform'], lang) if (/^typescript$|tsx?$/.test(lang)) { - return transformer || typescriptTransformer + return transformer || typescriptTransformer(lang) } else if (/^coffee$|coffeescript$/.test(lang)) { return transformer || coffeescriptTransformer } else { diff --git a/packages/vue3-jest/lib/transformers/typescript.js b/packages/vue3-jest/lib/transformers/typescript.js index e59a2429..18be5f41 100644 --- a/packages/vue3-jest/lib/transformers/typescript.js +++ b/packages/vue3-jest/lib/transformers/typescript.js @@ -7,7 +7,7 @@ const { getVueJestConfig } = require('../utils') -module.exports = { +module.exports = scriptLang => ({ process(scriptContent, filePath, config) { ensureRequire('typescript', ['typescript']) const typescript = require('typescript') @@ -16,7 +16,7 @@ module.exports = { const res = typescript.transpileModule(scriptContent, { ...tsconfig, - fileName: filePath + fileName: filePath + (scriptLang === 'tsx' ? '.tsx' : '') }) res.outputText = stripInlineSourceMap(res.outputText) @@ -31,4 +31,4 @@ module.exports = { return transformer.process(res.outputText, filePath, config) } -} +}) diff --git a/yarn.lock b/yarn.lock index a45a0fb0..dcebc9d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17,6 +17,13 @@ dependencies: "@babel/highlight" "^7.16.7" +"@babel/code-frame@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.22.5.tgz#234d98e1551960604f1246e6475891a570ad5658" + integrity sha512-Xmwn266vad+6DAqEB2A6V/CcZVp62BbwVmcOJc2RPuwih1kw02TjQvWVWlcKGbBPd+8/0V5DEkOcizRGYsspYQ== + dependencies: + "@babel/highlight" "^7.22.5" + "@babel/compat-data@^7.13.11", "@babel/compat-data@^7.14.7", "@babel/compat-data@^7.15.0", "@babel/compat-data@^7.17.7": version "7.17.7" resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.17.7.tgz#078d8b833fbbcc95286613be8c716cef2b519fa2" @@ -52,6 +59,16 @@ jsesc "^2.5.1" source-map "^0.5.0" +"@babel/generator@^7.22.7": + version "7.22.9" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.22.9.tgz#572ecfa7a31002fa1de2a9d91621fd895da8493d" + integrity sha512-KtLMbmicyuK2Ak/FTCJVbDnkN1SlT8/kceFTiuDiiRUUSMnHMidxSCdG4ndkTOHHpoomWe/4xkvHkEOncwjYIw== + dependencies: + "@babel/types" "^7.22.5" + "@jridgewell/gen-mapping" "^0.3.2" + "@jridgewell/trace-mapping" "^0.3.17" + jsesc "^2.5.1" + "@babel/helper-annotate-as-pure@^7.14.5": version "7.14.5" resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.14.5.tgz#7bf478ec3b71726d56a8ca5775b046fc29879e61" @@ -118,6 +135,11 @@ dependencies: "@babel/types" "^7.16.7" +"@babel/helper-environment-visitor@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.5.tgz#f06dd41b7c1f44e1f8da6c4055b41ab3a09a7e98" + integrity sha512-XGmhECfVA/5sAt+H+xpSg0mfrHq6FzNr9Oxh7PSEBBRUb/mL7Kz3NICXb194rCqAEdxkhPT1a88teizAFyvk8Q== + "@babel/helper-explode-assignable-expression@^7.14.5": version "7.14.5" resolved "https://registry.yarnpkg.com/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.14.5.tgz#8aa72e708205c7bb643e45c73b4386cdf2a1f645" @@ -133,6 +155,14 @@ "@babel/template" "^7.16.7" "@babel/types" "^7.17.0" +"@babel/helper-function-name@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.22.5.tgz#ede300828905bb15e582c037162f99d5183af1be" + integrity sha512-wtHSq6jMRE3uF2otvfuD3DIvVhOsSNshQl0Qrd7qC9oQJzHvOL4qQXlQn2916+CXGywIjpGuIkoyZRRxHPiNQQ== + dependencies: + "@babel/template" "^7.22.5" + "@babel/types" "^7.22.5" + "@babel/helper-hoist-variables@^7.14.5", "@babel/helper-hoist-variables@^7.16.7": version "7.16.7" resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.16.7.tgz#86bcb19a77a509c7b77d0e22323ef588fa58c246" @@ -140,6 +170,13 @@ dependencies: "@babel/types" "^7.16.7" +"@babel/helper-hoist-variables@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz#c01a007dac05c085914e8fb652b339db50d823bb" + integrity sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw== + dependencies: + "@babel/types" "^7.22.5" + "@babel/helper-member-expression-to-functions@^7.15.0": version "7.15.0" resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.15.0.tgz#0ddaf5299c8179f27f37327936553e9bba60990b" @@ -154,6 +191,13 @@ dependencies: "@babel/types" "^7.16.7" +"@babel/helper-module-imports@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.22.5.tgz#1a8f4c9f4027d23f520bd76b364d44434a72660c" + integrity sha512-8Dl6+HD/cKifutF5qGd/8ZJi84QeAKh+CEe1sBzz8UayBBGg1dAIJrdHOcOM5b2MpzWL2yuotJTtGjETq0qjXg== + dependencies: + "@babel/types" "^7.22.5" + "@babel/helper-module-transforms@^7.14.5", "@babel/helper-module-transforms@^7.15.0", "@babel/helper-module-transforms@^7.17.7": version "7.17.7" resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.17.7.tgz#3943c7f777139e7954a5355c815263741a9c1cbd" @@ -180,6 +224,11 @@ resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.18.9.tgz#4b8aea3b069d8cb8a72cdfe28ddf5ceca695ef2f" integrity sha512-aBXPT3bmtLryXaoJLyYPXPlSD4p1ld9aYeR+sJNOZjJJGiOpb+fKfh3NkcCu7J54nUJwCERPBExCCpyCOHnu/w== +"@babel/helper-plugin-utils@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.22.5.tgz#dd7ee3735e8a313b9f7b05a773d892e88e6d7295" + integrity sha512-uLls06UVKgFG9QD4OeFYLEGteMIAa5kpTPcFL28yuCIIzsf6ZyKZMllKVOCZFhiZ5ptnwX4mtKdWCBE/uT4amg== + "@babel/helper-remap-async-to-generator@^7.14.5": version "7.14.5" resolved "https://registry.yarnpkg.com/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.14.5.tgz#51439c913612958f54a987a4ffc9ee587a2045d6" @@ -220,11 +269,28 @@ dependencies: "@babel/types" "^7.16.7" +"@babel/helper-split-export-declaration@^7.22.6": + version "7.22.6" + resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz#322c61b7310c0997fe4c323955667f18fcefb91c" + integrity sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g== + dependencies: + "@babel/types" "^7.22.5" + +"@babel/helper-string-parser@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz#533f36457a25814cf1df6488523ad547d784a99f" + integrity sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw== + "@babel/helper-validator-identifier@^7.14.5", "@babel/helper-validator-identifier@^7.16.7": version "7.16.7" resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.16.7.tgz#e8c602438c4a8195751243da9031d1607d247cad" integrity sha512-hsEnFemeiW4D08A5gUAZxLBTXpZ39P+a+DGDsHw1yxqyQ/jzFEnxf5uTEGp+3bzAbNOxU1paTgYS4ECU/IgfDw== +"@babel/helper-validator-identifier@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz#9544ef6a33999343c8740fa51350f30eeaaaf193" + integrity sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ== + "@babel/helper-validator-option@^7.14.5", "@babel/helper-validator-option@^7.16.7": version "7.16.7" resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.16.7.tgz#b203ce62ce5fe153899b617c08957de860de4d23" @@ -258,7 +324,16 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.15.0", "@babel/parser@^7.16.7", "@babel/parser@^7.17.9", "@babel/parser@^7.6.0", "@babel/parser@^7.9.6": +"@babel/highlight@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.22.5.tgz#aa6c05c5407a67ebce408162b7ede789b4d22031" + integrity sha512-BSKlD1hgnedS5XRnGOljZawtag7H1yPfQp0tdNJCHoH6AZ+Pcm9VvkrK59/Yy593Ypg0zMxH2BxD1VPYUQ7UIw== + dependencies: + "@babel/helper-validator-identifier" "^7.22.5" + chalk "^2.0.0" + js-tokens "^4.0.0" + +"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.15.0", "@babel/parser@^7.16.7", "@babel/parser@^7.17.9": version "7.17.9" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.17.9.tgz#9c94189a6062f0291418ca021077983058e171ef" integrity sha512-vqUSBLP8dQHFPdPi9bc5GK9vRkYHJ49fsZdtoJ8EQ8ibpwk5rPKfvNIwChB0KVXcIjcepEBBd2VHC5r9Gy8ueg== @@ -268,6 +343,11 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.18.6.tgz#845338edecad65ebffef058d3be851f1d28a63bc" integrity sha512-uQVSa9jJUe/G/304lXspfWVpKpK4euFLgGiMQFOCpM/bgcAdeoHwi/OQz23O9GK2osz26ZiXRRV9aV+Yl1O8tw== +"@babel/parser@^7.22.5", "@babel/parser@^7.22.7": + version "7.22.7" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.22.7.tgz#df8cf085ce92ddbdbf668a7f186ce848c9036cae" + integrity sha512-7NF8pOkHP5o2vpmGgNGcfAeCvOYhGLyA3Z4eBQkT1RJlWu47n63bCs93QfJ2hIAFCil7L5P2IWhs1oToVgrL0Q== + "@babel/parser@^7.6.0", "@babel/parser@^7.9.6": version "7.15.5" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.15.5.tgz#d33a58ca69facc05b26adfe4abebfed56c1c2dac" @@ -473,6 +553,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.18.6" +"@babel/plugin-syntax-jsx@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.22.5.tgz#a6b68e84fb76e759fc3b93e901876ffabbe1d918" + integrity sha512-gvyP4hZrgrs/wWMaocvxZ44Hw0b3W8Pe+cMxc8V1ULQ07oh8VNbIRaoD1LRZVTvD+0nieDKjfgKg89sD7rrKrg== + dependencies: + "@babel/helper-plugin-utils" "^7.22.5" + "@babel/plugin-syntax-logical-assignment-operators@^7.10.4", "@babel/plugin-syntax-logical-assignment-operators@^7.8.3": version "7.10.4" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.10.4.tgz#ca91ef46303530448b906652bac2e9fe9941f699" @@ -890,6 +977,15 @@ "@babel/parser" "^7.16.7" "@babel/types" "^7.16.7" +"@babel/template@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.5.tgz#0c8c4d944509875849bd0344ff0050756eefc6ec" + integrity sha512-X7yV7eiwAxdj9k94NEylvbVHLiVG1nvzCV2EAowhxLTwODV1jl9UzZ48leOC0sH7OnuHrIkllaBgneUykIcZaw== + dependencies: + "@babel/code-frame" "^7.22.5" + "@babel/parser" "^7.22.5" + "@babel/types" "^7.22.5" + "@babel/traverse@^7.13.0", "@babel/traverse@^7.14.5", "@babel/traverse@^7.15.0", "@babel/traverse@^7.17.3", "@babel/traverse@^7.17.9", "@babel/traverse@^7.7.2": version "7.17.9" resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.17.9.tgz#1f9b207435d9ae4a8ed6998b2b82300d83c37a0d" @@ -906,6 +1002,22 @@ debug "^4.1.0" globals "^11.1.0" +"@babel/traverse@^7.22.5": + version "7.22.8" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.8.tgz#4d4451d31bc34efeae01eac222b514a77aa4000e" + integrity sha512-y6LPR+wpM2I3qJrsheCTwhIinzkETbplIgPBbwvqPKc+uljeA5gP+3nP8irdYt1mjQaDnlIcG+dw8OjAco4GXw== + dependencies: + "@babel/code-frame" "^7.22.5" + "@babel/generator" "^7.22.7" + "@babel/helper-environment-visitor" "^7.22.5" + "@babel/helper-function-name" "^7.22.5" + "@babel/helper-hoist-variables" "^7.22.5" + "@babel/helper-split-export-declaration" "^7.22.6" + "@babel/parser" "^7.22.7" + "@babel/types" "^7.22.5" + debug "^4.1.0" + globals "^11.1.0" + "@babel/types@^7.0.0", "@babel/types@^7.14.5", "@babel/types@^7.15.0", "@babel/types@^7.16.7", "@babel/types@^7.17.0", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4", "@babel/types@^7.6.1", "@babel/types@^7.9.6": version "7.17.0" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.17.0.tgz#a826e368bccb6b3d84acd76acad5c0d87342390b" @@ -914,6 +1026,15 @@ "@babel/helper-validator-identifier" "^7.16.7" to-fast-properties "^2.0.0" +"@babel/types@^7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.22.5.tgz#cd93eeaab025880a3a47ec881f4b096a5b786fbe" + integrity sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA== + dependencies: + "@babel/helper-string-parser" "^7.22.5" + "@babel/helper-validator-identifier" "^7.22.5" + to-fast-properties "^2.0.0" + "@bcoe/v8-coverage@^0.2.3": version "0.2.3" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" @@ -1145,6 +1266,20 @@ "@jridgewell/set-array" "^1.0.0" "@jridgewell/sourcemap-codec" "^1.4.10" +"@jridgewell/gen-mapping@^0.3.2": + version "0.3.3" + resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz#7e02e6eb5df901aaedb08514203b096614024098" + integrity sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ== + dependencies: + "@jridgewell/set-array" "^1.0.1" + "@jridgewell/sourcemap-codec" "^1.4.10" + "@jridgewell/trace-mapping" "^0.3.9" + +"@jridgewell/resolve-uri@3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78" + integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w== + "@jridgewell/resolve-uri@^3.0.3": version "3.0.6" resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.0.6.tgz#4ac237f4dabc8dd93330386907b97591801f7352" @@ -1155,6 +1290,16 @@ resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.0.tgz#1179863356ac8fbea64a5a4bcde93a4871012c01" integrity sha512-SfJxIxNVYLTsKwzB3MoOQ1yxf4w/E6MdkvTgrgAt1bfxjSrLUoHMKrDOykwN14q65waezZIdqDneUIPh4/sKxg== +"@jridgewell/set-array@^1.0.1": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72" + integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw== + +"@jridgewell/sourcemap-codec@1.4.14": + version "1.4.14" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24" + integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== + "@jridgewell/sourcemap-codec@^1.4.10": version "1.4.11" resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.11.tgz#771a1d8d744eeb71b6adb35808e1a6c7b9b8c8ec" @@ -1168,6 +1313,14 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" +"@jridgewell/trace-mapping@^0.3.17": + version "0.3.18" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.18.tgz#25783b2086daf6ff1dcb53c9249ae480e4dd4cd6" + integrity sha512-w+niJYzMHdd7USdiH2U6869nqhD2nbfZXND5Yp93qIbEmnDNk7PD48o+YchRVpzMU7M6jVCbenTR7PA1FLQ9pA== + dependencies: + "@jridgewell/resolve-uri" "3.1.0" + "@jridgewell/sourcemap-codec" "1.4.14" + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -1570,6 +1723,26 @@ resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.2.1.tgz#31624a7a505fb14da1d58023725a4c5f270e6a81" integrity sha512-QOi5OW45e2R20VygMSNhyQHvpdUwQZqGPc748JLGCYEy+yp8fNFNdbNIGAgZmi9e+2JHPd6i6idRuqivyicIkA== +"@vue/babel-helper-vue-transform-on@^1.1.5": + version "1.1.5" + resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-transform-on/-/babel-helper-vue-transform-on-1.1.5.tgz#a976486b21e108e545524fe41ffe3fc9bbc28c7f" + integrity sha512-SgUymFpMoAyWeYWLAY+MkCK3QEROsiUnfaw5zxOVD/M64KQs8D/4oK6Q5omVA2hnvEOE0SCkH2TZxs/jnnUj7w== + +"@vue/babel-plugin-jsx@^1.1.5": + version "1.1.5" + resolved "https://registry.yarnpkg.com/@vue/babel-plugin-jsx/-/babel-plugin-jsx-1.1.5.tgz#5088bae7dbb83531d94df3742ff650c12fd54973" + integrity sha512-nKs1/Bg9U1n3qSWnsHhCVQtAzI6aQXqua8j/bZrau8ywT1ilXQbK4FwEJGmU8fV7tcpuFvWmmN7TMmV1OBma1g== + dependencies: + "@babel/helper-module-imports" "^7.22.5" + "@babel/plugin-syntax-jsx" "^7.22.5" + "@babel/template" "^7.22.5" + "@babel/traverse" "^7.22.5" + "@babel/types" "^7.22.5" + "@vue/babel-helper-vue-transform-on" "^1.1.5" + camelcase "^6.3.0" + html-tags "^3.3.1" + svg-tags "^1.0.0" + "@vue/babel-plugin-transform-vue-jsx@^1.2.1": version "1.2.1" resolved "https://registry.yarnpkg.com/@vue/babel-plugin-transform-vue-jsx/-/babel-plugin-transform-vue-jsx-1.2.1.tgz#646046c652c2f0242727f34519d917b064041ed7" @@ -2701,6 +2874,11 @@ camelcase@^6.2.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809" integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg== +camelcase@^6.3.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a" + integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== + caniuse-lite@^1.0.30001370: version "1.0.30001384" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001384.tgz#029527c2d781a3cfef13fa63b3a78a6088e35973" @@ -5089,6 +5267,11 @@ html-tags@^2.0.0: resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-2.0.0.tgz#10b30a386085f43cede353cc8fa7cb0deeea668b" integrity sha1-ELMKOGCF9Dzt41PMj6fLDe7qZos= +html-tags@^3.3.1: + version "3.3.1" + resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.3.1.tgz#a04026a18c882e4bba8a01a3d39cfe465d40b5ce" + integrity sha512-ztqyC3kLto0e9WbNp0aeP+M3kTt+nbaIveGmUxAtZa+8iFgKLUOD4YKM5j+f3QD89bra7UeumolZHKuOXnTmeQ== + http-cache-semantics@^3.8.1: version "3.8.1" resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-3.8.1.tgz#39b0e16add9b605bf0a9ef3d9daaf4843b4cacd2" @@ -10677,7 +10860,7 @@ vue-template-es2015-compiler@^1.9.0: "vue2-sass-importer-lib@file:e2e/2.x/sass-importer/lib": version "1.0.0" dependencies: - vue2-sass-importer-sass-lib "file:../../Library/Caches/Yarn/v6/npm-vue2-sass-importer-lib-1.0.0-7ea9c798-4187-4843-8438-890703751297-1658071612744/node_modules/sass-lib-v1" + vue2-sass-importer-sass-lib "file:../../Library/Caches/Yarn/v6/npm-vue2-sass-importer-lib-1.0.0-ccaeac9e-c707-4bf2-843f-2b6514207308-1690815365364/node_modules/sass-lib-v1" "vue2-sass-importer-sass-lib@file:e2e/2.x/sass-importer/sass-lib-v1": version "1.0.0" @@ -10688,7 +10871,7 @@ vue-template-es2015-compiler@^1.9.0: "vue3-sass-importer-lib@file:e2e/3.x/sass-importer/lib": version "1.0.0" dependencies: - vue3-sass-importer-sass-lib "file:../../Library/Caches/Yarn/v6/npm-vue3-sass-importer-lib-1.0.0-6f2c27b2-1a8d-453e-a6a3-12b82bb6e5f4-1658071612745/node_modules/sass-lib-v1" + vue3-sass-importer-sass-lib "file:../../Library/Caches/Yarn/v6/npm-vue3-sass-importer-lib-1.0.0-32edd869-08a1-4b33-835d-626fdeb0344c-1690815365364/node_modules/sass-lib-v1" "vue3-sass-importer-sass-lib@file:e2e/3.x/sass-importer/sass-lib-v1": version "1.0.0" From d7a9494be14bbb4ecf41df9184ab1447695f9a33 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Mon, 7 Aug 2023 09:02:21 +1000 Subject: [PATCH 15/19] publish: 29.2.5 --- packages/vue2-jest/package.json | 2 +- packages/vue3-jest/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vue2-jest/package.json b/packages/vue2-jest/package.json index a05f7503..f26c9a5d 100644 --- a/packages/vue2-jest/package.json +++ b/packages/vue2-jest/package.json @@ -1,6 +1,6 @@ { "name": "@vue/vue2-jest", - "version": "29.2.4", + "version": "29.2.5", "description": "Jest transformer for Vue 2", "main": "lib/index.js", "files": [ diff --git a/packages/vue3-jest/package.json b/packages/vue3-jest/package.json index 550f02b7..c56199a0 100644 --- a/packages/vue3-jest/package.json +++ b/packages/vue3-jest/package.json @@ -1,6 +1,6 @@ { "name": "@vue/vue3-jest", - "version": "29.2.4", + "version": "29.2.5", "description": "Jest Vue transform", "main": "lib/index.js", "files": [ From ec7448203f911c64943d96d0ee0ef1596b3f2d5b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Aug 2023 10:00:50 +1000 Subject: [PATCH 16/19] chore(deps): bump json5 from 1.0.1 to 1.0.2 (#526) Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2. - [Release notes](https://github.com/json5/json5/releases) - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md) - [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2) --- updated-dependencies: - dependency-name: json5 dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Lachlan Miller --- yarn.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/yarn.lock b/yarn.lock index dcebc9d4..f3258efa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6530,9 +6530,9 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1: integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus= json5@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.1.tgz#779fb0018604fa854eacbf6252180d83543e3dbe" - integrity sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow== + version "1.0.2" + resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593" + integrity sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA== dependencies: minimist "^1.2.0" @@ -7410,9 +7410,9 @@ minimist-options@^3.0.1: is-plain-obj "^1.1.0" minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.5: - version "1.2.5" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" - integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== + version "1.2.7" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18" + integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g== minipass@^2.3.5, minipass@^2.6.0, minipass@^2.9.0: version "2.9.0" @@ -10860,7 +10860,7 @@ vue-template-es2015-compiler@^1.9.0: "vue2-sass-importer-lib@file:e2e/2.x/sass-importer/lib": version "1.0.0" dependencies: - vue2-sass-importer-sass-lib "file:../../Library/Caches/Yarn/v6/npm-vue2-sass-importer-lib-1.0.0-ccaeac9e-c707-4bf2-843f-2b6514207308-1690815365364/node_modules/sass-lib-v1" + vue2-sass-importer-sass-lib "file:../../../Library/Caches/Yarn/v6/npm-vue2-sass-importer-lib-1.0.0-c8ecb622-3c66-45e7-a49b-7fe0cf212f02-1691365665246/node_modules/sass-lib-v1" "vue2-sass-importer-sass-lib@file:e2e/2.x/sass-importer/sass-lib-v1": version "1.0.0" @@ -10871,7 +10871,7 @@ vue-template-es2015-compiler@^1.9.0: "vue3-sass-importer-lib@file:e2e/3.x/sass-importer/lib": version "1.0.0" dependencies: - vue3-sass-importer-sass-lib "file:../../Library/Caches/Yarn/v6/npm-vue3-sass-importer-lib-1.0.0-32edd869-08a1-4b33-835d-626fdeb0344c-1690815365364/node_modules/sass-lib-v1" + vue3-sass-importer-sass-lib "file:../../../Library/Caches/Yarn/v6/npm-vue3-sass-importer-lib-1.0.0-8ffc19e9-f75c-4094-8154-77cbd93d14ce-1691365665246/node_modules/sass-lib-v1" "vue3-sass-importer-sass-lib@file:e2e/3.x/sass-importer/sass-lib-v1": version "1.0.0" From b0c843a5e71d259df51dee23ba4390085f244db2 Mon Sep 17 00:00:00 2001 From: Pierre-Michel Brown Date: Thu, 7 Sep 2023 00:47:51 +0200 Subject: [PATCH 17/19] fix: allow importing relative paths in global resources (#548) --- e2e/2.x/style/colors.less | 1 + e2e/2.x/style/colors.scss | 1 + e2e/2.x/style/variables.less | 4 +++- e2e/2.x/style/variables.scss | 4 +++- e2e/3.x/style/colors.less | 1 + e2e/3.x/style/colors.scss | 1 + e2e/3.x/style/variables.less | 4 +++- e2e/3.x/style/variables.scss | 4 +++- packages/vue2-jest/lib/process-style.js | 19 ++++++++++++++----- packages/vue3-jest/lib/process-style.js | 19 ++++++++++++++----- 10 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 e2e/2.x/style/colors.less create mode 100644 e2e/2.x/style/colors.scss create mode 100644 e2e/3.x/style/colors.less create mode 100644 e2e/3.x/style/colors.scss diff --git a/e2e/2.x/style/colors.less b/e2e/2.x/style/colors.less new file mode 100644 index 00000000..7b9ea3f9 --- /dev/null +++ b/e2e/2.x/style/colors.less @@ -0,0 +1 @@ +@primary-color: "red"; diff --git a/e2e/2.x/style/colors.scss b/e2e/2.x/style/colors.scss new file mode 100644 index 00000000..d7cf8edb --- /dev/null +++ b/e2e/2.x/style/colors.scss @@ -0,0 +1 @@ +$primary-color: #333; diff --git a/e2e/2.x/style/variables.less b/e2e/2.x/style/variables.less index 7b9ea3f9..57319a4a 100644 --- a/e2e/2.x/style/variables.less +++ b/e2e/2.x/style/variables.less @@ -1 +1,3 @@ -@primary-color: "red"; +@import "./colors.less"; + +@font-size: 16px; diff --git a/e2e/2.x/style/variables.scss b/e2e/2.x/style/variables.scss index d7cf8edb..4f8d9064 100644 --- a/e2e/2.x/style/variables.scss +++ b/e2e/2.x/style/variables.scss @@ -1 +1,3 @@ -$primary-color: #333; +@import './colors.scss'; + +$font-size: 16px; diff --git a/e2e/3.x/style/colors.less b/e2e/3.x/style/colors.less new file mode 100644 index 00000000..7b9ea3f9 --- /dev/null +++ b/e2e/3.x/style/colors.less @@ -0,0 +1 @@ +@primary-color: "red"; diff --git a/e2e/3.x/style/colors.scss b/e2e/3.x/style/colors.scss new file mode 100644 index 00000000..d7cf8edb --- /dev/null +++ b/e2e/3.x/style/colors.scss @@ -0,0 +1 @@ +$primary-color: #333; diff --git a/e2e/3.x/style/variables.less b/e2e/3.x/style/variables.less index 7b9ea3f9..57319a4a 100644 --- a/e2e/3.x/style/variables.less +++ b/e2e/3.x/style/variables.less @@ -1 +1,3 @@ -@primary-color: "red"; +@import "./colors.less"; + +@font-size: 16px; diff --git a/e2e/3.x/style/variables.scss b/e2e/3.x/style/variables.scss index d7cf8edb..4f8d9064 100644 --- a/e2e/3.x/style/variables.scss +++ b/e2e/3.x/style/variables.scss @@ -1 +1,3 @@ -$primary-color: #333; +@import './colors.scss'; + +$font-size: 16px; diff --git a/packages/vue2-jest/lib/process-style.js b/packages/vue2-jest/lib/process-style.js index 538705ba..049e0c6b 100644 --- a/packages/vue2-jest/lib/process-style.js +++ b/packages/vue2-jest/lib/process-style.js @@ -1,5 +1,4 @@ const path = require('path') -const fs = require('fs') const cssTree = require('css-tree') const getVueJestConfig = require('./utils').getVueJestConfig const compileStyle = require('@vue/component-compiler-utils').compileStyle @@ -12,14 +11,23 @@ function getGlobalResources(resources, lang) { let globalResources = '' if (resources && resources[lang]) { globalResources = resources[lang] - .map(resource => path.resolve(process.cwd(), resource)) - .filter(resourcePath => fs.existsSync(resourcePath)) - .map(resourcePath => fs.readFileSync(resourcePath).toString()) - .join('\n') + .map(resource => { + const absolutePath = path.resolve(process.cwd(), resource) + return `${getImportLine(lang, absolutePath)}\n` + }) + .join('') } return globalResources } +function getImportLine(lang, filePath) { + const importLines = { + default: `@import "${filePath}";`, + sass: `@import "${filePath}"` + } + return importLines[lang] || importLines.default +} + function extractClassMap(cssCode) { const ast = cssTree.parse(cssCode) @@ -35,6 +43,7 @@ function extractClassMap(cssCode) { function getPreprocessOptions(lang, filePath, jestConfig) { if (lang === 'scss' || lang === 'sass') { return { + filename: filePath, importer: (url, prev, done) => ({ file: applyModuleNameMapper( url, diff --git a/packages/vue3-jest/lib/process-style.js b/packages/vue3-jest/lib/process-style.js index 578c9492..93adb48a 100644 --- a/packages/vue3-jest/lib/process-style.js +++ b/packages/vue3-jest/lib/process-style.js @@ -1,6 +1,5 @@ const { compileStyle } = require('@vue/compiler-sfc') const path = require('path') -const fs = require('fs') const cssTree = require('css-tree') const getVueJestConfig = require('./utils').getVueJestConfig const applyModuleNameMapper = require('./module-name-mapper-helper') @@ -12,14 +11,23 @@ function getGlobalResources(resources, lang) { let globalResources = '' if (resources && resources[lang]) { globalResources = resources[lang] - .map(resource => path.resolve(process.cwd(), resource)) - .filter(resourcePath => fs.existsSync(resourcePath)) - .map(resourcePath => fs.readFileSync(resourcePath).toString()) - .join('\n') + .map(resource => { + const absolutePath = path.resolve(process.cwd(), resource) + return `${getImportLine(lang, absolutePath)}\n` + }) + .join('') } return globalResources } +function getImportLine(lang, filePath) { + const importLines = { + default: `@import "${filePath}";`, + sass: `@import "${filePath}"` + } + return importLines[lang] || importLines.default +} + function extractClassMap(cssCode) { const ast = cssTree.parse(cssCode) @@ -35,6 +43,7 @@ function extractClassMap(cssCode) { function getPreprocessOptions(lang, filePath, jestConfig) { if (lang === 'scss' || lang === 'sass') { return { + filename: filePath, importer: (url, prev) => ({ file: applyModuleNameMapper( url, From d61d430c8f673cb4576afc91e85479ab4f7e6b34 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Thu, 7 Sep 2023 08:57:53 +1000 Subject: [PATCH 18/19] publish: 29.2.6 --- packages/vue2-jest/package.json | 2 +- packages/vue3-jest/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vue2-jest/package.json b/packages/vue2-jest/package.json index f26c9a5d..dd3f45a9 100644 --- a/packages/vue2-jest/package.json +++ b/packages/vue2-jest/package.json @@ -1,6 +1,6 @@ { "name": "@vue/vue2-jest", - "version": "29.2.5", + "version": "29.2.6", "description": "Jest transformer for Vue 2", "main": "lib/index.js", "files": [ diff --git a/packages/vue3-jest/package.json b/packages/vue3-jest/package.json index c56199a0..42819995 100644 --- a/packages/vue3-jest/package.json +++ b/packages/vue3-jest/package.json @@ -1,6 +1,6 @@ { "name": "@vue/vue3-jest", - "version": "29.2.5", + "version": "29.2.6", "description": "Jest Vue transform", "main": "lib/index.js", "files": [ From de5af783559cda0bb770f484f80c4d9b32cfe300 Mon Sep 17 00:00:00 2001 From: Jurriaan van Hengel <15790266+hngl@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:59:49 +0100 Subject: [PATCH 19/19] docs: Jest globals key is always `vue-jest` (#519) The key used to get config is `vue-jest` in both [`@vue/vue2-jest`](https://github.com/vuejs/vue-jest/blob/3dc76ff8491d149d89a8ba5deb02f517f1535f98/packages/vue2-jest/lib/utils.js#L57) and [`@vue/vue3-jest`](https://github.com/vuejs/vue-jest/blob/3dc76ff8491d149d89a8ba5deb02f517f1535f98/packages/vue3-jest/lib/utils.js#L57), not the respective Vue/Jest version dependant package variant name. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f0e92bad..38e53f22 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ A `package.json` Example "^.+\\.vue$": "@vue/vue2-jest" }, "globals": { - "@vue/vue2-jest": { + "vue-jest": { "transform": { "your-custom-block": "./custom-block-processor.js" } @@ -135,7 +135,7 @@ A `jest.config.js` Example - If you're using a dedicated configuration file like ```js module.exports = { globals: { - '@vue/vue2-jest': { + 'vue-jest': { transform: { 'your-custom-block': require('./custom-block-processor') } @@ -170,7 +170,7 @@ You can provide [TemplateCompileOptions](https://github.com/vuejs/component-comp { "jest": { "globals": { - "@vue/vue2-jest": { + "vue-jest": { "templateCompiler": { "transpileOptions": { "transforms": { @@ -195,7 +195,7 @@ You can provide [TemplateCompileOptions](https://github.com/vuejs/component-comp { "jest": { "globals": { - "@vue/vue2-jest": { + "vue-jest": { "pug": { "basedir": "mybasedir" }