diff --git a/package.json b/package.json index 8f96476c5..cd262cf8c 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,10 +131,11 @@ "@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", + "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..e781ba9ab 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 = `