How to use the jest-snapshot.utils function in jest-snapshot

To help you get started, we’ve selected a few jest-snapshot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gimenete / github-jest-snapshots / lib / index.js View on Github external
files.forEach(file => {
      if (file.name === 'node_modules') return

      const fullPath = path.join(dir, file.name)
      if (file.isDirectory()) return traverseFiles(fullPath)

      const snapshotFile = path.join(dir, '__snapshots__', file.name + '.snap')
      if (fs.existsSync(snapshotFile)) {
        const snapshot = jestSnapshot.utils.getSnapshotData(snapshotFile)
        const code = fs.readFileSync(fullPath, 'utf-8')
        const ast = babelParser.parse(code)

        const paths = []
        let testName = null
        let snapshotNumber = 0

        const pushPath = path => {
          const last = paths[paths.length - 1]
          if (last && !last.isAncestor(path)) {
            snapshotNumber = 0
            paths.splice(0)
          }
          paths.push(path)
          testName = paths.map(pickStringArgument).join(' ')
        }