JuniorTour / vue-template-babel-compiler

Enable Optional Chaining(?.), Nullish Coalescing(??) and many new ES syntax for Vue.js SFC based on Babel
https://www.npmjs.com/package/vue-template-babel-compiler
118 stars 9 forks source link

[Bug] support for jest >= 29? #49

Open manzoliric opened 1 year ago

manzoliric commented 1 year ago

Current behavior

I'm using jest 29 and vue2-jest 29, do you have any plans to support?

Screenshot 2023-04-10 at 16 21 51

module.exports = {
  testEnvironment: 'jsdom',
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/$1',
    '^~/(.*)$': '<rootDir>/$1',
    '^vue$': 'vue/dist/vue.common.js'
  },
  moduleFileExtensions: ['js', 'vue', 'json'],
  transform: {
    '^.+\\.js$': 'babel-jest',
    '^.+\\.vue$': '@vue/vue2-jest',
    '^.+\\.svg$': '<rootDir>/libs/svg-transformer.js'
  },
  globals: {
    '@vue/vue2-jest': {
      templateCompiler: {
        compiler: require('vue-template-babel-compiler')
      }
    }
  },
  collectCoverage: true,
  coverageReporters: ['html', 'text-summary'],
  collectCoverageFrom: [
    '<rootDir>/components/**/*.vue',
    '<rootDir>/pages/**/*.vue'
  ]
};

Extra

JuniorTour commented 1 year ago

Thanks for your feedback.

This lib do work for jest@29+, DEMO: https://stackblitz.com/edit/github-kbx3q1?file=components%2FTutorial.vue,package.json

  "devDependencies": {
    "@vue/test-utils": "^1.3.4",
    "@vue/vue2-jest": "^29.2.3",
    "jest": "^29.5.0",
    "jest-environment-jsdom": "^29.5.0",
    "vue-template-babel-compiler": "^2.0.0"
  }

The error you got may be come from your wrong jest config of globals key,

image