intlify / vue-i18n-jest

:globe_with_meridians: vue-jest wrapper for i18n custom blocks
MIT License
7 stars 4 forks source link

support for vue-jest@v5 #23

Open kazupon opened 3 years ago

XavierChevalier commented 2 years ago

It does not seem to support version 5. When I try to run tests, I have this exception:

 ● Test suite failed to run

  TypeError: codes.forEach is not a function

    at node_modules/@vue/vue3-jest/lib/generate-code.js:70:13
        at Array.forEach (<anonymous>)
    at generateCode (node_modules/@vue/vue3-jest/lib/generate-code.js:69:24)
    at Object.module.exports [as process] (node_modules/@vue/vue3-jest/lib/process.js:171:18)
    at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:620:31)
    at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:766:40)
    at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:823:19)

With this Jest configuration:

{
  // ...
  transform: {
    '^.+\\.ts$': 'ts-jest',
    '^.+\\.vue$': '@vue/vue3-jest',
  },
  globals: {
    'vue-jest': {
      transform: {
        i18n: 'vue-i18n-jest',
      },
    },
}

It's fail here:

https://github.com/vuejs/vue-jest/blob/6edfa9cd93be05ca4c9c41849db668dbf2ae92d5/packages/vue3-jest/lib/generate-code.js#L70-L72

I tried to debug, and the value of variable codes is a string:

"undefined.__i18n = ['{"en":{...},"fr":{...}}']"

This string is not iterable here.

My dependencies version:

"devDependencies": {
  "@babel/core": "^7.16.0",
  "@intlify/vite-plugin-vue-i18n": "^3.2.1",
  "@intlify/vue-i18n-loader": "^4.0.1",
  "@vue/test-utils": "^2.0.0-rc.16",
  "@vue/vue3-jest": "^27.0.0-alpha.4",
  "babel-loader": "^8.2.3",
  "jest": "^27.4.1",
  "ts-jest": "^27.0.7",
  "typescript": "^4.4.3",
  "vue-i18n-jest": "^1.1.1",
  "vue-loader": "^16.8.3",
  "vue-tsc": "^0.3.0"
}
XavierChevalier commented 2 years ago

After investigating, I tried to change the code to be compatible with vue-jest@5. I will open a PR soon.

Several changes are to be expected: