-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsnapshot.test.js
More file actions
90 lines (75 loc) · 2.13 KB
/
snapshot.test.js
File metadata and controls
90 lines (75 loc) · 2.13 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { snapshot, serialize, deserialize } from './snapshot.js'
import fc from 'fast-check'
import fs from 'fs'
import Steps from './experimental/scenario.js'
const { Given, When, Then, After, Scenario } = Steps()
const snapshotFile = 'snapshot.temp.test.psnap'
Given('a new snapshot', function () {
this.snapshot = snapshot(snapshotFile)
})
When('I set {key} to {value}', async function ({ key, value }) {
await this.snapshot.set(key, value)
this.text = fs.readFileSync(snapshotFile).toString()
})
Then('{key} should be {value}', async function ({ key, value }) {
if ((await this.snapshot.find(key)).value !== value) throw new Error('The record does not have the correct value')
})
When('I delete {key}', async function ({ key }) {
await this.snapshot.remove(key)
this.text = fs.readFileSync(snapshotFile).toString()
})
Then('{key} should not exist', async function () {
if ((await this.snapshot.find('hello')).exists) throw new Error('The record exists though it should not')
})
After('I should clean up', function () {
fs.unlinkSync(snapshotFile)
delete this.snapshot
})
/**
* @test { key: 'hello', value: 'world' }
*/
export const SimulateSnapshot = Scenario`
Given a new snapshot
When I set {key} to {value}
Then {key} should be {value}
After I should clean up
`
/**
* @test { key: 'hello', value: 'world' }
*/
export const SimulateSnapshotWithDeletion = Scenario`
Given a new snapshot
When I set {key} to {value}
Then {key} should be {value}
When I delete {key}
Then {key} should not exist
After I should clean up
`
/**
* @pineapple_define Characters
*/
export const Characters = () => {
return {
Backslash: '\\'
}
}
/**
* @pineapple_define Snapshots
*/
export const Arbitraries = () => {
return {
Text: fc.string().filter(text => !text.endsWith('\\'))
}
}
/**
* @test void
*/
export const SnapshotUnicode = () => '\u1516\u1596\u4851'
/**
* We need to test ' \\' because it fails, however everything else serializes properly.
* @test #Snapshots.Text resolves args.0
* @no-test #anything resolves args.0
*/
export function serializeAndDeserialize (value) {
return deserialize(serialize(value))
}