summaryrefslogtreecommitdiff
path: root/test/dom-text-scanner.test.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-12-16 19:52:00 -0500
committerGitHub <noreply@github.com>2023-12-17 00:52:00 +0000
commit77d27113d347b4724302f1c72de1f238e04aeead (patch)
tree1d9d5a8f2533778e98d662b8757f52a9533ed5f0 /test/dom-text-scanner.test.js
parent64e4598b8cb59983fa21787550f68c562256fe67 (diff)
Fix DOM tests (#363)
* Only apply eslint rules to .test.js files * Fix tests * Use built-in environment * Fix tests * Optional file name * Remove environment
Diffstat (limited to 'test/dom-text-scanner.test.js')
-rw-r--r--test/dom-text-scanner.test.js49
1 files changed, 8 insertions, 41 deletions
diff --git a/test/dom-text-scanner.test.js b/test/dom-text-scanner.test.js
index f6a7410a..76e95a09 100644
--- a/test/dom-text-scanner.test.js
+++ b/test/dom-text-scanner.test.js
@@ -16,25 +16,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import fs from 'fs';
-import {JSDOM} from 'jsdom';
import {fileURLToPath} from 'node:url';
import path from 'path';
-import {expect, test} from 'vitest';
+import {describe, expect} from 'vitest';
import {DOMTextScanner} from '../ext/js/dom/dom-text-scanner.js';
+import {domTest} from './document-test.js';
const dirname = path.dirname(fileURLToPath(import.meta.url));
/**
- * @param {string} fileName
- * @returns {JSDOM}
- */
-function createJSDOM(fileName) {
- const domSource = fs.readFileSync(fileName, {encoding: 'utf8'});
- return new JSDOM(domSource);
-}
-
-/**
* @param {Element} element
* @param {string} selector
* @returns {?Node}
@@ -111,13 +101,12 @@ function createAbsoluteGetComputedStyle(window) {
}
-/**
- * @param {JSDOM} dom
- */
-async function testDomTextScanner(dom) {
- const document = dom.window.document;
+describe('DOMTextScanner', () => {
+ const testDoc = domTest(path.join(dirname, 'data/html/test-dom-text-scanner.html'));
+ testDoc('Seek tests', ({window}) => {
+ const {document} = window;
+ window.getComputedStyle = createAbsoluteGetComputedStyle(window);
- test('DomTextScanner', () => {
for (const testElement of /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('y-test'))) {
let testData = JSON.parse(/** @type {string} */ (testElement.dataset.testData));
if (!Array.isArray(testData)) {
@@ -185,26 +174,4 @@ async function testDomTextScanner(dom) {
}
}
});
-}
-
-
-/** */
-async function testDocument1() {
- const dom = createJSDOM(path.join(dirname, 'data', 'html', 'test-dom-text-scanner.html'));
- const window = dom.window;
- try {
- window.getComputedStyle = createAbsoluteGetComputedStyle(window);
-
- await testDomTextScanner(dom);
- } finally {
- window.close();
- }
-}
-
-
-/** */
-async function main() {
- await testDocument1();
-}
-
-await main();
+});