chore: more aria snapshot fixes (#33534)
This commit is contained in:
parent
114884335d
commit
33f9c8279c
|
|
@ -300,7 +300,8 @@ export function renderAriaTree(ariaNode: AriaNode, options?: { mode?: 'raw' | 'r
|
|||
}
|
||||
|
||||
let key = ariaNode.role;
|
||||
if (ariaNode.name) {
|
||||
// Yaml has a limit of 1024 characters per key, and we leave some space for role and attributes.
|
||||
if (ariaNode.name && ariaNode.name.length <= 900) {
|
||||
const name = renderString(ariaNode.name);
|
||||
if (name) {
|
||||
const stringifiedName = name.startsWith('/') && name.endsWith('/') ? name : JSON.stringify(name);
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ export async function toMatchAriaSnapshot(
|
|||
if (notFound) {
|
||||
return {
|
||||
pass: this.isNot,
|
||||
message: () => messagePrefix + `Expected: ${this.utils.printExpected(expected)}\nReceived: ${EXPECTED_COLOR('not found')}` + callLogText(log),
|
||||
message: () => messagePrefix + `Expected: ${this.utils.printExpected(expected)}\nReceived: ${EXPECTED_COLOR('<element not found>')}` + callLogText(log),
|
||||
name: 'toMatchAriaSnapshot',
|
||||
expected,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -479,16 +479,16 @@ it('should escape yaml text in text nodes', async ({ page }) => {
|
|||
`);
|
||||
});
|
||||
|
||||
it.fixme('should handle long strings', async ({ page }) => {
|
||||
it('should handle long strings', async ({ page }) => {
|
||||
const s = 'a'.repeat(10000);
|
||||
await page.setContent(`
|
||||
<a href='about:blank'>
|
||||
<div role='region'>${'a'.repeat(100000)}</div>
|
||||
<div role='region'>${s}</div>
|
||||
</a>
|
||||
`);
|
||||
|
||||
const trimmed = 'a'.repeat(1000);
|
||||
await checkAndMatchSnapshot(page.locator('body'), `
|
||||
- link "${trimmed}":
|
||||
- region: "${trimmed}"
|
||||
- link:
|
||||
- region: ${s}
|
||||
`);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -640,17 +640,6 @@ test('call log should contain actual snapshot', async ({ page }) => {
|
|||
expect(stripAnsi(error.message)).toContain(`- unexpected value "- heading "todos" [level=1]"`);
|
||||
});
|
||||
|
||||
test.fixme('should normalize whitespace when matching accessible name', async ({ page }) => {
|
||||
await page.setContent(`
|
||||
<button>hello world</button>
|
||||
`);
|
||||
await expect(page.locator('body')).toMatchAriaSnapshot(`
|
||||
- |
|
||||
button "hello
|
||||
world"
|
||||
`);
|
||||
});
|
||||
|
||||
test('should parse attributes', async ({ page }) => {
|
||||
{
|
||||
await page.setContent(`
|
||||
|
|
|
|||
|
|
@ -377,3 +377,22 @@ test('should generate baseline for input values', async ({ runInlineTest }, test
|
|||
const result2 = await runInlineTest({});
|
||||
expect(result2.exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test('should not update snapshots when locator did not match', async ({ runInlineTest }, testInfo) => {
|
||||
const result = await runInlineTest({
|
||||
'a.spec.ts': `
|
||||
import { test, expect } from '@playwright/test';
|
||||
test('test', async ({ page }) => {
|
||||
await page.setContent('<h1>hello</h1>');
|
||||
await expect(page.locator('div')).toMatchAriaSnapshot('- heading', { timeout: 3000 });
|
||||
});
|
||||
`,
|
||||
}, { 'update-snapshots': true });
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
const patchPath = testInfo.outputPath('test-results/rebaselines.patch');
|
||||
expect(fs.existsSync(patchPath)).toBe(false);
|
||||
expect(result.output).not.toContain('New baselines created');
|
||||
expect(result.output).toContain('Expected: "- heading"');
|
||||
expect(result.output).toContain('Received: <element not found>');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue