Skip to content

Instantly share code, notes, and snippets.

@prescottprue
Created November 26, 2018 21:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prescottprue/5ece5e173bcfba7ed86dae6a91444451 to your computer and use it in GitHub Desktop.
Save prescottprue/5ece5e173bcfba7ed86dae6a91444451 to your computer and use it in GitHub Desktop.
Jest snapshot resolver for snapshots at top level of repo when tests are in component folders.
const path = require('path')
const rootDir = path.resolve(__dirname, '..')
module.exports = {
/** 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)
}
}
@aliankarali
Copy link

Nice. Needed to add testPathForConsistencyCheck: 'some/__tests__/example.test.js', at the end though (Jest 24.1.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment