配置 vue 的 jest 单元测试时报错如下:
Failed to write coverage reports: ERROR: Error: EEXIST: file already exists, mkdir 'xxx estscoveragevue-cli-3distjs' STACK: Error: EEXIST: file already exists, mkdir 'xxx estscoveragevue-cli-3distjs' at Object.mkdirSync (fs.js:738:3) at sync (xxx ode_modulesmkdirpindex.js:71:13) at sync (xxx ode_modulesmkdirpindex.js:77:24) at sync (xxx ode_modulesmkdirpindex.js:78:17) at sync (xxx ode_modulesmkdirpindex.js:78:17) at sync (xxx ode_modulesmkdirpindex.js:78:17) at sync (xxx ode_modulesmkdirpindex.js:78:17) at sync (xxx ode_modulesmkdirpindex.js:78:17) at sync (xxx ode_modulesmkdirpindex.js:78:17) at sync (xxx ode_modulesmkdirpindex.js:78:17)
百度、谷歌没有无果。后来修改了 jest.config.js 里的 collectCoverageFrom 匹配规格解决问题。
将
// jest.config.js model.export={ // ... collectCoverageFrom: [ '**/*.{js,vue}', '!**/node_modules/**' ], // ... }
改成
// jest.config.js model.export={ // ... collectCoverageFrom: [ 'src/**/*.{js,vue}', '!src/main.js', '!src/router/index.js', '!**/node_modules/**' ], // ... }