首页 > 解决方案 > 无法从 xxx.vue jest 收集报道

问题描述

我运行时得到了这个日志yarn test。我试图删除 node_modules,重新安装所有依赖项并运行yarn test --no-cache,但它不起作用。

yarn run v1.22.10
$ jest --coverage
 PASS  __test__/src/App.test.ts
  √ test1 (2 ms)

Running coverage on untested files...Failed to collect coverage from D:\svn-frontend-admin\src\App.vue
ERROR: Unexpected token ] in JSON at position 6179
STACK: SyntaxError: Unexpected token ] in JSON at position 6179

这些是我的配置文件

// jest.config.js
module.exports = {
  ......

  preset: 'ts-jest',
  collectCoverage: true,
  collectCoverageFrom: ['src/**/*.{js,ts,vue}', 'src/*.{ts,vue}'],
  coverageReporters: ['clover'],
  moduleFileExtensions: ['js', 'ts', 'tsx', 'json', 'vue'],
  transform: {
    '.*\\.(vue)$': 'vue-jest',
    '^.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': require.resolve('jest-transform-stub'),
    '^.+\\.tsx?$': 'ts-jest',
    '^.+\\.jsx?$': 'babel-jest',
  },
  transformIgnorePatterns: [
    'node_modules/(?!(@babel/runtime-corejs3/helpers/esm/.*)|(vue/dist/.*))'
  ],

  ......
};

标签: jestjs

解决方案


推荐阅读