Skip to content

Commit a341258

Browse files
committed
fix: suppress sparse hint for depth-limited snapshots
1 parent 84033c7 commit a341258

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/commands/cli-output.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const cliOutputFormatters: Partial<Record<CommandName, CliOutputFormatter>> = {
6363
raw: input.raw as boolean | undefined,
6464
interactiveOnly: input.interactiveOnly as boolean | undefined,
6565
scope: input.scope as string | undefined,
66+
depth: input.depth as number | undefined,
6667
}),
6768
wait: messageOutput,
6869
alert: messageOutput,

src/commands/client-output.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export function snapshotCliOutput(params: {
108108
raw?: boolean;
109109
interactiveOnly?: boolean;
110110
scope?: string;
111+
depth?: number;
111112
}): CliOutput {
112113
const data = serializeSnapshotResult(params.result);
113114
return {
@@ -118,6 +119,7 @@ export function snapshotCliOutput(params: {
118119
raw: params.raw,
119120
flatten: params.interactiveOnly,
120121
scoped: typeof params.scope === 'string' && params.scope.trim().length > 0,
122+
depthLimited: typeof params.depth === 'number',
121123
}),
122124
};
123125
}

src/utils/__tests__/output.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,28 @@ test('formatSnapshotText suppresses sparse snapshot hint for scoped reads', () =
13391339
assert.doesNotMatch(text, /sparse accessibility snapshot/);
13401340
});
13411341

1342+
test('formatSnapshotText suppresses sparse snapshot hint for depth-limited reads', () => {
1343+
const text = withNoColor(() =>
1344+
formatSnapshotText(
1345+
{
1346+
nodes: [
1347+
{
1348+
ref: 'e1',
1349+
index: 0,
1350+
depth: 0,
1351+
type: 'Application',
1352+
label: 'Main',
1353+
},
1354+
],
1355+
truncated: false,
1356+
},
1357+
{ depthLimited: true },
1358+
),
1359+
);
1360+
1361+
assert.doesNotMatch(text, /sparse accessibility snapshot/);
1362+
});
1363+
13421364
test('formatSnapshotText keeps flattened output and adds duplicate nav warning', () => {
13431365
const nodes = Array.from({ length: 24 }, (_, index) => ({
13441366
ref: `e${index + 1}`,

src/utils/output.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type SnapshotTextOptions = {
5959
raw?: boolean;
6060
flatten?: boolean;
6161
scoped?: boolean;
62+
depthLimited?: boolean;
6263
};
6364

6465
export function formatSnapshotText(
@@ -632,9 +633,9 @@ function buildSnapshotNotices(
632633

633634
function formatSparseSnapshotHint(
634635
nodes: SnapshotNode[],
635-
options: Pick<SnapshotTextOptions, 'scoped'>,
636+
options: Pick<SnapshotTextOptions, 'scoped' | 'depthLimited'>,
636637
): string | null {
637-
if (options.scoped === true || nodes.length > 3) return null;
638+
if (options.scoped === true || options.depthLimited === true || nodes.length > 3) return null;
638639
const noun = nodes.length === 1 ? 'node' : 'nodes';
639640
return `Hint: sparse accessibility snapshot returned ${nodes.length} ${noun}. The app may expose limited accessibility metadata; run screenshot --overlay-refs for visual context.`;
640641
}

0 commit comments

Comments
 (0)