如何强制玩笑在根lvl __snapshots__文件夹中输出快照?

问题描述 投票:1回答:1

我今天遇到了一个开玩笑的小问题,我的文件夹结构遵循此约定

components/
   Paragraph/
     index.js
     style.js
     test.js

当我运行jest快照测试时,它将在每个组件文件夹中生成它们,即>]

components/
   Paragraph/
     __snapshots__
     index.js
     style.js
     test.js

是否有办法强制开玩笑将所有快照放入根lvl __snapshot__文件夹中?所以最终输出看起来像这样

__snapshots__
   // All snapshots here?
components/
   Paragraph/
     index.js
     style.js
     test.js
<< [

package.json
中(或在jest.config.js中,如果使用的话)将路径添加到snapshotResolver文件中
"jest": { "snapshotResolver": "./snapshotResolver.js" }
在根项目中,使用以下代码创建snapshotResolver.js文件:

const path = require('path') const rootDir = path.resolve(__dirname, '..') module.exports = { testPathForConsistencyCheck: 'some/__tests__/example.test.js', /** resolves from test to snapshot path */ resolveSnapshotPath: (testPath, snapshotExtension) => { return testPath.replace('src/', '__snapshots__/') + snapshotExtension }, /** resolves from snapshot to test path */ resolveTestPath: (snapshotFilePath, snapshotExtension) => { return snapshotFilePath .replace('__snapshots__/', 'src/') .slice(0, -snapshotExtension.length) }, }

https://gist.github.com/prescottprue/5ece5e173bcfba7ed86dae6a91444451
testing jest
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.