check added nodes from removed nodes and dropped nodes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rrweb",
|
"name": "rrweb",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "record and replay the web",
|
"description": "record and replay the web",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "dist/module.js",
|
"module": "dist/module.js",
|
||||||
@@ -15,6 +15,11 @@
|
|||||||
"keywords": [
|
"keywords": [
|
||||||
"rrweb"
|
"rrweb"
|
||||||
],
|
],
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"index.d.ts",
|
||||||
|
"src/types.ts"
|
||||||
|
],
|
||||||
"author": "yanzhen@smartx.com",
|
"author": "yanzhen@smartx.com",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
@@ -26,10 +31,12 @@
|
|||||||
"@types/mocha": "^5.2.5",
|
"@types/mocha": "^5.2.5",
|
||||||
"@types/node": "^10.11.7",
|
"@types/node": "^10.11.7",
|
||||||
"@types/puppeteer": "^1.9.0",
|
"@types/puppeteer": "^1.9.0",
|
||||||
|
"@types/rewire": "^2.5.28",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"jest-snapshot": "^23.6.0",
|
"jest-snapshot": "^23.6.0",
|
||||||
"mocha": "^5.2.0",
|
"mocha": "^5.2.0",
|
||||||
"puppeteer": "^1.9.0",
|
"puppeteer": "^1.9.0",
|
||||||
|
"rewire": "^4.0.1",
|
||||||
"rollup": "^0.66.6",
|
"rollup": "^0.66.6",
|
||||||
"rollup-plugin-node-resolve": "^3.4.0",
|
"rollup-plugin-node-resolve": "^3.4.0",
|
||||||
"rollup-plugin-typescript": "^1.0.0",
|
"rollup-plugin-typescript": "^1.0.0",
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ function initMutationObserver(cb: mutationCallBack): MutationObserver {
|
|||||||
const observer = new MutationObserver(mutations => {
|
const observer = new MutationObserver(mutations => {
|
||||||
const texts: textCursor[] = [];
|
const texts: textCursor[] = [];
|
||||||
const attributes: attributeCursor[] = [];
|
const attributes: attributeCursor[] = [];
|
||||||
const removes: removedNodeMutation[] = [];
|
let removes: removedNodeMutation[] = [];
|
||||||
const adds: addedNodeMutation[] = [];
|
const adds: addedNodeMutation[] = [];
|
||||||
const dropped: Node[] = [];
|
const dropped: Node[] = [];
|
||||||
|
|
||||||
@@ -123,8 +123,21 @@ function initMutationObserver(cb: mutationCallBack): MutationObserver {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
removes = removes.map(remove => {
|
||||||
|
if (remove.parentNode) {
|
||||||
|
remove.parentId = mirror.getId(remove.parentNode as INode);
|
||||||
|
delete remove.parentNode;
|
||||||
|
}
|
||||||
|
return remove;
|
||||||
|
});
|
||||||
|
|
||||||
Array.from(addsSet).forEach(n => {
|
Array.from(addsSet).forEach(n => {
|
||||||
if (n.parentNode && dropped.indexOf(n.parentNode) < 0) {
|
const parentId = mirror.getId(n.parentNode as INode);
|
||||||
|
if (
|
||||||
|
parentId &&
|
||||||
|
!dropped.some(d => d === n.parentNode) &&
|
||||||
|
!removes.some(r => r.id === parentId)
|
||||||
|
) {
|
||||||
adds.push({
|
adds.push({
|
||||||
parentId: mirror.getId(n.parentNode as INode),
|
parentId: mirror.getId(n.parentNode as INode),
|
||||||
previousId: !n.previousSibling
|
previousId: !n.previousSibling
|
||||||
@@ -149,13 +162,7 @@ function initMutationObserver(cb: mutationCallBack): MutationObserver {
|
|||||||
id: mirror.getId(attribute.node as INode),
|
id: mirror.getId(attribute.node as INode),
|
||||||
attributes: attribute.attributes,
|
attributes: attribute.attributes,
|
||||||
})),
|
})),
|
||||||
removes: removes.map(remove => {
|
removes,
|
||||||
if (remove.parentNode) {
|
|
||||||
remove.parentId = mirror.getId(remove.parentNode as INode);
|
|
||||||
delete remove.parentNode;
|
|
||||||
}
|
|
||||||
return remove;
|
|
||||||
}),
|
|
||||||
adds,
|
adds,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
5
test/html/child-list.html
Normal file
5
test/html/child-list.html
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<body>
|
||||||
|
<ul>
|
||||||
|
<li></li>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
@@ -77,7 +77,32 @@ describe('record integration tests', () => {
|
|||||||
await page.select('select', '1');
|
await page.select('select', '1');
|
||||||
|
|
||||||
const snapshots = await page.evaluate('window.snapshots');
|
const snapshots = await page.evaluate('window.snapshots');
|
||||||
const result = matchSnapshot(JSON.stringify(snapshots), __filename, 'form');
|
const result = matchSnapshot(
|
||||||
|
JSON.stringify(snapshots, null, 2),
|
||||||
|
__filename,
|
||||||
|
'form',
|
||||||
|
);
|
||||||
|
assert(result.pass, result.pass ? '' : result.report());
|
||||||
|
}).timeout(5000);
|
||||||
|
|
||||||
|
it('can record childList mutations', async () => {
|
||||||
|
const page: puppeteer.Page = await this.browser.newPage();
|
||||||
|
await page.goto('about:blank');
|
||||||
|
await page.setContent(getHtml.call(this, 'child-list.html'));
|
||||||
|
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const li = document.createElement('li');
|
||||||
|
const ul = document.querySelector('ul') as HTMLUListElement;
|
||||||
|
ul.appendChild(li);
|
||||||
|
document.body.removeChild(ul);
|
||||||
|
});
|
||||||
|
|
||||||
|
const snapshots = await page.evaluate('window.snapshots');
|
||||||
|
const result = matchSnapshot(
|
||||||
|
JSON.stringify(snapshots, null, 2),
|
||||||
|
__filename,
|
||||||
|
'child-list',
|
||||||
|
);
|
||||||
assert(result.pass, result.pass ? '' : result.report());
|
assert(result.pass, result.pass ? '' : result.report());
|
||||||
}).timeout(5000);
|
}).timeout(5000);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user