Skip to content

feat(aria-snapshot): add numberSubstitution option for baseline generation#40977

Open
adityasingh2400 wants to merge 1 commit into
microsoft:mainfrom
adityasingh2400:adityasingh2400/aria-snapshot-number-substitution
Open

feat(aria-snapshot): add numberSubstitution option for baseline generation#40977
adityasingh2400 wants to merge 1 commit into
microsoft:mainfrom
adityasingh2400:adityasingh2400/aria-snapshot-number-substitution

Conversation

@adityasingh2400
Copy link
Copy Markdown

Closes #40080.

The aria-snapshot baseline generator currently rewrites numbers and dates into \d+ regexes, which is helpful for live UIs but unwanted for tests against mocked endpoints where the values are stable. This adds a numberSubstitution: 'regex' | 'static' option (default 'regex' so existing baselines do not change) that can be set per matcher call or globally via the expect.toMatchAriaSnapshot config.

Usage:

// per call
await expect(page.locator('body')).toMatchAriaSnapshot(`...`, { numberSubstitution: 'static' });

// globally
export default defineConfig({
  expect: {
    toMatchAriaSnapshot: { numberSubstitution: 'static' },
  },
});

The option is plumbed through expressionArg on the existing to.match.aria channel, then read inside matchesExpectAriaTemplate to gate the regex-rewrite step in renderAriaTree's codegen mode.

Tests cover both modes plus the existing default behavior, including the precedence where a per-call option overrides the global config.

…ation

Closes microsoft#40080.

The aria-snapshot baseline generator currently rewrites numbers and dates
into \d+ regexes, which is helpful for live UIs but unwanted for tests
against mocked endpoints where the values are stable.

This adds a numberSubstitution: 'regex' | 'static' option (default 'regex'
so existing baselines do not change) that can be set per matcher or
globally via the expect config.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Be able to switch off regex number substitution for aria snapshots

1 participant