From e3a73e950649bf541e054462f588fc254e2eb99c Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Mon, 1 Feb 2021 21:09:03 +0000 Subject: [PATCH] Reliably generate mutations while the snapshot is iterating in order to test rare occurrences. Have added what I believe should be the correct parsing --- src/snapshot.ts | 7 +++ test/__snapshots__/integration.ts.snap | 46 ++++++++++++++++++++ test/html/mutating.html | 59 ++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 test/html/mutating.html diff --git a/src/snapshot.ts b/src/snapshot.ts index 3d04acc..0b9839b 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -525,6 +525,13 @@ export function serializeNodeWithId( serializedNode.type === NodeType.Element) && recordChild ) { + // MUTATION TEST + if ((n as HTMLElement).dataset && + (n as HTMLElement).dataset.mutatefn && + typeof (n as HTMLElement).dataset.mutatefn === 'string') { + eval((n as HTMLElement).dataset.mutatefn || ''); + } + // END MUTATION TEST (this block should be removed by compiler!) if ( slimDOMOptions.headWhitespace && _serializedNode.type === NodeType.Element && diff --git a/test/__snapshots__/integration.ts.snap b/test/__snapshots__/integration.ts.snap index d7d76c6..a519045 100644 --- a/test/__snapshots__/integration.ts.snap +++ b/test/__snapshots__/integration.ts.snap @@ -202,6 +202,52 @@ exports[`[html file]: invalid-tagname.html 1`] = ` " `; +exports[`[html file]: mutating.html 1`] = ` +" + + + + Document +
+ + + +
+
+ + + + +
+
+ + + +
+
+ + +
" +`; + +exports[`[html file]: mutating.html~ 1`] = ` +" + + + + Document +
+ + + +
+
+ + + +
" +`; + exports[`[html file]: picture.html 1`] = ` " diff --git a/test/html/mutating.html b/test/html/mutating.html new file mode 100644 index 0000000..35a27fe --- /dev/null +++ b/test/html/mutating.html @@ -0,0 +1,59 @@ + + + + + + + + Document + + + + + + +
+ + + +
+
+ + + + +
+
+ + + + +
+
+ + +
+ + +