lib/snapshot.js
// should only ever call _one_ of read/save
should only ever call _one_ of read/save
should only ever call _one_ of read / save
read (message) {
    const index = +this.indexes.get(message) || 1
    this.indexes.set(message, index + 1)
    try {
      if (!fs.statSync(this.file).isFile())
        throw 'not a file'
      this.snapshot = this.snapshot || require(this.file)
    } catch {
      throw new Error(
        'Snapshot file not found: ' + this.file + '\n' +
        'Run with TAP_SNAPSHOT=1 in the environment\n' +
        'to create snapshot files'
      )
    }
    const entry = message + ' ' + index
    const s = this.snapshot[entry]
    if (s === undefined)
      throw new Error(
        'Snapshot entry not found: "' + entry + '"\n' +
        'Run with TAP_SNAPSHOT=1 in the environment\n' +
        'to create snapshots'
      )
    return s.replace(/^\n|\n$/g, '')
  }
read ( message ) { const index = + this . indexes . get ( message ) || 1 this . indexes . set ( message , index + 1 ) try { if ( ! fs . statSync ( this . file ) . isFile ( ) ) throw 'not a file' this . snapshot = this . snapshot || require ( this . file ) } catch { throw new Error ( 'Snapshot file not found: ' + this . file + '\n' + 'Run with TAP_SNAPSHOT=1 in the environment\n' + 'to create snapshot files' ) } const entry = message + ' ' + index const s = this . snapshot [ entry ] if ( s === undefined ) throw new Error ( 'Snapshot entry not found: "' + entry + '"\n' + 'Run with TAP_SNAPSHOT=1 in the environment\n' + 'to create snapshots' ) return s . replace ( / ^\n|\n$ / g , '' ) }
should only ever call _one_ of read/save
should only ever call _one_ of read / save
// throw before the require() for missing file, because node // caches module load errors, and we might create it at some point.