Skip to content

Commit dc1a4ee

Browse files
Address PR feedback: backtick formatting in changelog, dynamic describe name, add snapshot tests
Agent-Logs-Url: https://github.com/microsoft/rushstack/sessions/f33fe415-7fc0-4905-8330-774013ebbe50 Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
1 parent c3ccf78 commit dc1a4ee

3 files changed

Lines changed: 84 additions & 2 deletions

File tree

common/changes/@rushstack/lookup-by-path/enhance-lookup-by-path-json-methods_2026-04-07-22-32.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"changes": [
33
{
4-
"comment": "Add toJson/fromJson methods to LookupByPath for serialization/deserialization",
4+
"comment": "Add `toJson`/`fromJson` methods to `LookupByPath` for serialization/deserialization",
55
"type": "minor",
66
"packageName": "@rushstack/lookup-by-path"
77
}

libraries/lookup-by-path/src/test/LookupByPath.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ describe(LookupByPath.prototype.groupByChild.name, () => {
675675
});
676676
});
677677

678-
describe('toJson and fromJson', () => {
678+
describe(`${LookupByPath.prototype.toJson.name} and ${LookupByPath.fromJson.name}`, () => {
679679
it('round-trips an empty trie', () => {
680680
const original = new LookupByPath<number>();
681681
const json: ILookupByPathJson<number> = original.toJson((v) => v);
@@ -702,6 +702,31 @@ describe('toJson and fromJson', () => {
702702
expect(restored.get('missing')).toEqual(undefined);
703703
});
704704

705+
it('snapshot: serialized JSON for a simple tree', () => {
706+
const original = new LookupByPath<number>([
707+
['foo', 1],
708+
['foo/bar', 2],
709+
['baz', 3]
710+
]);
711+
712+
const json: ILookupByPathJson<number> = original.toJson((v) => v);
713+
expect(json).toMatchSnapshot();
714+
});
715+
716+
it('snapshot: serialized JSON with intermediate nodes and custom delimiter', () => {
717+
const original = new LookupByPath<string>(
718+
[
719+
['a,b,c', 'deep'],
720+
['a,b', 'mid'],
721+
['x', 'top']
722+
],
723+
','
724+
);
725+
726+
const json: ILookupByPathJson<string> = original.toJson((v) => v);
727+
expect(json).toMatchSnapshot();
728+
});
729+
705730
it('round-trips with string values', () => {
706731
const original = new LookupByPath<string>([
707732
['a', 'alpha'],
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`toJson and fromJson snapshot: serialized JSON for a simple tree 1`] = `
4+
Object {
5+
"delimiter": "/",
6+
"tree": Object {
7+
"children": Object {
8+
"baz": Object {
9+
"valueIndex": 2,
10+
},
11+
"foo": Object {
12+
"children": Object {
13+
"bar": Object {
14+
"valueIndex": 1,
15+
},
16+
},
17+
"valueIndex": 0,
18+
},
19+
},
20+
},
21+
"values": Array [
22+
1,
23+
2,
24+
3,
25+
],
26+
}
27+
`;
28+
29+
exports[`toJson and fromJson snapshot: serialized JSON with intermediate nodes and custom delimiter 1`] = `
30+
Object {
31+
"delimiter": ",",
32+
"tree": Object {
33+
"children": Object {
34+
"a": Object {
35+
"children": Object {
36+
"b": Object {
37+
"children": Object {
38+
"c": Object {
39+
"valueIndex": 1,
40+
},
41+
},
42+
"valueIndex": 0,
43+
},
44+
},
45+
},
46+
"x": Object {
47+
"valueIndex": 2,
48+
},
49+
},
50+
},
51+
"values": Array [
52+
"mid",
53+
"deep",
54+
"top",
55+
],
56+
}
57+
`;

0 commit comments

Comments
 (0)