From ee2af3c975a56e66d30e5ca838954f0075add7f9 Mon Sep 17 00:00:00 2001 From: 7h3Rabbit <62792609+7h3Rabbit@users.noreply.github.com> Date: Wed, 9 Apr 2025 16:10:00 +0200 Subject: [PATCH] Added regression test --- lib/harAnalyzer.js | 18 ++---------------- lib/index.js | 7 ++++--- package.json | 7 ++++++- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/harAnalyzer.js b/lib/harAnalyzer.js index 706436e..33bd048 100644 --- a/lib/harAnalyzer.js +++ b/lib/harAnalyzer.js @@ -22,7 +22,7 @@ export class HarAnalyzer { const libFolder = fileURLToPath(new URL('..', import.meta.url)); this.pluginFolder = path.resolve(libFolder, '..'); } - transform2SimplifiedData(harData, url, group) { + transform2SimplifiedData(harData, url) { const data = { 'url': url, 'security-rules': this.configSecurity, @@ -82,20 +82,6 @@ export class HarAnalyzer { data['script-elements'].push(styleElementObj); } }); - - // Extract style="" attributes from HTML content - // const elementsWithStyleAttr = dom.window.document.querySelectorAll('[style]'); - // elementsWithStyleAttr.forEach((element, index) => { - // const styleAttrContent = element.getAttribute('style'); - // const styleAttrObj = { - // 'url': htmlObj.url, - // // Wrap the style attribute content in a dummy #id rule - // 'content': `#dummy-style-attribute-id { ${styleAttrContent} }`, - // 'index': htmlObj.index - // }; - // data['all-styles'].push(styleAttrObj); - // data['style-attributes'].push(styleAttrObj); - // }); } return data; @@ -175,7 +161,7 @@ export class HarAnalyzer { this.groups[group] = {}; } - const analyzedData = this.transform2SimplifiedData(harData, url, group); + const analyzedData = this.transform2SimplifiedData(harData, url); if (!('analyzedData' in this.groups[group])) { this.groups[group]['analyzedData'] = [] } diff --git a/lib/index.js b/lib/index.js index b5c3bf3..5aa0e52 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,6 +20,7 @@ export default class JavascriptPlugin extends SitespeedioPlugin { this.harAnalyzer = new HarAnalyzer(); const libFolder = fileURLToPath(new URL('..', import.meta.url)); this.pluginFolder = path.resolve(libFolder); + this.options = options; this.pug = await fsp.readFile( path.resolve(this.pluginFolder, 'pug', 'index.pug'), @@ -83,7 +84,7 @@ export default class JavascriptPlugin extends SitespeedioPlugin { } } } - close(options, errors) { - // Cleanup if necessary - } + // close(options, errors) { + // // Cleanup if necessary + // } } \ No newline at end of file diff --git a/package.json b/package.json index 5cdd27e..0ca25a9 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,10 @@ "eslint-config-prettier": "10.1.1", "eslint-plugin-prettier": "5.2.5", "eslint-plugin-unicorn": "58.0.0", - "prettier": "3.5.3" + "prettier": "3.5.3", + "serve": "14.2.4", + "serve-handler": "6.1.6", + "typescript": "5.7.2" }, "dependencies": { "jsdom": "26.0.0", @@ -55,6 +58,8 @@ }, "scripts": { "test": "ava", + "start-server": "serve test/data/", + "stop-server": "sudo pkill serve", "lint": "eslint .", "lint:fix": "eslint . --fix", "eslint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check"