From fb0408961c5ac49bdae76225c66c981bcf4d3f2b Mon Sep 17 00:00:00 2001 From: Daniel Puckowski Date: Sun, 11 Feb 2024 07:04:09 -0500 Subject: [PATCH] Add automated tests bringing the total to 206 * Add automated tests bringing the total to 206. * Verify there are no duplicate unbound Sling lifecycle functions in the DOM. --- src/globalTests.js | 182 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) diff --git a/src/globalTests.js b/src/globalTests.js index 671116d..dc7065b 100644 --- a/src/globalTests.js +++ b/src/globalTests.js @@ -9399,6 +9399,7 @@ export class GlobalTestRunner { }; const fnSet = new Set(); + const nodeSet = new Set(); let hasDuplicates = false; let count = 0; @@ -9410,6 +9411,13 @@ export class GlobalTestRunner { while (stack.length > 0) { const node = stack.pop(); + + if (node.id !== undefined && node.id !== null && nodeSet.has(node.id)) { + continue; + } else { + nodeSet.add(node.id); + } + count++; const fn = node.slOnDestroyFn; @@ -9440,6 +9448,180 @@ export class GlobalTestRunner { window.globalTestCount++; } + testRunLastUnboundDestroyFunctionReferenceNoDuplicates() { + const result = { + test: 'test there are no duplicate unbound destroy function references', + success: false, + message: '' + }; + + const fnSet = new Set(); + const nodeSet = new Set(); + let hasDuplicates = false; + let count = 0; + + const stack = []; + + for (const bodyChild of document.body.children) { + stack.push(bodyChild); + } + + while (stack.length > 0) { + const node = stack.pop(); + + if (node.id !== undefined && node.id !== null && nodeSet.has(node.id)) { + continue; + } else { + nodeSet.add(node.id); + } + + count++; + const fn = node.slUnboundOnDestroy; + + if (fn !== undefined && fn !== null) { + console.log(fn); + console.log(node); + + if (fnSet.has(fn)) { + hasDuplicates = true; + + break; + } else { + fnSet.add(fn); + } + } + + if (hasDuplicates) { + break; + } + + for (const child of node.children) { + stack.push(child); + } + } + + console.log('Evaluated ' + count + ' nodes in body for duplicate unbound destroy functions'); + + result.success = !hasDuplicates; + + window.globalTestResults.push(result); + window.globalTestCount++; + } + + testRunLastAfterInitFunctionReferenceNoDuplicates() { + const result = { + test: 'test there are no duplicate unbound after init function references', + success: false, + message: '' + }; + + const fnSet = new Set(); + const nodeSet = new Set(); + let hasDuplicates = false; + let count = 0; + + const stack = []; + + for (const bodyChild of document.body.children) { + stack.push(bodyChild); + } + + while (stack.length > 0) { + const node = stack.pop(); + + if (node.id !== undefined && node.id !== null && nodeSet.has(node.id)) { + continue; + } else { + nodeSet.add(node.id); + } + + count++; + const fn = node.slUnboundAfterInit; + + if (fn !== undefined && fn !== null) { + if (fnSet.has(fn)) { + hasDuplicates = true; + + break; + } else { + fnSet.add(fn); + } + } + + if (hasDuplicates) { + break; + } + + for (const child of node.children) { + stack.push(child); + } + } + + console.log('Evaluated ' + count + ' nodes in body for duplicate unbound after init functions'); + + result.success = !hasDuplicates; + + window.globalTestResults.push(result); + window.globalTestCount++; + } + + testRunLastOnInitFunctionReferenceNoDuplicates() { + const result = { + test: 'test there are no duplicate unbound on init function references', + success: false, + message: '' + }; + + const fnSet = new Set(); + const nodeSet = new Set(); + let hasDuplicates = false; + let count = 0; + + const stack = []; + + for (const bodyChild of document.body.children) { + stack.push(bodyChild); + } + + while (stack.length > 0) { + const node = stack.pop(); + + if (node.id !== undefined && node.id !== null && nodeSet.has(node.id)) { + continue; + } else { + nodeSet.add(node.id); + } + + count++; + const fn = node.slUnboundOnInit; + + if (fn !== undefined && fn !== null) { + if (fnSet.has(fn)) { + hasDuplicates = true; + + break; + } else { + fnSet.add(fn); + } + } + + if (hasDuplicates) { + break; + } + + for (const child of node.children) { + stack.push(child); + } + } + + console.log('Evaluated ' + count + ' nodes in body for duplicate unbound on init functions'); + + result.success = !hasDuplicates; + + window.globalTestResults.push(result); + window.globalTestCount++; + } + testRunLastFunctionMapNoDuplicates() { const result = { test: 'test destroy function map contains no duplicates',