在 运行 时尝试使用默认配置和预设未找到的 vue-test-utils-getting-started

Trying vue-test-utils-getting-started with default config and Preset Not Found when run

我正在尝试按照 the official guide 克隆演示存储库 vue-test-utils-getting-started

进行单元测试

复制步骤

  1. npm install(克隆 vue-test-utils-getting-started 后仅 运行 一次)
  2. 因为文件准备好了,运行 npm test 可以看到下面的错误
● Validation Error:

  Preset @vue/cli-plugin-unit-jest/presets/no-babel/jest-preset.js not found.

  Configuration Documentation:
  https://facebook.github.io/jest/docs/configuration.html

如果 cat 文件

cat @vue/cli-plugin-unit-jest/presets/no-babel/jest-preset.js

it does display the content meaning that the file does exist in the path

如果注释掉该行,就可以了。加载预设文件的机制似乎有问题。 有谁知道如何正确加载预设吗?

// jest.config.js

module.exports = {
  // this is installed by default, but not working, many people encounters, "not found" but file exists 
  // preset: '@vue/cli-plugin-unit-jest/presets/no-babel'
}

刚查到原因

因为vue-test-utils-getting-started使用旧版本jest,发现preset路径读取问题。因此,将所有软件包更新到最新版本即可解决。

vue-test-utils-getting-started 存储库的补充说明。最后一次更新是 3 年前。所以,万一有人遇到类似的事情。如果使用具有节点包依赖性的旧存储库,则内部定义的旧版本可能是问题所在。 无论如何感谢访问这个问题的人。已解决。