File: snapshot.js

package info (click to toggle)
node-tap 12.0.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 3,996 kB
  • sloc: javascript: 13,674; sh: 75; makefile: 73
file content (50 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict'
const t = require('../')
const Snapshot = require('../lib/snapshot.js')
const rimraf = require('rimraf')
const mkdirp = require('mkdirp')
const path = require('path')
const dir = path.resolve(__dirname, 'snapshot')
const fs = require('fs')

t.test('cleanup first', t => {
  rimraf.sync(dir)
  mkdirp.sync(dir)
  process.chdir(dir)
  t.end()
})

t.test('actual test', t => {
  t.comment('not using subtests, because snapshots are per-test')

  t.test('checking snapshot without creating throws', t => {
    const s = new Snapshot(t)
    t.throws(_ => s.read('asdf', 'asdf'))
    t.end()
  })

  const s = new Snapshot(t)
  t.comment('create some snapshots')
  s.snap(fs.readFileSync(__filename, 'utf8'), 'this file')
  s.snap('this is fine', 'a statement of acceptance')
  s.save()

  t.comment('now check that the snapshots are valid')
  const ss = new Snapshot(t)
  t.equal(fs.readFileSync(__filename, 'utf8'), ss.read('this file'))
  t.equal('this is fine', ss.read('a statement of acceptance'))
  t.throws(_ => ss.read('this is not in the file'))

  t.comment('saving without snapping anything removes the file')
  const sss = new Snapshot(t)
  sss.save()
  t.throws(_ => fs.statSync(sss.file), 'file is gone')

  t.end()
})

t.test('cleanup after', t => {
  rimraf.sync(dir)
  process.chdir(__dirname)
  t.end()
})