test: bring the snapshotter test back (#9635)

This commit is contained in:
Andrey Lushnikov 2021-10-19 17:38:01 -07:00 committed by GitHub
parent f29ff86344
commit 500e43931e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -153,12 +153,12 @@ it.describe('snapshots', () => {
{ {
const handle = await page.$('text=Hello'); const handle = await page.$('text=Hello');
const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'snapshot', toImpl(handle)); const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'snapshot', toImpl(handle));
expect(distillSnapshot(snapshot)).toBe('<BUTTON>Hello</BUTTON><BUTTON>World</BUTTON>'); expect(distillSnapshot(snapshot, false /* distillTarget */)).toBe('<BUTTON __playwright_target__=\"snapshot\">Hello</BUTTON><BUTTON>World</BUTTON>');
} }
{ {
const handle = await page.$('text=World'); const handle = await page.$('text=World');
const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'snapshot2', toImpl(handle)); const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'snapshot2', toImpl(handle));
expect(distillSnapshot(snapshot)).toBe('<BUTTON>Hello</BUTTON><BUTTON>World</BUTTON>'); expect(distillSnapshot(snapshot, false /* distillTarget */)).toBe('<BUTTON __playwright_target__=\"snapshot\">Hello</BUTTON><BUTTON __playwright_target__=\"snapshot2\">World</BUTTON>');
} }
}); });
@ -182,8 +182,10 @@ it.describe('snapshots', () => {
}); });
}); });
function distillSnapshot(snapshot) { function distillSnapshot(snapshot, distillTarget = true) {
const { html } = snapshot.render(); let { html } = snapshot.render();
if (distillTarget)
html = html.replace(/\s__playwright_target__="[^"]+"/g, '');
return html return html
.replace(/<script>[.\s\S]+<\/script>/, '') .replace(/<script>[.\s\S]+<\/script>/, '')
.replace(/<style>.*__playwright_target__.*<\/style>/, '') .replace(/<style>.*__playwright_target__.*<\/style>/, '')
@ -192,7 +194,6 @@ function distillSnapshot(snapshot) {
.replace(/<HTML>/, '') .replace(/<HTML>/, '')
.replace(/<\/HTML>/, '') .replace(/<\/HTML>/, '')
.replace(/<HEAD>/, '') .replace(/<HEAD>/, '')
.replace(/\s__playwright_target__="[^"]+"/g, '')
.replace(/<\/HEAD>/, '') .replace(/<\/HEAD>/, '')
.replace(/<BODY>/, '') .replace(/<BODY>/, '')
.replace(/<\/BODY>/, '').trim(); .replace(/<\/BODY>/, '').trim();