forked from jestjs/jest
/
get_snapshot_summary.test.js
122 lines (111 loc) · 2.55 KB
/
get_snapshot_summary.test.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
import getSnapshotSummary from '../get_snapshot_summary';
const UPDATE_COMMAND = 'press --u';
const globalConfig = {
rootDir: 'root',
};
test('creates a snapshot summary', () => {
const snapshots = {
added: 1,
didUpdate: false,
filesAdded: 1,
filesRemoved: 1,
filesRemovedList: [],
filesUnmatched: 1,
filesUpdated: 1,
matched: 2,
total: 2,
unchecked: 1,
uncheckedKeysByFile: [
{
filePath: 'path/to/suite_one',
keys: ['unchecked snapshot 1'],
},
],
unmatched: 1,
updated: 1,
};
expect(
getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND)
.join('\n')
.replace(/\\/g, '/'),
).toMatchSnapshot();
});
test('creates a snapshot summary after an update', () => {
const snapshots = {
added: 1,
didUpdate: true,
filesAdded: 1,
filesRemoved: 1,
filesRemovedList: [],
filesUnmatched: 1,
filesUpdated: 1,
unchecked: 1,
uncheckedKeysByFile: [
{
filePath: 'path/to/suite_one',
keys: ['unchecked snapshot 1'],
},
],
unmatched: 1,
updated: 1,
};
expect(
getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND)
.join('\n')
.replace(/\\/g, '/'),
).toMatchSnapshot();
});
it('creates a snapshot summary with multiple snapshot being written/updated', () => {
const snapshots = {
added: 2,
didUpdate: false,
filesAdded: 2,
filesRemoved: 2,
filesRemovedList: [],
filesUnmatched: 2,
filesUpdated: 2,
unchecked: 2,
uncheckedKeysByFile: [
{
filePath: 'path/to/suite_one',
keys: ['unchecked snapshot 1'],
},
{
filePath: 'path/to/suite_two',
keys: ['unchecked snapshot 2'],
},
],
unmatched: 2,
updated: 2,
};
expect(
getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND)
.join('\n')
.replace(/\\/g, '/'),
).toMatchSnapshot();
});
it('returns nothing if there are no updates', () => {
const snapshots = {
added: 0,
didUpdate: false,
filesAdded: 0,
filesRemoved: 0,
filesRemovedList: [],
filesUnmatched: 0,
filesUpdated: 0,
unchecked: 0,
uncheckedKeysByFile: [],
unmatched: 0,
updated: 0,
};
expect(
getSnapshotSummary(snapshots, globalConfig, UPDATE_COMMAND).join('\n'),
).toMatchSnapshot();
});