From 928f15e912b21780638c61d4ff211622477eb9c7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Oct 2024 06:14:19 +0000 Subject: [PATCH 1/3] chore(deps): bump @xmldom/xmldom from 0.8.10 to 0.9.4 Bumps [@xmldom/xmldom](https://github.com/xmldom/xmldom) from 0.8.10 to 0.9.4. - [Release notes](https://github.com/xmldom/xmldom/releases) - [Changelog](https://github.com/xmldom/xmldom/blob/master/CHANGELOG.md) - [Commits](https://github.com/xmldom/xmldom/compare/0.8.10...0.9.4) --- updated-dependencies: - dependency-name: "@xmldom/xmldom" dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8f96476c5..dd883ab79 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "@cucumber/cucumber-expressions": "17", "@cucumber/gherkin": "29", "@cucumber/messages": "25.0.1", - "@xmldom/xmldom": "0.8.10", + "@xmldom/xmldom": "0.9.4", "acorn": "8.12.1", "arrify": "2.0.1", "axios": "1.7.7", @@ -131,7 +131,7 @@ "@wdio/sauce-service": "9.0.9", "@wdio/selenium-standalone-service": "8.3.2", "@wdio/utils": "9.1.2", - "@xmldom/xmldom": "0.8.10", + "@xmldom/xmldom": "0.9.4", "apollo-server-express": "2.25.3", "chai-as-promised": "7.1.2", "chai-subset": "1.6.0", From ed359d2c97227a87f92e9448a75d5574fd411658 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Tue, 22 Oct 2024 17:14:18 +0200 Subject: [PATCH 2/3] fix: UTs --- package.json | 1 + test/unit/html_test.js | 59 +++++++++++++++------------------------ test/unit/locator_test.js | 2 +- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index dd883ab79..cd262cf8c 100644 --- a/package.json +++ b/package.json @@ -135,6 +135,7 @@ "apollo-server-express": "2.25.3", "chai-as-promised": "7.1.2", "chai-subset": "1.6.0", + "cheerio": "^1.0.0", "contributor-faces": "1.1.0", "documentation": "12.3.0", "electron": "31.3.1", diff --git a/test/unit/html_test.js b/test/unit/html_test.js index 66049ecfd..c45250731 100644 --- a/test/unit/html_test.js +++ b/test/unit/html_test.js @@ -5,8 +5,7 @@ let expect import('chai').then((chai) => { expect = chai.expect }) -const xpath = require('xpath') -const Dom = require('@xmldom/xmldom').DOMParser +const cheerio = require('cheerio') const { scanForErrorMessages, removeNonInteractiveElements, minifyHtml, splitByChunks } = require('../../lib/html') const opts = { @@ -53,20 +52,23 @@ describe('HTML module', () => { describe('#removeNonInteractiveElements', () => { it('should cut out all non-interactive elements from GitHub HTML', async () => { - // Call the function with the loaded HTML html = fs.readFileSync(path.join(__dirname, '../data/github.html'), 'utf8') const result = removeNonInteractiveElements(html, opts) - let doc = new Dom().parseFromString(result) - const nodes = xpath.select('//input[@name="q"]', doc) + + let $ = cheerio.load(result) + + const nodes = $('input[name="q"]') expect(nodes).to.have.length(1) expect(result).not.to.include('Let’s build from here') + const minified = await minifyHtml(result) - doc = new Dom().parseFromString(minified) - const nodes2 = xpath.select('//input[@name="q"]', doc) + $ = cheerio.load(minified) + + const nodes2 = $('input[name="q"]') expect(nodes2).to.have.length(1) }) - it('should keep interactive html elements', () => { + it('should keep interactive HTML elements', () => { html = `
@@ -74,8 +76,7 @@ describe('HTML module', () => {

Privacy Preference Center

- +
` @@ -88,8 +89,7 @@ describe('HTML module', () => {
  • -
  • - - aaa - - -
  • + + aaa + + +
` const result = await minifyHtml(removeNonInteractiveElements(html, opts)) @@ -113,7 +113,6 @@ describe('HTML module', () => { }) it('should cut out all non-interactive elements from HTML', () => { - // Call the function with the loaded HTML html = fs.readFileSync(path.join(__dirname, '../data/checkout.html'), 'utf8') const result = removeNonInteractiveElements(html, opts) expect(result).to.include('Name on card') @@ -121,47 +120,35 @@ describe('HTML module', () => { }) it('should allow adding new elements', () => { - const html = '
Hey
' - - const result = removeNonInteractiveElements(html, { - textElements: ['h6'], - }) - + const html = '
Hey
'; + const result = removeNonInteractiveElements(html, { textElements: ['h6'] }) expect(result).to.include('
Hey
') }) it('should cut out all non-interactive elements from GitLab HTML', () => { - // Call the function with the loaded HTML html = fs.readFileSync(path.join(__dirname, '../data/gitlab.html'), 'utf8') - // console.log(html); const result = removeNonInteractiveElements(html, opts) - result.should.include('Get free trial') result.should.include('Sign in') result.should.include(' { - // Call the function with the loaded HTML html = fs.readFileSync(path.join(__dirname, '../data/testomat.html'), 'utf8') - // console.log(html); const result = removeNonInteractiveElements(html, opts) result.should.include(' describe('Locator', () => { beforeEach(() => { - doc = new DOMParser().parseFromString(xml, 'application/xhtml+xml') + doc = new DOMParser().parseFromString(xml, 'text/xml') }) describe('constructor', () => { From ffa3c8eadfc8743208c6e540b5cadb01d7608cd2 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Tue, 22 Oct 2024 17:14:57 +0200 Subject: [PATCH 3/3] fix: UTs --- test/unit/html_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/html_test.js b/test/unit/html_test.js index c45250731..e781ba9ab 100644 --- a/test/unit/html_test.js +++ b/test/unit/html_test.js @@ -120,7 +120,7 @@ describe('HTML module', () => { }) it('should allow adding new elements', () => { - const html = '
Hey
'; + const html = '
Hey
' const result = removeNonInteractiveElements(html, { textElements: ['h6'] }) expect(result).to.include('
Hey
') })