Skip to content

Commit cd20ef3

Browse files
committed
chore(tests): add RegExpArray snapshot serializer
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 28314c6 commit cd20ef3

13 files changed

+172
-183
lines changed

__tests__/setup/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*/
55

66
import './chai'
7+
import './serializers'

__tests__/setup/serializers/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @file Entry Point - Snapshot Serializers
3+
* @module tests/setup/serializers
4+
* @see https://vitest.dev/guide/snapshot.html#custom-serializer
5+
*/
6+
7+
import './regex-array'
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @file Snapshot Serializers - RegExpArray
3+
* @module tests/setup/serializers/regex-array
4+
*/
5+
6+
import type { RegExpArray } from '#tests/types'
7+
import { isNumber, isString, type Fn } from '@flex-development/tutils'
8+
import { get, omit } from 'radash'
9+
10+
expect.addSnapshotSerializer({
11+
/**
12+
* Prints the given `value`.
13+
*
14+
* @param {unknown} value - Value to print
15+
* @param {Fn<[unknown], string>} printer - Print function
16+
* @return {string} `value` as printable string
17+
*/
18+
print(value: unknown, printer: Fn<[unknown], string>): string {
19+
return printer(omit(value as RegExpArray, ['index', 'input']))
20+
},
21+
/**
22+
* Checks if the given `value` is a {@linkcode RegExpArray}.
23+
*
24+
* @param {unknown} value - Value to check
25+
* @return {value is RegExpArray} `true` if `value` is {@linkcode RegExpArray}
26+
*/
27+
test(value: unknown): value is RegExpArray {
28+
return (
29+
Array.isArray(value) &&
30+
isNumber(get(value, 'index')) &&
31+
isString(get(value, 'input'))
32+
)
33+
}
34+
})

__tests__/types/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @file Entry Point - Test Type Definitions
3+
* @module tests/types
4+
*/
5+
6+
export type { default as RegExpArray } from './reg-exp-array'

__tests__/types/reg-exp-array.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @file Test Type Definitions - RegExpArray
3+
* @module tests/types/RegExpArray
4+
*/
5+
6+
/**
7+
* A {@linkcode RegExpExecArray} or {@linkcode RegExpMatchArray}.
8+
*/
9+
type RegExpArray = RegExpExecArray | RegExpMatchArray
10+
11+
export type { RegExpArray as default }

src/__snapshots__/export-aggregate.snap

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ exports[`unit:EXPORT_AGGREGATE_REGEX > exports > should match named export(s) in
3838
"specifier": "./lib",
3939
"type": undefined,
4040
},
41-
"index": 0,
4241
}
4342
`;
4443

@@ -53,7 +52,6 @@ exports[`unit:EXPORT_AGGREGATE_REGEX > exports > should match named export(s) in
5352
"specifier": "#src",
5453
"type": undefined,
5554
},
56-
"index": 0,
5755
}
5856
`;
5957

@@ -80,7 +78,6 @@ exports[`unit:EXPORT_AGGREGATE_REGEX > exports > should match named type export(
8078
"specifier": "@flex-development/tutils",
8179
"type": "type",
8280
},
83-
"index": 0,
8481
}
8582
`;
8683

@@ -95,7 +92,6 @@ exports[`unit:EXPORT_AGGREGATE_REGEX > exports > should match named type export(
9592
"specifier": "./options",
9693
"type": "type",
9794
},
98-
"index": 0,
9995
}
10096
`;
10197

@@ -110,7 +106,6 @@ exports[`unit:EXPORT_AGGREGATE_REGEX > exports > should match namespace export 1
110106
"specifier": "./interfaces",
111107
"type": undefined,
112108
},
113-
"index": 0,
114109
}
115110
`;
116111

@@ -125,6 +120,5 @@ exports[`unit:EXPORT_AGGREGATE_REGEX > exports > should match namespace export w
125120
"specifier": "./constants",
126121
"type": undefined,
127122
},
128-
"index": 0,
129123
}
130124
`;

src/__snapshots__/export-declaration.snap

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > class > should match export a
1111
"exports": "Pet",
1212
"modifiers": "abstract",
1313
},
14-
"index": 0,
1514
}
1615
`;
1716

@@ -26,7 +25,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > class > should match export c
2625
"exports": "Pet",
2726
"modifiers": undefined,
2827
},
29-
"index": 0,
3028
}
3129
`;
3230

@@ -41,7 +39,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > class > should match export d
4139
"exports": "Pet",
4240
"modifiers": "declare abstract",
4341
},
44-
"index": 0,
4542
}
4643
`;
4744

@@ -57,7 +54,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > const > should match export c
5754
"exports": "IGNORE_PATTERNS",
5855
"modifiers": undefined,
5956
},
60-
"index": 1,
6157
},
6258
{
6359
"0": "export const { name1, name2: bar } = o",
@@ -69,7 +65,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > const > should match export c
6965
"exports": "{ name1, name2: bar }",
7066
"modifiers": undefined,
7167
},
72-
"index": 46,
7368
},
7469
{
7570
"0": "export const [ name1, name2 ] = array",
@@ -81,7 +76,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > const > should match export c
8176
"exports": "[ name1, name2 ]",
8277
"modifiers": undefined,
8378
},
84-
"index": 86,
8579
},
8680
]
8781
`;
@@ -97,7 +91,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > const > should match export d
9791
"exports": "IGNORE_PATTERNS",
9892
"modifiers": "declare",
9993
},
100-
"index": 1,
10194
}
10295
`;
10396

@@ -112,7 +105,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > const enum > should match exp
112105
"exports": "Color",
113106
"modifiers": undefined,
114107
},
115-
"index": 0,
116108
}
117109
`;
118110

