vuejs / vue-jest

Jest Vue transformer
MIT License
748 stars 156 forks source link

[vue-jest] Error: Vue template compilation failed #563

Open 498755303 opened 3 months ago

498755303 commented 3 months ago

When executing the test, an error occurred [vue-jest] Error: Vue template compilation failed

package.json "vue": "^2.7.0", "vue-template-compiler": "^2.7.0", "@babel/core": "^7.21.0", "@babel/eslint-parser": "^7.12.16", "@babel/preset-env": "7.18.0", "@vue/cli-plugin-unit-jest": "~5.0.0",
"@vue/test-utils": "^1.1.3",
"@vue/vue2-jest": "^27.0.0-alpha.2",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^27.0.6",
"jest": "^27.0.5",
"jest-environment-jsdom": "^27.0.6"

jest.config.js

const path = require('path');

module.exports = { preset: '@vue/cli-plugin-unit-jest', rootDir: path.resolve(__dirname, '../'), testEnvironment: 'jsdom', testMatch: [ '/src/views/other/unit-demo/*/.spec.js', ], moduleFileExtensions: ['js', 'jsx', 'json', 'vue'], transform: { '^.+\.vue$': '@vue/vue2-jest', '.+\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub', '^.+\.[t|j]sx?$': 'babel-jest', }, moduleNameMapper: { '^@/(.*)$': '/src/$1' },
collectCoverage: true, coveragePathIgnorePatterns: ['/node_modules'], coverageDirectory: '/tests/coverage', reporters: [ 'default',
['./node_modules/jest-html-reporter', { pageTitle: 'report',
outputPath: './tests/report/test-report.html', }], ] };