Skip to content

Source maps for vue2 SFCs using TS are not created/wrongly created for v28 #474

Closed
@phloose

Description

@phloose

After upgrading to Jest v28 SFCs that are using TypeScript and the Composition-API plugin for Vue2 are producing a weird error:

FAIL  ***/FormDateInput.spec.ts
  ● Test suite failed to run

    No element indexed by 61

      4 | import Vue from 'vue';
      5 |
    > 6 | import FormDateInput from './FormDateInput.vue';
        | ^
      7 |
      8 | const localVue = createLocalVue();
      9 |

      at ArraySet_at [as at] (node_modules/source-map/lib/array-set.js:92:9)
      at BasicSourceMapConsumer.SourceMapConsumer_originalPositionFor [as originalPositionFor] (node_modules/source-map/lib/source-map-consumer.js:626:30)
      at node_modules/@vue/vue2-jest/lib/generate-source-map.js:29:28
          at Array.forEach (<anonymous>)
      at generateSourceMap (node_modules/@vue/vue2-jest/lib/generate-source-map.js:26:38)
      at Object.module.exports [as process] (node_modules/@vue/vue2-jest/lib/process.js:129:15)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:619:31)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:765:40)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:822:19)
      at Object.<anonymous> (***/FormDateInput.spec.ts:6:1)

It seems to me, that vue2-jest cannot produce source-maps or creates them i a way that is not consumable by the underlying source-map lib.

Relevant packages installed in a node 16 environment with npm 8 are:

  • "@vue/vue2-jest": "^28.0.0"
  • "jest": "^28.1.0"
  • "ts-jest": "^28.0.2"
  • "typescript": "^4.6.3"

I know that these version do not match exactly, but it makes no difference: Even if i downgrade all to exactly v28.0.0 it does not work

The transformers property lists @vue/vue2-jest correctly for transforming vue files, which also worked for vue-jest v27 and jest 27. I have also tried to include the full path in node modules like <rootDir>/node_modules/@vue/vue2-jest, but without success.

  transform: {
    '.*\\.(vue)$': '@vue/vue2-jest',
    '.*\\.(js)$': 'babel-jest',
    '.*\\.(ts)$': 'ts-jest',
  },

Unfortunatly i cannot include a repo link since its proprietary software.

Am i missing something in the way to upgrade to jest v28 or is this a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions