@cronn/playwright-semantic-snapshots 0.35.3 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +0 -2
- package/package.json +43 -31
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/index.d.mts
CHANGED
|
@@ -265,5 +265,4 @@ export declare function excludeRole<TRole extends NodeRole>(role: TRole | Array<
|
|
|
265
265
|
* Aggregates and normalizes the text content of all provided snapshots
|
|
266
266
|
*/
|
|
267
267
|
export declare function getTextContent(snapshots: Array<NodeSnapshot>): string;
|
|
268
|
-
export type { ButtonSnapshot, CellSnapshot, ColumnHeaderSnapshot, ComboboxSnapshot, ContainerSnapshot, DefaultSnapshotTransformer, DialogSnapshot, ElementRole, ElementSnapshot, GroupSnapshot, HeadingSnapshot, ImageSnapshot, InputSnapshot, LinkSnapshot, ListboxSnapshot, MarkdownTableSnapshotOptions, MatchMarkdownTableSnapshotFileOptions, MatchSemanticSnapshotFileOptions, MenuItemSnapshot, NodeRole, NodeSnapshot, OptionSnapshot, ProgressbarSnapshot, RadioGroupSnapshot, RegionSnapshot, RoleBasedSnapshotTransformer, RoleBasedSnapshotTransformers, SemanticSnapshotMatchers, SemanticSnapshotOptions, SeparatorSnapshot, SnapshotByRole, SnapshotTransformer, SnapshotTransformerContext, TabSnapshot, TextSnapshot, TreeItemSnapshot };
|
|
269
|
-
//# sourceMappingURL=index.d.mts.map
|
|
268
|
+
export type { ButtonSnapshot, CellSnapshot, ColumnHeaderSnapshot, ComboboxSnapshot, ContainerSnapshot, DefaultSnapshotTransformer, DialogSnapshot, ElementRole, ElementSnapshot, GroupSnapshot, HeadingSnapshot, ImageSnapshot, InputSnapshot, LinkSnapshot, ListboxSnapshot, MarkdownTableSnapshotOptions, MatchMarkdownTableSnapshotFileOptions, MatchSemanticSnapshotFileOptions, MenuItemSnapshot, NodeRole, NodeSnapshot, OptionSnapshot, ProgressbarSnapshot, RadioGroupSnapshot, RegionSnapshot, RoleBasedSnapshotTransformer, RoleBasedSnapshotTransformers, SemanticSnapshotMatchers, SemanticSnapshotOptions, SeparatorSnapshot, SnapshotByRole, SnapshotTransformer, SnapshotTransformerContext, TabSnapshot, TextSnapshot, TreeItemSnapshot };
|
package/dist/index.mjs
CHANGED
|
@@ -329,5 +329,3 @@ function mergeTexts(texts) {
|
|
|
329
329
|
return normalizeText(texts.map((textNode) => textNode.name).join(" "));
|
|
330
330
|
}
|
|
331
331
|
export { defineSemanticSnapshotMatchers, excludeRole, filter, filterByRole, getTextContent, includeRole, markdownTableSnapshot, rawSnapshot, semanticSnapshot };
|
|
332
|
-
|
|
333
|
-
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cronn/playwright-semantic-snapshots",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "Semantic snapshots for Playwright",
|
|
5
5
|
"homepage": "https://cronn.github.io/file-snapshots/playwright/semantic-snapshots/",
|
|
6
6
|
"bugs": {
|
|
@@ -24,6 +24,47 @@
|
|
|
24
24
|
"default": "./dist/index.mjs"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@cronn/lib-file-snapshots": "1.3.1",
|
|
29
|
+
"@cronn/playwright-file-snapshots": "2.4.1",
|
|
30
|
+
"package-directory": "^8.2.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@arethetypeswrong/core": "0.18.5",
|
|
34
|
+
"@cronn/file-snapshots-cli": "1.0.0",
|
|
35
|
+
"@cronn/shared-configs": "0.0.0",
|
|
36
|
+
"@cronn/test-utils": "0.0.0",
|
|
37
|
+
"@cronn/vitest-file-snapshots": "3.1.1",
|
|
38
|
+
"@playwright/test": "1.65.1",
|
|
39
|
+
"@types/node": "26.6.6",
|
|
40
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
41
|
+
"@vitest/coverage-v8": "5.1.1",
|
|
42
|
+
"oxlint": "1.94.0",
|
|
43
|
+
"oxlint-tsgolint": "7.0.2008",
|
|
44
|
+
"publint": "0.3.25",
|
|
45
|
+
"rimraf": "6.1.4",
|
|
46
|
+
"tsdown": "0.23.7",
|
|
47
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
48
|
+
"vitest": "5.1.1"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@playwright/test": "^1.55"
|
|
52
|
+
},
|
|
53
|
+
"devEngines": {
|
|
54
|
+
"packageManager": {
|
|
55
|
+
"name": "pnpm",
|
|
56
|
+
"version": "12.23.0",
|
|
57
|
+
"onFail": "download"
|
|
58
|
+
},
|
|
59
|
+
"runtime": {
|
|
60
|
+
"name": "node",
|
|
61
|
+
"version": "26.13.1",
|
|
62
|
+
"onFail": "download"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": "^24.8.0 || >=26"
|
|
67
|
+
},
|
|
27
68
|
"scripts": {
|
|
28
69
|
"build": "tsdown",
|
|
29
70
|
"clean": "rimraf .turbo dist playwright-report test-results coverage",
|
|
@@ -35,34 +76,5 @@
|
|
|
35
76
|
"test:integration": "playwright test",
|
|
36
77
|
"test:unit": "vitest run",
|
|
37
78
|
"test:unit:coverage": "vitest run --coverage"
|
|
38
|
-
},
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"@cronn/lib-file-snapshots": "workspace:*",
|
|
41
|
-
"@cronn/playwright-file-snapshots": "workspace:*",
|
|
42
|
-
"package-directory": "catalog:prod"
|
|
43
|
-
},
|
|
44
|
-
"devDependencies": {
|
|
45
|
-
"@arethetypeswrong/core": "catalog:dev",
|
|
46
|
-
"@cronn/file-snapshots-cli": "workspace:*",
|
|
47
|
-
"@cronn/shared-configs": "workspace:*",
|
|
48
|
-
"@cronn/test-utils": "workspace:*",
|
|
49
|
-
"@cronn/vitest-file-snapshots": "workspace:*",
|
|
50
|
-
"@playwright/test": "catalog:dev",
|
|
51
|
-
"@types/node": "catalog:dev",
|
|
52
|
-
"@typescript/native": "catalog:dev",
|
|
53
|
-
"@vitest/coverage-v8": "catalog:dev",
|
|
54
|
-
"oxlint": "catalog:dev",
|
|
55
|
-
"oxlint-tsgolint": "catalog:dev",
|
|
56
|
-
"publint": "catalog:dev",
|
|
57
|
-
"rimraf": "catalog:dev",
|
|
58
|
-
"tsdown": "catalog:dev",
|
|
59
|
-
"typescript": "catalog:dev",
|
|
60
|
-
"vitest": "catalog:dev"
|
|
61
|
-
},
|
|
62
|
-
"peerDependencies": {
|
|
63
|
-
"@playwright/test": "^1.55"
|
|
64
|
-
},
|
|
65
|
-
"engines": {
|
|
66
|
-
"node": "^24.8.0 || >=26"
|
|
67
79
|
}
|
|
68
|
-
}
|
|
80
|
+
}
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/playwright/markdown-table.ts","../src/types/attributes.ts","../src/types/elements/button.ts","../src/types/utils.ts","../src/types/elements/container.ts","../src/types/elements/dialog.ts","../src/types/elements/group.ts","../src/types/elements/heading.ts","../src/types/elements/image.ts","../src/types/elements/input.ts","../src/types/elements/link.ts","../src/types/elements/list.ts","../src/types/elements/progressbar.ts","../src/types/elements/separator.ts","../src/types/elements/tab.ts","../src/types/elements/table.ts","../src/types/elements/text.ts","../src/types/elements/tree.ts","../src/types/role.ts","../src/types/snapshot.ts","../src/types/transformer.ts","../src/utils/filter.ts","../src/playwright/snapshot.ts","../src/types/matchers.ts","../src/playwright/matchers.ts","../src/utils/predicates.ts","../src/utils/text.ts"],"mappings":";;;UA+BiB;;;;;;EAMf;;;;EAKA,cAAc,MAAM;;;;;wBAMA,sBACpB,SAAS,SACT,UAAS,+BACR;UCnDc;EACf;;UAGe;EACf;;UAGe;EACf;;UAGe;EACf;;UAGe;EACf,UAAU;;KAGA;UAEK;EACf;;UAGe,6BAA6B;EAC5C;EACA;EACA;;UCvBe,uBAAuB,iCAEtC;UAGQ,yBAAyB,uBAAuB;EACxD,UAAU;;KAGP;KCbO,UAAU,QAAQ,aAAa,UAAU,UAAU;KAEnD,mBAAmB,OAAO;cCDzB,iBAAe;UAwCX,0BAA0B,uBAAuB;KAEtD,gBAAgB,iBAAiB;UAE5B,uBAAuB;UC5CvB,uBAAuB,uBACtC,YACA;KAGU;UAEF,yBAAyB;EACjC;;UCRe,sBAAsB;UAEtB,2BAA2B,qCAE1C;UAGQ,6BAA6B;UCRtB,wBAAwB,kCAEvC;UAGQ;EACR;;UCNe,sBAAsB;UCStB,sBAAsB,uBACrC,iBACA;KAGU,yBAAyB;KAEzB;UASF,wBAAwB,uBAAuB;EACvD;;UAGe,8BACP,sBAAsB;EAC9B;;UAGe,yBAAyB,mCAExC;UAGQ,iCACA,uBAAuB;UAEvB,2BAA2B;EACnC,iBAAiB;;UAGF,uBAAuB,iCAEtC;UAGQ,yBACA,sBAAsB;UAEf,wBAAwB,kCAEvC;UAGQ,0BACA,0BAA0B;UC5DnB,qBAAqB,+BAEpC;UAGe;EACf;EACA,UAAU;;KAGP;UCPY,yBAAyB,mCAExC;UAGQ,2BAA2B,gBAAgB;UCRpC,4BAA4B,sCAE3C;UAGQ;EACR;;UCNe,0BAA0B;UCI1B,oBAAoB,8BAEnC;UAGQ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AcmB,YACpB,QAAQ,mBACP,QAAQ,MAAM;UCvEA;EACf,8BACE,QAAQ,kBACR,UAAU,qCACP,QAAQ;EACb,mCACE,QAAQ,SACR,UAAU,0CACP,QAAQ;;UAGE,yCACP,gCAAgC;UAEzB,8CAEb,KAAK,kEACL;;;;;;;;;;;;;;wBCOY,+BACd,SAAQ,wCACP,OAAO;;;;wBC9BM,YAAY,cAAc,UACxC,MAAM,QAAQ,MAAM,SACnB,uBAAuB,eAAe;;;;wBAOzB,YAAY,cAAc,UACxC,MAAM,QAAQ,MAAM,SACnB,uBAAuB,eAAe;;;;wBCVzB,eAAe,WAAW,MAAM"}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["baseExpect"],"sources":["../src/utils/guards.ts","../src/utils/predicates.ts","../src/utils/filter.ts","../src/playwright/proxy.ts","../src/utils/array.ts","../src/transformers/semantic-snapshot-transformer.ts","../src/playwright/snapshot-serializer.ts","../src/playwright/snapshot.ts","../src/playwright/markdown-table.ts","../src/playwright/matchers.ts","../src/utils/text.ts"],"sourcesContent":["import type { TextSnapshot } from \"../types/elements/text\";\nimport type { NodeRole, NodeSnapshot, SnapshotByRole } from \"../types/snapshot\";\n\nexport function isTextSnapshot(\n snapshot: NodeSnapshot,\n): snapshot is TextSnapshot {\n return hasRole(\"text\", snapshot);\n}\n\nexport function hasRole<TRole extends NodeRole>(\n role: TRole | Array<TRole>,\n snapshot: NodeSnapshot,\n): snapshot is SnapshotByRole<TRole> {\n if (typeof role === \"string\") {\n return role === snapshot.role;\n }\n\n return role.includes(snapshot.role as TRole);\n}\n\nexport function isEmpty(\n value: string | Array<unknown> | Record<string, unknown>,\n): boolean {\n if (typeof value === \"string\" || Array.isArray(value)) {\n return value.length === 0;\n }\n\n return Object.keys(value).length === 0;\n}\n","import type { NodeRole, NodeSnapshot, SnapshotByRole } from \"../types/snapshot\";\n\nimport type { GuardedFilterPredicate } from \"./filter\";\nimport { hasRole } from \"./guards\";\n\n/**\n * Include only elements with the specified role\n */\nexport function includeRole<TRole extends NodeRole>(\n role: TRole | Array<TRole>,\n): GuardedFilterPredicate<SnapshotByRole<TRole>> {\n return (snapshot: NodeSnapshot) => hasRole(role, snapshot);\n}\n\n/**\n * Exclude elements with the specified role\n */\nexport function excludeRole<TRole extends NodeRole>(\n role: TRole | Array<TRole>,\n): GuardedFilterPredicate<SnapshotByRole<TRole>> {\n return (snapshot: NodeSnapshot): snapshot is SnapshotByRole<TRole> =>\n !hasRole(role, snapshot);\n}\n","import type { NodeRole, NodeSnapshot, SnapshotByRole } from \"../types/snapshot\";\n\nimport { isTextSnapshot } from \"./guards\";\nimport { includeRole } from \"./predicates\";\n\nexport type FilterPredicate = (snapshot: NodeSnapshot) => boolean;\n\nexport type GuardedFilterPredicate<TSnapshot extends NodeSnapshot> = (\n snapshot: NodeSnapshot,\n) => snapshot is TSnapshot;\n\ninterface FilterOptions extends FilterBaseOptions {\n /**\n * Include only elements in the snapshot for which the specified predicate returns `true`\n */\n predicate: FilterPredicate;\n}\n\ninterface GuardedFilterOptions<\n TSnapshot extends NodeSnapshot,\n> extends FilterBaseOptions {\n /**\n * Include only elements in the snapshot for which the specified predicate returns `true`\n */\n predicate: GuardedFilterPredicate<TSnapshot>;\n}\n\ninterface FilterBaseOptions {\n /**\n * Array of snapshots to filter.\n */\n snapshots: Array<NodeSnapshot>;\n\n /**\n * Recursively apply specified filter to children of filtered elements\n *\n * By default, recursion ends when the filter returns `true` for an element.\n * Should be `true` for filters intended to remove specific elements recursively.\n *\n * @default false\n */\n recurse?: boolean;\n}\n\n/**\n * Filters node snapshots based on the provided predicate function\n */\nexport function filter<TSnapshot extends NodeSnapshot = NodeSnapshot>(\n options: GuardedFilterOptions<TSnapshot>,\n): Array<TSnapshot>;\nexport function filter(options: FilterOptions): Array<NodeSnapshot>;\nexport function filter<TSnapshot extends NodeSnapshot>(\n options: FilterOptions | GuardedFilterOptions<TSnapshot>,\n): Array<TSnapshot> {\n const { predicate, snapshots, recurse = false } = options;\n\n return snapshots.flatMap((snapshot) => {\n const isFilteredIn = predicate(snapshot);\n\n // end recursion on included snapshot\n if (isFilteredIn && !recurse) {\n return snapshot as TSnapshot;\n }\n\n // end recursion on excluded snapshot\n if (!isFilteredIn && recurse) {\n return [];\n }\n\n const filteredChildren = hasChildren(snapshot)\n ? filter<TSnapshot>({\n predicate: predicate as GuardedFilterPredicate<TSnapshot>,\n snapshots: snapshot.children ?? [],\n recurse,\n })\n : [];\n\n // recurse excluded snapshot\n if (!isFilteredIn) {\n return filteredChildren;\n }\n\n // recurse included snapshot\n if (isTextSnapshot(snapshot)) {\n return snapshot as TSnapshot;\n }\n\n return {\n ...snapshot,\n children: filteredChildren as Array<NodeSnapshot>,\n } as TSnapshot;\n });\n}\n\n/**\n * Filters node snapshots by a specific role\n */\nexport function filterByRole<TRole extends NodeRole>(\n role: TRole,\n snapshots: Array<NodeSnapshot>,\n): Array<SnapshotByRole<TRole>> {\n return filter({\n predicate: includeRole(role),\n recurse: false,\n snapshots,\n });\n}\n\nfunction hasChildren(\n snapshot: NodeSnapshot,\n): snapshot is NodeSnapshot & { children: Array<NodeSnapshot> } {\n return \"children\" in snapshot && snapshot.children.length > 0;\n}\n","import type { Frame, Locator } from \"@playwright/test\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { packageDirectory } from \"package-directory\";\n\nimport type { NodeSnapshot } from \"../types/snapshot\";\n\nexport class ElementSnapshotProxy {\n private static browserLibSource: string | undefined = undefined;\n\n public async snapshotElement(locator: Locator): Promise<Array<NodeSnapshot>> {\n // the library must be loaded into the element's own frame, which differs\n // from the page's main frame for elements inside iframes\n if (!(await this.isLibraryLoaded(locator))) {\n await this.loadLibrary(await this.resolveOwnerFrame(locator));\n }\n\n return await locator.evaluate((element) => {\n return window.snapshotElement(element);\n });\n }\n\n private async isLibraryLoaded(locator: Locator): Promise<boolean> {\n return await locator.evaluate(\n () => typeof window.snapshotElement === \"function\",\n );\n }\n\n private async resolveOwnerFrame(locator: Locator): Promise<Frame> {\n const elementHandle = await locator.elementHandle();\n try {\n const frame = await elementHandle.ownerFrame();\n if (frame === null) {\n throw new Error(\"Unable to resolve frame of element\");\n }\n return frame;\n } finally {\n await elementHandle.dispose();\n }\n }\n\n private async loadLibrary(frame: Frame): Promise<void> {\n // cache browser lib source to avoid reading it multiple times\n ElementSnapshotProxy.browserLibSource ??= await this.readBrowserLibSource();\n\n // evaluate source via Playwright instead of in-page `eval` to comply with\n // strict content security policies\n await frame.evaluate(ElementSnapshotProxy.browserLibSource);\n }\n\n private async readBrowserLibSource(): Promise<string> {\n const libPath = await this.resolveFromPackageRoot(\n \"dist\",\n \"browser-lib.iife.js\",\n );\n return await fs.readFile(libPath, \"utf8\");\n }\n\n private async resolveFromPackageRoot(\n ...paths: Array<string>\n ): Promise<string> {\n const packageRoot = await packageDirectory({\n cwd: import.meta.dirname,\n });\n\n if (packageRoot === undefined) {\n throw new Error(\"Unable to resolve root directory of package\");\n }\n\n return path.resolve(packageRoot, ...paths);\n }\n}\n","export function unwrapSingleItem<T>(items: Array<T>): T | Array<T> {\n return items.length === 1 ? (items.at(0) as T) : items;\n}\n","import type { ElementRole } from \"../types/role\";\nimport type { GenericElementSnapshot, NodeSnapshot } from \"../types/snapshot\";\nimport type {\n SnapshotTransformer,\n SnapshotTransformerContext,\n} from \"../types/transformer\";\nimport { unwrapSingleItem } from \"../utils/array\";\nimport { isEmpty } from \"../utils/guards\";\n\ninterface NormalizedElementSnapshot {\n role: ElementRole;\n name: string;\n attributes: Record<string, unknown>;\n children: Array<unknown>;\n}\n\nexport function semanticSnapshotTransformer(\n snapshot: NodeSnapshot,\n context: SnapshotTransformerContext,\n): unknown {\n if (snapshot.role === \"text\") {\n return snapshot.name;\n }\n\n return transformElementSnapshot(snapshot, context.transform);\n}\n\nfunction transformElementSnapshot(\n snapshot: GenericElementSnapshot,\n transformRecursive: SnapshotTransformer,\n): unknown {\n const normalizedSnapshot = normalizeElementSnapshot(\n snapshot,\n transformRecursive,\n );\n\n if (hasOnlyRole(normalizedSnapshot)) {\n const { role } = normalizedSnapshot;\n return transformedSnapshot(role, \"\");\n }\n\n if (hasOnlyName(normalizedSnapshot)) {\n const { role, name } = normalizedSnapshot;\n return transformedSnapshot(role, name);\n }\n\n if (hasOnlyChildren(normalizedSnapshot)) {\n const { role, children } = normalizedSnapshot;\n return transformedSnapshot(role, unwrapSingleItem(children));\n }\n\n const { role, name, attributes, children } = normalizedSnapshot;\n return transformedSnapshot(role, name, {\n ...attributes,\n children: isEmpty(children) ? undefined : unwrapSingleItem(children),\n });\n}\n\nfunction normalizeElementSnapshot(\n snapshot: GenericElementSnapshot,\n transformRecursive: SnapshotTransformer,\n): NormalizedElementSnapshot {\n const normalizedName = snapshot.name ?? \"\";\n const transformedAttributes = transformAttributes(snapshot.attributes ?? {});\n const transformedChildren = (snapshot.children ?? []).map(transformRecursive);\n const singleChild =\n transformedChildren.length === 1 ? transformedChildren.at(0) : undefined;\n const nameEqualsChildren = normalizedName === singleChild;\n const valueEqualsChildren =\n typeof transformedAttributes.value === \"string\" &&\n transformedAttributes.value === singleChild;\n\n return {\n role: snapshot.role,\n name: normalizedName,\n attributes: transformedAttributes,\n children:\n nameEqualsChildren || valueEqualsChildren ? [] : transformedChildren,\n };\n}\n\nfunction hasOnlyRole(snapshot: NormalizedElementSnapshot): boolean {\n return (\n isEmpty(snapshot.name) &&\n isEmpty(snapshot.attributes) &&\n isEmpty(snapshot.children)\n );\n}\n\nfunction hasOnlyName(snapshot: NormalizedElementSnapshot): boolean {\n return (\n !isEmpty(snapshot.name) &&\n isEmpty(snapshot.attributes) &&\n isEmpty(snapshot.children)\n );\n}\n\nfunction hasOnlyChildren(snapshot: NormalizedElementSnapshot): boolean {\n return (\n isEmpty(snapshot.name) &&\n isEmpty(snapshot.attributes) &&\n !isEmpty(snapshot.children)\n );\n}\n\nfunction transformAttributes(attributes: object): Record<string, unknown> {\n const filteredAttributes: Record<string, unknown> = {};\n\n Object.entries(attributes).forEach(([attributeName, attributeValue]) => {\n if (attributeValue === undefined) {\n return;\n }\n\n filteredAttributes[attributeName] = attributeValue;\n });\n\n return filteredAttributes;\n}\n\nfunction transformedSnapshot(\n role: ElementRole,\n nameOrContent: unknown,\n additionalProperties?: Record<string, unknown>,\n): unknown {\n return { [role]: nameOrContent, ...additionalProperties };\n}\n","import { semanticSnapshotTransformer } from \"../transformers/semantic-snapshot-transformer\";\nimport type { NodeSnapshot } from \"../types/snapshot\";\nimport type {\n DefaultSnapshotTransformer,\n RoleBasedSnapshotTransformer,\n RoleBasedSnapshotTransformers,\n} from \"../types/transformer\";\nimport { unwrapSingleItem } from \"../utils/array\";\nimport type { FilterPredicate } from \"../utils/filter\";\nimport { filter } from \"../utils/filter\";\n\ninterface SnapshotSerializerOptions {\n filter?: FilterPredicate;\n recurseFilter?: boolean;\n transformers?: RoleBasedSnapshotTransformers;\n defaultTransformer?: DefaultSnapshotTransformer;\n}\n\nexport class SnapshotSerializer {\n private readonly filter?: FilterPredicate;\n private readonly recurseFilter: boolean;\n private readonly transformers: RoleBasedSnapshotTransformers;\n private readonly defaultTransformer: DefaultSnapshotTransformer;\n\n public constructor(options: SnapshotSerializerOptions = {}) {\n this.filter = options.filter;\n this.recurseFilter = options.recurseFilter ?? false;\n this.transformers = { ...options.transformers };\n this.defaultTransformer =\n options.defaultTransformer ?? semanticSnapshotTransformer;\n }\n\n public transform(snapshots: Array<NodeSnapshot>): unknown {\n const filteredSnapshots = this.filterSnapshots(snapshots);\n const transformedSnapshots = filteredSnapshots.map(\n this.transformSnapshotRecursive,\n );\n\n return unwrapSingleItem(transformedSnapshots);\n }\n\n private filterSnapshots(snapshots: Array<NodeSnapshot>): Array<NodeSnapshot> {\n if (this.filter === undefined) {\n return snapshots;\n }\n\n return filter({\n predicate: this.filter,\n snapshots,\n recurse: this.recurseFilter,\n });\n }\n\n private readonly boundDefaultTransformer = (\n snapshot: NodeSnapshot,\n ): unknown =>\n this.defaultTransformer(snapshot, {\n transform: this.transformSnapshotRecursive,\n });\n\n private readonly transformSnapshotRecursive = (\n snapshot: NodeSnapshot,\n ): unknown => {\n const transformer = this.transformers[snapshot.role] as\n | RoleBasedSnapshotTransformer\n | undefined;\n\n if (transformer !== undefined) {\n return transformer(snapshot, { transform: this.boundDefaultTransformer });\n }\n\n return this.defaultTransformer(snapshot, {\n transform: this.transformSnapshotRecursive,\n });\n };\n}\n","import type { Page } from \"@playwright/test\";\n\nimport type { NodeSnapshot } from \"../types/snapshot\";\nimport type {\n DefaultSnapshotTransformer,\n RoleBasedSnapshotTransformers,\n} from \"../types/transformer\";\nimport type { PlaywrightTarget } from \"../types/utils\";\nimport type { FilterPredicate } from \"../utils/filter\";\n\nimport { ElementSnapshotProxy } from \"./proxy\";\nimport { SnapshotSerializer } from \"./snapshot-serializer\";\n\nexport interface SemanticSnapshotOptions {\n /**\n * Include only elements in the snapshot for which the specified filter returns `true`\n *\n * @default () => true\n */\n filter?: FilterPredicate;\n\n /**\n * Recursively apply specified filter to children of filtered elements\n *\n * By default, recursion ends when the filter returns `true` for an element.\n * Should be `true` for filters intended to remove specific elements recursively.\n *\n * @default false\n */\n recurseFilter?: boolean;\n\n /**\n * Replace the default transformation for specific roles\n *\n * Transformers are keyed by role and applied after the filter, but before\n * the default serialization. A transformer may return any JSON-serializable\n * value, which is written to the snapshot verbatim. The `transform` function\n * of its context applies the default transformation to untransformed\n * children.\n */\n transformers?: RoleBasedSnapshotTransformers;\n\n /**\n * Replace the default transformation for all roles\n *\n * Applied to every snapshot passed to the default transformation, including\n * the ones a transformer delegates via the `transform` function of its\n * context. Transformers registered for a role take precedence.\n *\n * @default semanticSnapshotTransformer\n */\n defaultTransformer?: DefaultSnapshotTransformer;\n}\n\n/**\n * Captures a semantic snapshot of the specified locator's DOM structure.\n *\n * This function creates a raw snapshot of the DOM element identified by the locator\n * and transforms it into a semantic representation using the provided options.\n *\n * @param target - The Page or Locator instance that identifies the DOM element to snapshot\n * @param options - Optional configuration settings for controlling the snapshot behavior\n * @return A promise that resolves to the semantic snapshot\n */\nexport async function semanticSnapshot(\n target: PlaywrightTarget,\n options?: SemanticSnapshotOptions,\n): Promise<unknown> {\n const snapshot = await rawSnapshot(target);\n return new SnapshotSerializer(options).transform(snapshot);\n}\n\n/**\n * Captures a raw snapshot of the element matched by the provided locator.\n *\n * Returns an array of node snapshots representing the current state of the matched elements\n * in the DOM, including their properties, attributes, and structure.\n *\n * @param target - The Page or Locator instance used to identify the target element to snapshot\n * @return A promise that resolves to an array of NodeSnapshot objects representing the captured element\n */\nexport async function rawSnapshot(\n target: PlaywrightTarget,\n): Promise<Array<NodeSnapshot>> {\n const locator = isPage(target) ? target.locator(\"body\") : target;\n return await new ElementSnapshotProxy().snapshotElement(locator);\n}\n\nfunction isPage(target: PlaywrightTarget): target is Page {\n return \"goto\" in target && typeof target.goto === \"function\";\n}\n","import type { Locator } from \"@playwright/test\";\n\nimport {\n type MarkdownTableNormalizer,\n MarkdownTableSerializer,\n type TableData,\n type TableRow,\n} from \"@cronn/lib-file-snapshots\";\n\nimport type { ColumnHeaderSnapshot, SortType } from \"../types/elements/table\";\nimport type {\n ElementSnapshot,\n NodeRole,\n NodeSnapshot,\n SnapshotByRole,\n} from \"../types/snapshot\";\nimport { filter, filterByRole } from \"../utils/filter\";\nimport { includeRole } from \"../utils/predicates\";\n\nimport { rawSnapshot } from \"./snapshot\";\n\nconst tableRoles = [\"table\", \"grid\"] satisfies Array<NodeRole>;\n\nconst cellRoles = [\"rowheader\", \"cell\", \"gridcell\"] satisfies Array<NodeRole>;\n\nconst sortIndicators: Record<SortType, string> = {\n ascending: \"⯅\",\n descending: \"⯆\",\n other: \"⯁\",\n};\n\nexport interface MarkdownTableSnapshotOptions {\n /**\n * Show sort indicator for column headers\n *\n * @default true\n */\n showSortIndicator?: boolean;\n\n /**\n * Custom normalizers to apply before serialization\n */\n normalizers?: Array<MarkdownTableNormalizer>;\n}\n\n/**\n * Creates a Markdown table snapshot from a table or grid element\n */\nexport async function markdownTableSnapshot(\n locator: Locator,\n options: MarkdownTableSnapshotOptions = {},\n): Promise<string> {\n const { showSortIndicator, normalizers } = options;\n\n const elementSnapshot = await rawSnapshot(locator);\n const parsedTable = parseTable(elementSnapshot, { showSortIndicator });\n\n return new MarkdownTableSerializer({ normalizers }).serialize(parsedTable);\n}\n\nfunction parseTable(\n snapshot: Array<NodeSnapshot>,\n options: MarkdownTableSnapshotOptions,\n): TableData {\n const { showSortIndicator = true } = options;\n\n const tableOrGridResult = filter({\n predicate: includeRole(tableRoles),\n snapshots: snapshot,\n });\n if (tableOrGridResult.length > 1) {\n throw new Error(\"Multiple tables or grids found\");\n }\n\n const [tableOrGrid] = tableOrGridResult;\n if (tableOrGrid === undefined) {\n throw new Error(\"No table or grid found\");\n }\n\n const [headerRow, ...bodyRows] = filterByRole(\"row\", tableOrGrid.children);\n if (headerRow === undefined) {\n throw new Error(\"No header row found\");\n }\n\n const columnHeaders = filterByRole(\"columnheader\", headerRow.children);\n if (columnHeaders.length === 0) {\n throw new Error(\"No column headers found\");\n }\n\n const columnHeaderTexts = columnHeaders.map((columnHeader) =>\n getColumnHeaderText(columnHeader, showSortIndicator),\n );\n const cellsTextsByRow = bodyRows.map(getCellTexts);\n\n return { columns: columnHeaderTexts, rows: cellsTextsByRow };\n}\n\nfunction getColumnHeaderText(\n columnHeader: ColumnHeaderSnapshot,\n showSortIndicator: boolean,\n): string {\n const headerText = getNameOrDefault(columnHeader);\n const sortType = columnHeader.attributes.sort;\n\n if (!showSortIndicator || sortType === undefined) {\n return headerText;\n }\n\n const sortIndicator = sortIndicators[sortType];\n return `${headerText} ${sortIndicator}`;\n}\n\nfunction getCellTexts(row: SnapshotByRole<\"row\">): TableRow {\n return filter({\n predicate: includeRole(cellRoles),\n snapshots: row.children,\n }).map(getNameOrDefault);\n}\n\nfunction getNameOrDefault(snapshot: ElementSnapshot): string {\n return snapshot.name ?? \"\";\n}\n","import type {\n Expect,\n ExpectMatcherState,\n Locator,\n MatcherReturnType,\n} from \"@playwright/test\";\nimport { expect as baseExpect } from \"@playwright/test\";\n\nimport type { PlaywrightValidationFileMatcherConfig } from \"@cronn/playwright-file-snapshots\";\nimport {\n defineJsonFileMatcher,\n defineTextFileMatcher,\n} from \"@cronn/playwright-file-snapshots\";\n\nimport type {\n SemanticSnapshotMatchers,\n MatchMarkdownTableSnapshotFileOptions,\n MatchSemanticSnapshotFileOptions,\n} from \"../types/matchers\";\n\nimport { markdownTableSnapshot } from \"./markdown-table\";\nimport { semanticSnapshot } from \"./snapshot\";\n\n/**\n * Defines a custom Playwright expect instance with semantic snapshot matchers for validating DOM elements against stored snapshots.\n *\n * @param {PlaywrightValidationFileMatcherConfig} config - Configuration options for file matching behavior\n * @return {Expect<SemanticSnapshotMatchers>} An extended expect instance that includes matcher methods for semantic snapshot validation.\n *\n * @example\n * export const expect = defineSemanticSnapshotMatchers();\n *\n * test(\"matches semantic snapshot\", async ({ page }) => {\n * await expect(page.getByRole(\"main\")).toMatchSemanticSnapshotFile();\n * });\n */\nexport function defineSemanticSnapshotMatchers(\n config: PlaywrightValidationFileMatcherConfig = {},\n): Expect<SemanticSnapshotMatchers> {\n async function toMatchSemanticSnapshotFile(\n this: ExpectMatcherState,\n actual: Locator,\n options: MatchSemanticSnapshotFileOptions = {},\n ): Promise<MatcherReturnType> {\n const toMatchJsonFile = defineJsonFileMatcher(\n \"toMatchSemanticSnapshotFile\",\n config,\n ).bind(this);\n return await toMatchJsonFile(\n () => semanticSnapshot(actual, options),\n options,\n );\n }\n\n async function toMatchMarkdownTableSnapshotFile(\n this: ExpectMatcherState,\n actual: Locator,\n options: MatchMarkdownTableSnapshotFileOptions = {},\n ): Promise<MatcherReturnType> {\n const toMatchTextFile = defineTextFileMatcher(\n \"toMatchMarkdownTableSnapshotFile\",\n config,\n ).bind(this);\n const { showSortIndicator, normalizers, ...matchFileOptions } = options;\n return await toMatchTextFile(\n () =>\n markdownTableSnapshot(actual, {\n showSortIndicator,\n normalizers,\n }),\n {\n ...matchFileOptions,\n fileExtension: \"md\",\n },\n );\n }\n\n return baseExpect.extend({\n toMatchSemanticSnapshotFile,\n toMatchMarkdownTableSnapshotFile,\n });\n}\n","import type { TextSnapshot } from \"../types/elements/text\";\nimport type { NodeSnapshot } from \"../types/snapshot\";\n\nimport { filter } from \"./filter\";\nimport { isTextSnapshot } from \"./guards\";\n\n/**\n * Aggregates and normalizes the text content of all provided snapshots\n */\nexport function getTextContent(snapshots: Array<NodeSnapshot>): string {\n const texts = filter({\n snapshots,\n predicate: isTextSnapshot,\n });\n\n return mergeTexts(texts);\n}\n\nexport function normalizeText(text: string): string {\n return text.replaceAll(/\\s+/g, \" \").trim();\n}\n\nexport function mergeTexts(texts: Array<TextSnapshot>): string {\n const mergedText = texts.map((textNode) => textNode.name).join(\" \");\n return normalizeText(mergedText);\n}\n"],"mappings":";;;;;;;AAGA,SAAgB,eACd,UAC0B;CAC1B,OAAO,QAAQ,QAAQ,QAAQ;AACjC;AAEA,SAAgB,QACd,MACA,UACmC;CACnC,IAAI,OAAO,SAAS,UAClB,OAAO,SAAS,SAAS;CAG3B,OAAO,KAAK,SAAS,SAAS,IAAa;AAC7C;AAEA,SAAgB,QACd,OACS;CACT,IAAI,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAClD,OAAO,MAAM,WAAW;CAG1B,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW;AACvC;;;;;ACpBA,SAAgB,YACd,MAC+C;CAC/C,QAAQ,aAA2B,QAAQ,MAAM,QAAQ;AAC3D;;;;AAKA,SAAgB,YACd,MAC+C;CAC/C,QAAQ,aACN,CAAC,QAAQ,MAAM,QAAQ;AAC3B;;AC6BA,SAAgB,OACd,SACkB;CAClB,MAAM,EAAE,WAAW,WAAW,UAAU,UAAU;CAElD,OAAO,UAAU,SAAS,aAAa;EACrC,MAAM,eAAe,UAAU,QAAQ;EAGvC,IAAI,gBAAgB,CAAC,SACnB,OAAO;EAIT,IAAI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