From d6b57fcfa09d9cba4e4aa203c42ae8cddc4eb055 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 | 48 ++++++++++++++++++++- test/html/mutating.html | 59 ++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 test/html/mutating.html diff --git a/src/snapshot.ts b/src/snapshot.ts index c6249eb..737ddbe 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -724,6 +724,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 afa7b2a..c557c3c 100644 --- a/test/__snapshots__/integration.ts.snap +++ b/test/__snapshots__/integration.ts.snap @@ -130,7 +130,7 @@ exports[`[html file]: form-fields.html 1`] = ` - + " `; @@ -217,6 +217,52 @@ exports[`[html file]: mask-text.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 + + + + + + +
+ + + +
+
+ + + + +
+
+ + + + +
+
+ + +
+ + +