Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

904 B
Raw Blame
// ./snapshot-resolver.js
const path = require('path')

// 👉 process.env.TEST_ROOT will only be available in --index-json or --stories-json mode.
// if you run this code without these flags, you will have to override it the test root, else it will break.
// e.g. process.env.TEST_ROOT = process.cwd()

module.exports = {
    resolveSnapshotPath: (testPath, snapshotExtension) => {
        // Save inside __snapshots__ folder at same level as test file
        const testDirectory = path.dirname(testPath)
        const testName = path.basename(testPath)
        return path.join(testDirectory, '__snapshots__', testName + snapshotExtension)
    },

    resolveTestPath: (snapshotFilePath) => {
        const testPath = snapshotFilePath.replace('__snapshots__/', '').replace(/\.snap$/, '')
        return testPath
    },

    testPathForConsistencyCheck: path.join(process.cwd(), 'example.test.js'),
}