Skip to content

Commit

Permalink
Prefer waitForRAF
Browse files Browse the repository at this point in the history
  • Loading branch information
eoghanmurray committed Jul 8, 2024
1 parent 2287249 commit 4b1623c
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions packages/rrweb/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,24 @@ describe('record integration tests', function (this: ISuite) {
ta2.id = 'ta2';
document.body.append(ta2);
});
await page.waitForTimeout(5);
await waitForRAF(page);
await page.evaluate(() => {
const t = document.querySelector('textarea') as HTMLTextAreaElement;
t.innerText = 'ok'; // this mutation should be recorded

const ta2t = document.createTextNode('added');
document.getElementById('ta2').append(ta2t);
});
await page.waitForTimeout(5);
await waitForRAF(page);
await page.evaluate(() => {
const t = document.querySelector('textarea') as HTMLTextAreaElement;
(t.childNodes[0] as Text).appendData('3'); // this mutation is also valid

document.getElementById('ta2').remove(); // done with this
});
await page.waitForTimeout(5);
await waitForRAF(page);
await page.type('textarea', '1'); // types (inserts) at index 0, in front of existing text
await page.waitForTimeout(5);
await waitForRAF(page);
await page.evaluate(() => {
const t = document.querySelector('textarea') as HTMLTextAreaElement;
// user has typed so childNode content should now be ignored
Expand All @@ -145,7 +145,7 @@ describe('record integration tests', function (this: ISuite) {
// there is nothing explicit in rrweb which enforces this, but this test may protect against
// a future change where a mutation on a textarea incorrectly updates the .value
});
await page.waitForTimeout(5);
await waitForRAF(page);
await page.type('textarea', '2'); // cursor is at index 1

const snapshots = (await page.evaluate(
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('record integration tests', function (this: ISuite) {
);
}
});
await page.waitForTimeout(5);
await waitForRAF(page);
await page.evaluate(() => {
let styleEl = document.querySelector('style');
if (styleEl) {
Expand All @@ -218,7 +218,7 @@ describe('record integration tests', function (this: ISuite) {
});
}
});
await page.waitForTimeout(5);
await waitForRAF(page);
await page.evaluate(() => {
let styleEl = document.querySelector('style');
if (styleEl) {
Expand All @@ -245,16 +245,13 @@ describe('record integration tests', function (this: ISuite) {
document.body.append(st);
});

await page.waitForTimeout(5);
await waitForRAF(page);
await page.evaluate(() => {
let styleEl = document.getElementById('goldilocks');
if (styleEl) {
styleEl.childNodes.forEach((cn) => {
if (cn.textContent) {
cn.textContent = cn.textContent.replace(
'brown',
'gold',
);
cn.textContent = cn.textContent.replace('brown', 'gold');
}
});
}
Expand Down

0 comments on commit 4b1623c

Please sign in to comment.