This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport.test.ts
193 lines (137 loc) · 4.34 KB
/
report.test.ts
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import test from "ava";
import analyse from "./analyse";
import report from "./report";
import * as path from "path";
import { SnapshotAnalysis } from "./types";
let analysis: SnapshotAnalysis;
const simpleKey = "1. snapshot for simple-rn-component 1";
const listKey = "2. snapshot for list-rn-component 1";
const primitivesKey = "0. snapshot for primitives 1";
const lengthKey = "6. snapshot for length-tests 1";
const hugeKey = "8. snapshot for huge-style 1";
test.before(async () => {
analysis = await analyse(
path.join(process.cwd(), "__snapshots__/generate-snapshots.js.snap")
);
});
test("should return no errors or warnings with no criteria", t => {
const criteria = {};
const result = report(criteria)(analysis);
t.snapshot(result);
});
test("should return no errors for an acceptable file size", t => {
const criteria = {
maxFileSize: 8000
};
const result = report(criteria)(analysis);
t.snapshot(result.errors);
});
test("should return an error for an unacceptable file size", t => {
const criteria = {
maxFileSize: 2000
};
const result = report(criteria)(analysis);
t.snapshot(result.errors);
});
test(`should return no errors for a "good" snapshot`, t => {
const criteria = {
genericAttrs: ["initialNumToRender", "onContentSizeChange"],
genericValues: ["[Function]"],
maxAttr: 10,
maxAttrLength: 200,
maxDepth: 8,
maxLines: 20
};
const result = report(criteria)(analysis);
const simpleComponentLints = result.lints.find(
({ key }) => key === simpleKey
);
t.snapshot(simpleComponentLints);
});
test("should return the generic attribute error", t => {
const criteria = {
genericAttrs: ["initialNumToRender", "onContentSizeChange"]
};
const result = report(criteria)(analysis);
const listComponentLints = result.lints.find(({ key }) => key === listKey);
t.snapshot(listComponentLints);
});
test("should return the generic value error", t => {
const criteria = {
genericValues: ["[Function]"]
};
const result = report(criteria)(analysis);
const listComponentLints = result.lints.find(({ key }) => key === listKey);
t.snapshot(listComponentLints);
});
test("should return the max attribute error", t => {
const criteria = {
maxAttr: 2
};
const result = report(criteria)(analysis);
const simpleComponentLints = result.lints.find(
({ key }) => key === simpleKey
);
t.snapshot(simpleComponentLints);
});
test("should return the max attribute length error for a string", t => {
const criteria = {
maxAttrStringLength: 20
};
const result = report(criteria)(analysis);
const lengthComponentLints = result.lints.find(
({ key }) => key === lengthKey
);
t.snapshot(lengthComponentLints);
});
test("should return the max attribute length error for an array", t => {
const criteria = {
maxAttrArrayLength: 3
};
const result = report(criteria)(analysis);
const lengthComponentLints = result.lints.find(
({ key }) => key === lengthKey
);
t.snapshot(lengthComponentLints);
});
test("should not return the max attribute length error for an object", t => {
const criteria = {
maxAttrStringLength: 20,
maxAttrArrayLength: 3
};
const result = report(criteria)(analysis);
const hugeStyleLints = result.lints.find(({ key }) => key === hugeKey);
t.snapshot(hugeStyleLints);
});
test("should return the max depth error", t => {
const criteria = {
maxDepth: 4
};
const result = report(criteria)(analysis);
const listComponentLints = result.lints.find(({ key }) => key === listKey);
t.snapshot(listComponentLints);
});
test("should return the max lines error", t => {
const criteria = {
maxLines: 10
};
const result = report(criteria)(analysis);
const simpleComponentLints = result.lints.find(
({ key }) => key === simpleKey
);
t.snapshot(simpleComponentLints);
});
test("should return the max generic element warning", t => {
const criteria = {
maxGenericElement: 2
};
const result = report(criteria)(analysis);
const listComponentLints = result.lints.find(({ key }) => key === listKey);
t.snapshot(listComponentLints);
});
test("should return the no elements found warning", t => {
const criteria = {};
const result = report(criteria)(analysis);
const primitivesLints = result.lints.find(({ key }) => key === primitivesKey);
t.snapshot(primitivesLints);
});