@rickcedwhat/playwright-smart-table 6.24.0-next.cc0fbcb → 6.25.0-next.3dfcc94

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.
@@ -25,6 +25,8 @@ export declare class RowFinder<T = any> {
25
25
  maxPages?: number;
26
26
  }): Promise<SmartRow<T>>;
27
27
  private waitForTableReady;
28
+ /** Unfiltered rows keep the plain `SmartRow #n` name that `_makeSmart` applies. */
29
+ private nameFilteredRow;
28
30
  findRows(filters?: Record<string, FilterValue>, options?: {
29
31
  exact?: boolean;
30
32
  maxPages?: number;
@@ -9,6 +9,7 @@ const navigationBarrier_1 = require("../utils/navigationBarrier");
9
9
  const rowResolution_1 = require("./rowResolution");
10
10
  const resolveCellLocator_1 = require("../utils/resolveCellLocator");
11
11
  const scanPages_1 = require("./scanPages");
12
+ const locatorDescription_1 = require("../utils/locatorDescription");
12
13
  const loadingWait_1 = require("../utils/loadingWait");
13
14
  class RowFinder {
14
15
  constructor(rootLocator, config, resolve, filterEngine, tableMapper, makeSmartRow, tableState = { currentPageIndex: 0 }, advancePage = async () => false) {
@@ -111,12 +112,13 @@ class RowFinder {
111
112
  await (0, debugUtils_1.debugDelay)(this.config, 'findRow');
112
113
  const map = await this.tableMapper.getMap();
113
114
  const resolved = await this.resolveRowIndex(rowLocator);
114
- return this.makeSmartRow(rowLocator, map, resolved === null || resolved === void 0 ? void 0 : resolved.index, this.tableState.currentPageIndex, undefined, resolved === null || resolved === void 0 ? void 0 : resolved.selector);
115
+ const describedRow = (0, locatorDescription_1.describeLocator)(rowLocator, (0, locatorDescription_1.describeRowByFilters)(filters), this.config);
116
+ return this.makeSmartRow(describedRow, map, resolved === null || resolved === void 0 ? void 0 : resolved.index, this.tableState.currentPageIndex, undefined, resolved === null || resolved === void 0 ? void 0 : resolved.selector);
115
117
  }
116
118
  (0, debugUtils_1.logDebug)(this.config, 'error', 'Row not found', filters);
117
119
  await (0, debugUtils_1.debugDelay)(this.config, 'findRow');
118
- const sentinel = this.resolve(this.config.rowSelector, this.rootLocator)
119
- .filter({ hasText: "___SENTINEL_ROW_NOT_FOUND___" + Date.now() });
120
+ const sentinel = (0, locatorDescription_1.describeLocator)(this.resolve(this.config.rowSelector, this.rootLocator)
121
+ .filter({ hasText: "___SENTINEL_ROW_NOT_FOUND___" + Date.now() }), (0, locatorDescription_1.describeSentinelRow)(filters), this.config);
120
122
  const smartRow = this.makeSmartRow(sentinel, await this.tableMapper.getMap(), undefined);
121
123
  smartRow[sentinel_1.SENTINEL_ROW] = true;
122
124
  return smartRow;
@@ -134,6 +136,12 @@ class RowFinder {
134
136
  };
135
137
  await (0, loadingWait_1.waitWhileTableLoading)(this.config, context, this.rootLocator.page(), 'waitForTableReady');
136
138
  }
139
+ /** Unfiltered rows keep the plain `SmartRow #n` name that `_makeSmart` applies. */
140
+ nameFilteredRow(row, resolved, filters) {
141
+ if (!resolved || Object.keys(filters).length === 0)
142
+ return row;
143
+ return (0, locatorDescription_1.describeLocator)(row, (0, locatorDescription_1.describeRowByIndex)(resolved.index, filters), this.config);
144
+ }
137
145
  async findRows(filters = {}, options) {
138
146
  var _a;
139
147
  var _b, _c;
@@ -168,7 +176,8 @@ class RowFinder {
168
176
  const barrier = useBarrier ? new navigationBarrier_1.NavigationBarrier(newIndices.length) : undefined;
169
177
  for (const idx of newIndices) {
170
178
  const resolved = await (0, rowResolution_1.resolveLogicalRowIndex)(currentRows[idx], this.config, () => allRows.length);
171
- const smartRow = this.makeSmartRow(currentRows[idx], map, resolved === null || resolved === void 0 ? void 0 : resolved.index, this.tableState.currentPageIndex, barrier, resolved === null || resolved === void 0 ? void 0 : resolved.selector);
179
+ const rowLocator = this.nameFilteredRow(currentRows[idx], resolved, filtersRecord);
180
+ const smartRow = this.makeSmartRow(rowLocator, map, resolved === null || resolved === void 0 ? void 0 : resolved.index, this.tableState.currentPageIndex, barrier, resolved === null || resolved === void 0 ? void 0 : resolved.selector);
172
181
  const loadingOutcome = await (0, rowResolution_1.resolveRowLoading)(smartRow, this.config.strategies.loading, 'skip', (msg) => (0, debugUtils_1.logDebug)(this.config, 'verbose', `findRows: ${msg}`));
173
182
  if (loadingOutcome !== 'process') {
174
183
  barrier === null || barrier === void 0 ? void 0 : barrier.markFinished();
@@ -45,8 +45,9 @@ async function runMap(env, callback, options = {}, label = 'map') {
45
45
  let rowIndex = 0;
46
46
  let stopped = false;
47
47
  let stoppedIndex = Infinity;
48
+ // In parallel/synchronized mode rows can call stop() out of order; the earliest row wins.
48
49
  const stop = (idx) => {
49
- if (!stopped) {
50
+ if (idx < stoppedIndex) {
50
51
  log(env.config, `${label}: stop() called at row ${idx} — halting`);
51
52
  stopped = true;
52
53
  stoppedIndex = idx;
@@ -3,4 +3,4 @@
3
3
  * Generated by scripts/embed-version.mjs from package.json
4
4
  */
5
5
  /** Semver of this package. Use in logs or diagnostics to confirm the installed build. */
6
- export declare const PLAYWRIGHT_SMART_TABLE_VERSION: "6.24.0-next.cc0fbcb";
6
+ export declare const PLAYWRIGHT_SMART_TABLE_VERSION: "6.25.0-next.3dfcc94";
@@ -6,4 +6,4 @@ exports.PLAYWRIGHT_SMART_TABLE_VERSION = void 0;
6
6
  * Generated by scripts/embed-version.mjs from package.json
7
7
  */
8
8
  /** Semver of this package. Use in logs or diagnostics to confirm the installed build. */
9
- exports.PLAYWRIGHT_SMART_TABLE_VERSION = "6.24.0-next.cc0fbcb";
9
+ exports.PLAYWRIGHT_SMART_TABLE_VERSION = "6.25.0-next.3dfcc94";
package/dist/smartRow.js CHANGED
@@ -7,6 +7,7 @@ const debugUtils_1 = require("./utils/debugUtils");
7
7
  const paginationPath_1 = require("./utils/paginationPath");
8
8
  const sentinel_1 = require("./utils/sentinel");
9
9
  const pageIndex_1 = require("./utils/pageIndex");
10
+ const locatorDescription_1 = require("./utils/locatorDescription");
10
11
  /**
11
12
  * Internal helper to navigate to a cell with active cell optimization.
12
13
  * Uses `strategies.navigation` primitives (goUp/goDown/goLeft/goRight, optional snap/seek/goHome).
@@ -328,7 +329,7 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
328
329
  // Attach Methods
329
330
  smart.getCell = (colName) => {
330
331
  var _a;
331
- var _b;
332
+ var _b, _c;
332
333
  if ((_a = config.syntheticColumns) === null || _a === void 0 ? void 0 : _a[colName]) {
333
334
  throw new Error(`Column "${colName}" is synthetic (no DOM cell) — use getValue("${colName}") or toJSON() instead`);
334
335
  }
@@ -351,7 +352,8 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
351
352
  else {
352
353
  baseLocator = resolve(config.cellSelector, rowLocator).nth(idx);
353
354
  }
354
- const smartCell = baseLocator;
355
+ const cellDescription = `${(_c = (0, locatorDescription_1.getLocatorDescription)(rowLocator)) !== null && _c !== void 0 ? _c : 'SmartRow'} › "${colName}" cell`;
356
+ const smartCell = (0, locatorDescription_1.describeLocator)(baseLocator, cellDescription, config);
355
357
  smartCell.bringIntoView = async () => {
356
358
  const page = rootLocator.page();
357
359
  const navigatedCell = await _navigateToCell({
@@ -850,36 +852,44 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
850
852
  barrier: smart._barrier
851
853
  });
852
854
  const columnOverride = (_b = config.columnOverrides) === null || _b === void 0 ? void 0 : _b[colName];
853
- if (columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.write) {
854
- const cellLocator = smart.getCell(colName);
855
- let currentValue;
856
- if (columnOverride.read) {
857
- currentValue = await columnOverride.read(cellLocator, {
858
- row: smart, columnName: colName, columnIndex: colIdx,
859
- getCell: (name) => smart.getCell(name),
855
+ try {
856
+ if (columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.write) {
857
+ const cellLocator = smart.getCell(colName);
858
+ let currentValue;
859
+ if (columnOverride.read) {
860
+ currentValue = await columnOverride.read(cellLocator, {
861
+ row: smart, columnName: colName, columnIndex: colIdx,
862
+ getCell: (name) => smart.getCell(name),
863
+ });
864
+ }
865
+ await columnOverride.write({
866
+ cell: cellLocator,
867
+ targetValue: value,
868
+ currentValue,
869
+ row: smart
870
+ });
871
+ }
872
+ else {
873
+ const strategy = config.strategies.fill || fill_1.FillStrategies.default;
874
+ (0, debugUtils_1.logDebug)(config, 'verbose', `Filling cell "${colName}" with value`, value);
875
+ await strategy({
876
+ row: smart,
877
+ columnName: colName,
878
+ value,
879
+ index: rowIndex !== null && rowIndex !== void 0 ? rowIndex : -1,
880
+ page: rowLocator.page(),
881
+ rootLocator,
882
+ config,
883
+ table: table,
884
+ fillOptions
860
885
  });
861
886
  }
862
- await columnOverride.write({
863
- cell: cellLocator,
864
- targetValue: value,
865
- currentValue,
866
- row: smart
867
- });
868
887
  }
869
- else {
870
- const strategy = config.strategies.fill || fill_1.FillStrategies.default;
871
- (0, debugUtils_1.logDebug)(config, 'verbose', `Filling cell "${colName}" with value`, value);
872
- await strategy({
873
- row: smart,
874
- columnName: colName,
875
- value,
876
- index: rowIndex !== null && rowIndex !== void 0 ? rowIndex : -1,
877
- page: rowLocator.page(),
878
- rootLocator,
879
- config,
880
- table: table,
881
- fillOptions
882
- });
888
+ catch (err) {
889
+ const source = (columnOverride === null || columnOverride === void 0 ? void 0 : columnOverride.write) ? 'columnOverrides.write' : 'fill strategy';
890
+ const wrapped = new Error(`[SmartTable] smartFill: ${source} for "${colName}" failed — ${err instanceof Error ? err.message : String(err)}`);
891
+ wrapped.cause = err;
892
+ throw wrapped;
883
893
  }
884
894
  // Delay after filling
885
895
  await (0, debugUtils_1.debugDelay)(config, 'getCell');
package/dist/types.d.ts CHANGED
@@ -760,6 +760,14 @@ export type RowIterationContext<T = any> = {
760
760
  index: number;
761
761
  /** 0-based page index — which page this row was collected from. */
762
762
  pageIndex: number;
763
+ /**
764
+ * Ends the iteration. No further pages are loaded, and the result of `map` / `filter`
765
+ * includes this row and nothing after it. If several rows call `stop()`, the earliest one wins.
766
+ *
767
+ * In `'sequential'` mode (the default) no callback after this row runs. In `'parallel'` and
768
+ * `'synchronized'` mode the rest of the current page is already in flight, so later rows'
769
+ * callbacks may still run (and their side effects happen) even though their results are dropped.
770
+ */
763
771
  stop: () => void;
764
772
  };
765
773
  /** Concurrency modes for row iteration. */
@@ -935,7 +943,8 @@ export interface TableResult<T = any> extends AsyncIterable<{
935
943
  /**
936
944
  * Iterates every row across all pages, calling the callback for side effects.
937
945
  * Execution is sequential by default (safe for interactions like clicking/filling).
938
- * Call `stop()` in the callback to end iteration early.
946
+ * Call `stop()` in the callback to end iteration early. In sequential mode no later row runs;
947
+ * in parallel mode the rest of the current page may still run (see `RowIterationContext.stop`).
939
948
  *
940
949
  * @param callback - Function receiving { row, rowIndex, stop }
941
950
  * @param options - maxPages, concurrency, dedupe, useBulkPagination
@@ -952,7 +961,8 @@ export interface TableResult<T = any> extends AsyncIterable<{
952
961
  * Defaults to `concurrency: 'sequential'` (safe for clicks/fills). Pass
953
962
  * `concurrency: 'parallel'` for read-only extraction, or `'synchronized'` when
954
963
  * navigation must stay lock-step on virtualized grids.
955
- * Call `stop()` to halt after the current page finishes.
964
+ * Call `stop()` to end early: the result includes the row that called it and nothing after it
965
+ * (in parallel mode, later rows on the same page may still run; see `RowIterationContext.stop`).
956
966
  *
957
967
  * @param callback - Function receiving { row, rowIndex, stop }
958
968
  * @param options - maxPages, concurrency, dedupe, useBulkPagination
package/dist/useTable.js CHANGED
@@ -35,6 +35,7 @@ const elementTracker_1 = require("./utils/elementTracker");
35
35
  const loadingWait_1 = require("./utils/loadingWait");
36
36
  const pageIndex_1 = require("./utils/pageIndex");
37
37
  const smartRowInternals_1 = require("./utils/smartRowInternals");
38
+ const locatorDescription_1 = require("./utils/locatorDescription");
38
39
  // Helper to safely serialize objects containing functions for logging
39
40
  const safeStringify = (obj) => {
40
41
  try {
@@ -153,7 +154,13 @@ const useTable = (rootLocator, configOptions = {}) => {
153
154
  const effectiveLocator = healSelector
154
155
  ? rootLocator.locator(healSelector)
155
156
  : rowLocator;
156
- const sr = (0, smartRow_1.default)(effectiveLocator, map, rowIndex, config, rootLocator, resolve, finalTable, tablePageIndex, barrier, renderWindowPosition);
157
+ // Keep a caller-supplied description (e.g. the filters) across self-healing; otherwise name the row by index.
158
+ const existingDescription = (0, locatorDescription_1.getLocatorDescription)(rowLocator);
159
+ const description = existingDescription !== null && existingDescription !== void 0 ? existingDescription : (rowIndex !== undefined ? (0, locatorDescription_1.describeRowByIndex)(rowIndex) : undefined);
160
+ const describedLocator = description !== undefined && (healSelector !== undefined || existingDescription === undefined)
161
+ ? (0, locatorDescription_1.describeLocator)(effectiveLocator, description, config)
162
+ : effectiveLocator;
163
+ const sr = (0, smartRow_1.default)(describedLocator, map, rowIndex, config, rootLocator, resolve, finalTable, tablePageIndex, barrier, renderWindowPosition);
157
164
  if (healSelector)
158
165
  (0, smartRowInternals_1.internals)(sr)._selfHealing = true;
159
166
  return sr;
@@ -514,7 +521,8 @@ const useTable = (rootLocator, configOptions = {}) => {
514
521
  throw new Error('Initialization Error: You attempted to access a row before the table structure was mapped. Please call "await table.init()" once before using synchronous row access.');
515
522
  const allRows = resolve(config.rowSelector, rootLocator);
516
523
  const matchedRows = filterEngine.applyFilters(allRows, filters, map, options.exact || false, rootLocator.page(), rootLocator);
517
- return _makeSmart(matchedRows, map, undefined); // sync path cannot compute real index
524
+ const describedRows = (0, locatorDescription_1.describeLocator)(matchedRows, (0, locatorDescription_1.describeRowByFilters)(filters), config);
525
+ return _makeSmart(describedRows, map, undefined); // sync path cannot compute real index
518
526
  },
519
527
  getRowByIndex: (index) => {
520
528
  log(`getRowByIndex: index=${index}`);
@@ -0,0 +1,15 @@
1
+ import type { Locator } from '@playwright/test';
2
+ import type { FilterValue, FinalTableConfig } from '../types';
3
+ /** `Name="Alice", Status=/act/i` — readable in traces, unlike JSON.stringify (which turns RegExp into `{}`). */
4
+ export declare const formatFilters: (filters: Record<string, FilterValue>) => string;
5
+ export declare const describeRowByFilters: (filters: Record<string, FilterValue>) => string;
6
+ /** `SmartRow #3`, or `SmartRow #3 where Dept="Eng"` when the row came from a filtered search. */
7
+ export declare const describeRowByIndex: (rowIndex: number, filters?: Record<string, FilterValue>) => string;
8
+ export declare const describeSentinelRow: (filters: Record<string, FilterValue>) => string;
9
+ /**
10
+ * Applies `locator.describe()` (Playwright 1.53+) so traces, HTML reports and error messages show a
11
+ * readable name instead of the raw selector chain. Older Playwright versions get the locator back unchanged.
12
+ */
13
+ export declare const describeLocator: (locator: Locator, description: string, config?: FinalTableConfig) => Locator;
14
+ /** The description already applied to a locator, or undefined (unsupported or never described). */
15
+ export declare const getLocatorDescription: (locator: Locator) => string | undefined;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLocatorDescription = exports.describeLocator = exports.describeSentinelRow = exports.describeRowByIndex = exports.describeRowByFilters = exports.formatFilters = void 0;
4
+ const debugUtils_1 = require("./debugUtils");
5
+ const MAX_VALUE_LENGTH = 40;
6
+ const locatorDescriptions = new WeakMap();
7
+ let loggedUnsupported = false;
8
+ const formatFilterValue = (value) => {
9
+ if (value instanceof RegExp)
10
+ return value.toString();
11
+ if (typeof value === 'function')
12
+ return '<locator filter>';
13
+ if (typeof value === 'number')
14
+ return String(value);
15
+ const text = value.length > MAX_VALUE_LENGTH ? `${value.slice(0, MAX_VALUE_LENGTH)}…` : value;
16
+ return JSON.stringify(text);
17
+ };
18
+ /** `Name="Alice", Status=/act/i` — readable in traces, unlike JSON.stringify (which turns RegExp into `{}`). */
19
+ const formatFilters = (filters) => Object.entries(filters).map(([col, value]) => `${col}=${formatFilterValue(value)}`).join(', ');
20
+ exports.formatFilters = formatFilters;
21
+ const describeRowByFilters = (filters) => {
22
+ const formatted = (0, exports.formatFilters)(filters);
23
+ return formatted ? `SmartRow where ${formatted}` : 'SmartRow';
24
+ };
25
+ exports.describeRowByFilters = describeRowByFilters;
26
+ /** `SmartRow #3`, or `SmartRow #3 where Dept="Eng"` when the row came from a filtered search. */
27
+ const describeRowByIndex = (rowIndex, filters = {}) => {
28
+ const formatted = (0, exports.formatFilters)(filters);
29
+ return formatted ? `SmartRow #${rowIndex} where ${formatted}` : `SmartRow #${rowIndex}`;
30
+ };
31
+ exports.describeRowByIndex = describeRowByIndex;
32
+ const describeSentinelRow = (filters) => {
33
+ const formatted = (0, exports.formatFilters)(filters);
34
+ return formatted ? `SmartRow not found: ${formatted}` : 'SmartRow not found';
35
+ };
36
+ exports.describeSentinelRow = describeSentinelRow;
37
+ /**
38
+ * Applies `locator.describe()` (Playwright 1.53+) so traces, HTML reports and error messages show a
39
+ * readable name instead of the raw selector chain. Older Playwright versions get the locator back unchanged.
40
+ */
41
+ const describeLocator = (locator, description, config) => {
42
+ if (typeof locator.describe === 'function') {
43
+ const described = locator.describe(description);
44
+ locatorDescriptions.set(described, description);
45
+ return described;
46
+ }
47
+ if ((config === null || config === void 0 ? void 0 : config.debug) && !loggedUnsupported) {
48
+ loggedUnsupported = true;
49
+ (0, debugUtils_1.logDebug)(config, 'info', 'Upgrade @playwright/test to 1.53+ to see SmartRow / SmartCell names in traces and error messages');
50
+ }
51
+ return locator;
52
+ };
53
+ exports.describeLocator = describeLocator;
54
+ /** The description already applied to a locator, or undefined (unsupported or never described). */
55
+ const getLocatorDescription = (locator) => { var _a; return typeof locator.description === 'function' ? (_a = locator.description()) !== null && _a !== void 0 ? _a : undefined : locatorDescriptions.get(locator); };
56
+ exports.getLocatorDescription = getLocatorDescription;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickcedwhat/playwright-smart-table",
3
- "version": "6.24.0-next.cc0fbcb",
3
+ "version": "6.25.0-next.3dfcc94",
4
4
  "description": "Smart, column-aware table interactions for Playwright",
5
5
  "author": "Cedrick Catalan",
6
6
  "license": "MIT",