@@ -127,7 +119,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > const enum > should match exp
127119
"exports": "Color",
128120
"modifiers": "declare",
129121
},
130-
"index": 0,
131122
}
132123
`;
133124

@@ -142,7 +133,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > enum > should match export de
142133
"exports": "TokenKind",
143134
"modifiers": "declare",
144135
},
145-
"index": 0,
146136
}
147137
`;
148138

@@ -157,7 +147,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > enum > should match export en
157147
"exports": "TokenKind",
158148
"modifiers": undefined,
159149
},
160-
"index": 0,
161150
}
162151
`;
163152

@@ -172,7 +161,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > function > should match expor
172161
"exports": "foo",
173162
"modifiers": "async",
174163
},
175-
"index": 0,
176164
}
177165
`;
178166

@@ -187,7 +175,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > function > should match expor
187175
"exports": "foo",
188176
"modifiers": "async declare",
189177
},
190-
"index": 0,
191178
}
192179
`;
193180

@@ -202,7 +189,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > function > should match expor
202189
"exports": "foo",
203190
"modifiers": "declare",
204191
},
205-
"index": 0,
206192
}
207193
`;
208194

@@ -217,7 +203,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > function > should match expor
217203
"exports": "foo",
218204
"modifiers": undefined,
219205
},
220-
"index": 0,
221206
}
222207
`;
223208

@@ -232,7 +217,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > function* > should match expo
232217
"exports": "generator",
233218
"modifiers": "async",
234219
},
235-
"index": 0,
236220
}
237221
`;
238222

@@ -247,7 +231,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > function* > should match expo
247231
"exports": "generator",
248232
"modifiers": "async declare",
249233
},
250-
"index": 0,
251234
}
252235
`;
253236

@@ -262,7 +245,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > function* > should match expo
262245
"exports": "generator",
263246
"modifiers": "declare",
264247
},
265-
"index": 0,
266248
}
267249
`;
268250

@@ -277,7 +259,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > function* > should match expo
277259
"exports": "generator",
278260
"modifiers": undefined,
279261
},
280-
"index": 0,
281262
}
282263
`;
283264

@@ -292,7 +273,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > interface > should match expo
292273
"exports": "IUser",
293274
"modifiers": "declare",
294275
},
295-
"index": 0,
296276
}
297277
`;
298278

@@ -307,7 +287,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > interface > should match expo
307287
"exports": "IUser",
308288
"modifiers": undefined,
309289
},
310-
"index": 0,
311290
}
312291
`;
313292

@@ -322,7 +301,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > let > should match export dec
322301
"exports": "name1, name2",
323302
"modifiers": "declare",
324303
},
325-
"index": 0,
326304
}
327305
`;
328306

@@ -337,7 +315,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > let > should match export let
337315
"exports": "name1, name2",
338316
"modifiers": undefined,
339317
},
340-
"index": 0,
341318
}
342319
`;
343320

@@ -352,7 +329,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > namespace > should match expo
352329
"exports": "Utils",
353330
"modifiers": "declare",
354331
},
355-
"index": 0,
356332
}
357333
`;
358334

@@ -367,7 +343,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > namespace > should match expo
367343
"exports": "Utils",
368344
"modifiers": undefined,
369345
},
370-
"index": 0,
371346
}
372347
`;
373348

@@ -382,7 +357,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > type > should match export de
382357
"exports": "Options",
383358
"modifiers": "declare",
384359
},
385-
"index": 0,
386360
}
387361
`;
388362

@@ -397,7 +371,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > type > should match export ty
397371
"exports": "Options",
398372
"modifiers": undefined,
399373
},
400-
"index": 0,
401374
}
402375
`;
403376

@@ -412,7 +385,6 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > var > should match export dec
412385
"exports": "name1, name2",
413386
"modifiers": "declare",
414387
},
415-
"index": 0,
416388
}
417389
`;
418390

@@ -427,6 +399,5 @@ exports[`unit:EXPORT_DECLARATION_REGEX > exports > var > should match export var
427399
"exports": "name1, name2",
428400
"modifiers": undefined,
429401
},
430-
"index": 0,
431402
}
432403
`;

0 commit comments

Comments
 (0)