@cronn/element-snapshot 0.26.0 → 0.28.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/dist/index.d.mts +13 -7
- package/dist/index.mjs +19 -9
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Expect, Locator, MatcherReturnType } from "@playwright/test";
|
|
1
|
+
import { Expect, Locator, MatcherReturnType, Page } from "@playwright/test";
|
|
2
2
|
import { PlaywrightMatchJsonFileOptions, PlaywrightMatchTextFileOptions, PlaywrightValidationFileMatcherConfig } from "@cronn/playwright-file-snapshots";
|
|
3
|
+
import { MarkdownTableNormalizer } from "@cronn/lib-file-snapshots";
|
|
3
4
|
//#region src/playwright/markdown-table.d.ts
|
|
4
5
|
interface MarkdownTableSnapshotOptions {
|
|
5
6
|
/**
|
|
@@ -8,6 +9,10 @@ interface MarkdownTableSnapshotOptions {
|
|
|
8
9
|
* @default true
|
|
9
10
|
*/
|
|
10
11
|
showSortIndicator?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Custom normalizers to apply before serialization
|
|
14
|
+
*/
|
|
15
|
+
normalizers?: Array<MarkdownTableNormalizer>;
|
|
11
16
|
}
|
|
12
17
|
/**
|
|
13
18
|
* Creates a Markdown table snapshot from a table or grid element
|
|
@@ -46,6 +51,7 @@ type PressedValue = true | "mixed";
|
|
|
46
51
|
//#endregion
|
|
47
52
|
//#region src/types/utils.d.ts
|
|
48
53
|
type SetValues<TSet> = TSet extends Set<infer TValue> ? TValue : never;
|
|
54
|
+
type PlaywrightTarget = Page | Locator;
|
|
49
55
|
//#endregion
|
|
50
56
|
//#region src/types/elements/container.d.ts
|
|
51
57
|
declare const CONTAINER_ROLES: Set<"alert" | "article" | "banner" | "blockquote" | "code" | "complementary" | "contentinfo" | "definition" | "deletion" | "descriptionlist" | "emphasis" | "form" | "grid" | "insertion" | "label" | "list" | "listbox" | "listitem" | "log" | "main" | "mark" | "menu" | "navigation" | "note" | "paragraph" | "row" | "rowgroup" | "search" | "status" | "strong" | "subscript" | "superscript" | "table" | "tablist" | "tabpanel" | "term" | "tree">;
|
|
@@ -230,29 +236,29 @@ interface SemanticSnapshotOptions {
|
|
|
230
236
|
* This function creates a raw snapshot of the DOM element identified by the locator
|
|
231
237
|
* and transforms it into a semantic representation using the provided options.
|
|
232
238
|
*
|
|
233
|
-
* @param
|
|
239
|
+
* @param target - The Page or Locator instance that identifies the DOM element to snapshot
|
|
234
240
|
* @param options - Optional configuration settings for controlling the snapshot behavior
|
|
235
241
|
* @return A promise that resolves to the semantic snapshot
|
|
236
242
|
*/
|
|
237
|
-
declare function semanticSnapshot(
|
|
243
|
+
declare function semanticSnapshot(target: PlaywrightTarget, options?: SemanticSnapshotOptions): Promise<unknown>;
|
|
238
244
|
/**
|
|
239
245
|
* Captures a raw snapshot of the element matched by the provided locator.
|
|
240
246
|
*
|
|
241
247
|
* Returns an array of node snapshots representing the current state of the matched elements
|
|
242
248
|
* in the DOM, including their properties, attributes, and structure.
|
|
243
249
|
*
|
|
244
|
-
* @param
|
|
250
|
+
* @param target - The Page or Locator instance used to identify the target element to snapshot
|
|
245
251
|
* @return A promise that resolves to an array of NodeSnapshot objects representing the captured element
|
|
246
252
|
*/
|
|
247
|
-
declare function rawSnapshot(
|
|
253
|
+
declare function rawSnapshot(target: PlaywrightTarget): Promise<Array<NodeSnapshot>>;
|
|
248
254
|
//#endregion
|
|
249
255
|
//#region src/types/matchers.d.ts
|
|
250
256
|
interface ElementSnapshotMatchers {
|
|
251
|
-
toMatchSemanticSnapshotFile: (actual:
|
|
257
|
+
toMatchSemanticSnapshotFile: (actual: PlaywrightTarget, options?: MatchSemanticSnapshotFileOptions) => Promise<MatcherReturnType>;
|
|
252
258
|
toMatchMarkdownTableSnapshotFile: (actual: Locator, options?: MatchMarkdownTableSnapshotFileOptions) => Promise<MatcherReturnType>;
|
|
253
259
|
}
|
|
254
260
|
interface MatchSemanticSnapshotFileOptions extends PlaywrightMatchJsonFileOptions, SemanticSnapshotOptions {}
|
|
255
|
-
interface MatchMarkdownTableSnapshotFileOptions extends Omit<PlaywrightMatchTextFileOptions, "fileExtension">, MarkdownTableSnapshotOptions {}
|
|
261
|
+
interface MatchMarkdownTableSnapshotFileOptions extends Omit<PlaywrightMatchTextFileOptions, "fileExtension" | "normalizers">, MarkdownTableSnapshotOptions {}
|
|
256
262
|
//#endregion
|
|
257
263
|
//#region src/playwright/matchers.d.ts
|
|
258
264
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -199,12 +199,12 @@ var SemanticSnapshotTransformer = class {
|
|
|
199
199
|
* This function creates a raw snapshot of the DOM element identified by the locator
|
|
200
200
|
* and transforms it into a semantic representation using the provided options.
|
|
201
201
|
*
|
|
202
|
-
* @param
|
|
202
|
+
* @param target - The Page or Locator instance that identifies the DOM element to snapshot
|
|
203
203
|
* @param options - Optional configuration settings for controlling the snapshot behavior
|
|
204
204
|
* @return A promise that resolves to the semantic snapshot
|
|
205
205
|
*/
|
|
206
|
-
async function semanticSnapshot(
|
|
207
|
-
const snapshot = await rawSnapshot(
|
|
206
|
+
async function semanticSnapshot(target, options) {
|
|
207
|
+
const snapshot = await rawSnapshot(target);
|
|
208
208
|
return new SemanticSnapshotTransformer(options).transform(snapshot);
|
|
209
209
|
}
|
|
210
210
|
/**
|
|
@@ -213,12 +213,16 @@ async function semanticSnapshot(locator, options) {
|
|
|
213
213
|
* Returns an array of node snapshots representing the current state of the matched elements
|
|
214
214
|
* in the DOM, including their properties, attributes, and structure.
|
|
215
215
|
*
|
|
216
|
-
* @param
|
|
216
|
+
* @param target - The Page or Locator instance used to identify the target element to snapshot
|
|
217
217
|
* @return A promise that resolves to an array of NodeSnapshot objects representing the captured element
|
|
218
218
|
*/
|
|
219
|
-
async function rawSnapshot(
|
|
219
|
+
async function rawSnapshot(target) {
|
|
220
|
+
const locator = isPage(target) ? target.locator("body") : target;
|
|
220
221
|
return await new ElementSnapshotProxy(locator.page()).snapshotElement(locator);
|
|
221
222
|
}
|
|
223
|
+
function isPage(target) {
|
|
224
|
+
return "goto" in target && typeof target.goto === "function";
|
|
225
|
+
}
|
|
222
226
|
//#endregion
|
|
223
227
|
//#region src/playwright/markdown-table.ts
|
|
224
228
|
const tableRoles = ["table", "grid"];
|
|
@@ -236,8 +240,9 @@ const sortIndicators = {
|
|
|
236
240
|
* Creates a Markdown table snapshot from a table or grid element
|
|
237
241
|
*/
|
|
238
242
|
async function markdownTableSnapshot(locator, options = {}) {
|
|
239
|
-
const
|
|
240
|
-
|
|
243
|
+
const { showSortIndicator, normalizers } = options;
|
|
244
|
+
const parsedTable = parseTable(await rawSnapshot(locator), { showSortIndicator });
|
|
245
|
+
return new MarkdownTableSerializer({ normalizers }).serialize(parsedTable);
|
|
241
246
|
}
|
|
242
247
|
function parseTable(snapshot, options) {
|
|
243
248
|
const { showSortIndicator = true } = options;
|
|
@@ -285,8 +290,13 @@ function defineElementSnapshotMatchers(config = {}) {
|
|
|
285
290
|
return await defineJsonFileMatcher("toMatchSemanticSnapshotFile", config).bind(this)(() => semanticSnapshot(actual, options), options);
|
|
286
291
|
}
|
|
287
292
|
async function toMatchMarkdownTableSnapshotFile(actual, options = {}) {
|
|
288
|
-
|
|
289
|
-
|
|
293
|
+
const toMatchTextFile = defineTextFileMatcher("toMatchMarkdownTableSnapshotFile", config).bind(this);
|
|
294
|
+
const { showSortIndicator, normalizers, ...matchFileOptions } = options;
|
|
295
|
+
return await toMatchTextFile(() => markdownTableSnapshot(actual, {
|
|
296
|
+
showSortIndicator,
|
|
297
|
+
normalizers
|
|
298
|
+
}), {
|
|
299
|
+
...matchFileOptions,
|
|
290
300
|
fileExtension: "md"
|
|
291
301
|
});
|
|
292
302
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cronn/element-snapshot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Element snapshots for Playwright",
|
|
5
5
|
"homepage": "https://cronn.github.io/file-snapshots/playwright/element-snapshots/",
|
|
6
6
|
"bugs": {
|
|
@@ -35,20 +35,20 @@
|
|
|
35
35
|
"@types/node": "24.13.3",
|
|
36
36
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
37
37
|
"@vitest/coverage-v8": "4.1.10",
|
|
38
|
-
"eslint": "10.8.
|
|
38
|
+
"eslint": "10.8.1",
|
|
39
39
|
"eslint-config-prettier": "10.1.8",
|
|
40
40
|
"eslint-plugin-check-file": "3.3.2",
|
|
41
41
|
"eslint-plugin-unused-imports": "4.4.1",
|
|
42
|
-
"publint": "0.3.
|
|
42
|
+
"publint": "0.3.23",
|
|
43
43
|
"rimraf": "6.1.3",
|
|
44
44
|
"tsdown": "0.22.14",
|
|
45
45
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
46
|
-
"typescript-eslint": "8.
|
|
46
|
+
"typescript-eslint": "8.67.0",
|
|
47
47
|
"vitest": "4.1.10",
|
|
48
|
-
"node": "runtime:24.
|
|
49
|
-
"@cronn/
|
|
48
|
+
"node": "runtime:24.19.0",
|
|
49
|
+
"@cronn/shared-configs": "0.0.0",
|
|
50
50
|
"@cronn/test-utils": "0.0.0",
|
|
51
|
-
"@cronn/
|
|
51
|
+
"@cronn/vitest-file-snapshots": "2.1.2"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@playwright/test": "^1.55"
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"devEngines": {
|
|
57
57
|
"packageManager": {
|
|
58
58
|
"name": "pnpm",
|
|
59
|
-
"version": "11.
|
|
59
|
+
"version": "11.22.0",
|
|
60
60
|
"onFail": "download"
|
|
61
61
|
},
|
|
62
62
|
"runtime": {
|
|
63
63
|
"name": "node",
|
|
64
|
-
"version": "24.
|
|
64
|
+
"version": "24.19.0",
|
|
65
65
|
"onFail": "download"
|
|
66
66
|
}
|
|
67
67
|
},
|