From 6d5d5000bfe813a7af645f607950f60f3cf56627 Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Sun, 23 Mar 2025 22:33:45 +0000 Subject: [PATCH] Clean up and separate unit and e2e tests, remove QUnit, update documentation (#1324) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Try uncluttering code * Fully remove QUnit tests * Update test documentation * Remove more mentions of Testafé * Don't autorun Unit Tests --- .mocharc.json | 1 - TESTS.md | 21 +--- package-lock.json | 103 ------------------ package.json | 1 - tests/e2e/spec/legacy-ray_charles.e2e.spec.js | 12 +- tests/unit/index.html | 43 -------- www/index.html | 2 +- 7 files changed, 8 insertions(+), 175 deletions(-) delete mode 100644 tests/unit/index.html diff --git a/.mocharc.json b/.mocharc.json index 1636e5c6..d2f0ffe4 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,6 +1,5 @@ { "extension": ["js"], - "spec": "tests/unit/**/*.test.js", "timeout": 5000, "recursive": true, "exit": true, diff --git a/TESTS.md b/TESTS.md index f1b88951..46f3bc17 100644 --- a/TESTS.md +++ b/TESTS.md @@ -9,25 +9,10 @@ functions that the rest of the app relies on. End-to-end tests are designed to t ## Unit tests -Unit tests are implemented, for historic reaons, with QUnit. When run in an automated way, these are currently run by using the browser testing framework TestCafé. +Unit tests are implemented using Mocha. -You can manually run and debug Unit tests simply by opening `tests/index.html` in Firefox, Edge, or Chromium/Chrome through a (local) web server, such as Vite or http-server (see -[CONTRIBUTING](./CONTRIBUTING.md)). Use DevTools (F12) to debug and find out what is failing. Note that this only tests the unbundled -(source) code, and so it only works in browsers that support ES6 modules. You *cannot* use these tests in IE11 or older Firefox/Chromium. - -You can run the Unit tests with npm on all your installed browsers with `npm test` in your terminal. Before running the tests, if you didn't already, you will need to fetch -development dependencies (see "[Build system and setup](./CONTRIBUTING.md#build-system-and-setup)"). If testing this way, -make sure that `http-server` is not already running, because another copy is launched for these tests, and the ports may conflict. If running tests in parallel like this produces -unexpected results (some tests might be too slow and assert before they have completed correctly), then you can run individual tests in headless mode with -`npm run test-unit-firefox`, `npm run test-unit-edge`, etc. (see `package.json` for full list of scripts). Note that browsers need to be available in standard locations for this -to work: they won't be fetched or installed by the script. - -We currently use [TestCafé](https://testcafe.io/) to run the Unit tests in headless browsers in GitHub actions. If you want to run this locally, you can find out which browsers it -knows about by running `npx testcafe --list-browsers` (it may take some time to discover local browsers). - -When you run `npm test`, it will run the tests visually, not headless. The individual browser tests (e.g. `npm run test-unit-chrome`) are run headless. If you want to run these -individual tests visually, not headless, it's easiest simply to open `tests/index.html` in the respective browser, and this allows you to debug. If you really want to do it from the -commandline, then you'll need, e.g., `npx testcafe chrome ./tests/initTestCafe.js --app "http-server --silent -p 8080 ."` (adapt the browser as necessary). +You can run the Unit tests in a NodeJS environment with `npm test` in your terminal. Before running the tests, if you didn't already, +you will need to fetch development dependencies (see "[Build system and setup](./CONTRIBUTING.md#build-system-and-setup)"). ## End-to-end tests diff --git a/package-lock.json b/package-lock.json index c58a7fcf..214820df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,7 +38,6 @@ "jsdom": "^25.0.1", "mocha": "^10.8.2", "nyc": "^17.1.0", - "qunit": "^2.19.4", "rollup": "^4.5.0", "rollup-plugin-copy": "^3.4.0", "selenium-webdriver": "^4.11.1", @@ -3885,15 +3884,6 @@ "node": ">= 0.8" } }, - "node_modules/commander": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", - "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==", - "dev": true, - "engines": { - "node": ">= 10" - } - }, "node_modules/commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -5242,12 +5232,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/globalyzer": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/globalyzer/-/globalyzer-0.1.0.tgz", - "integrity": "sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==", - "dev": true - }, "node_modules/globby": { "version": "13.2.0", "resolved": "https://registry.npmjs.org/globby/-/globby-13.2.0.tgz", @@ -5279,12 +5263,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/globrex": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz", - "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==", - "dev": true - }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -6921,15 +6899,6 @@ "dev": true, "license": "MIT" }, - "node_modules/node-watch": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/node-watch/-/node-watch-0.7.3.tgz", - "integrity": "sha512-3l4E8uMPY1HdMMryPRUAl+oIHtXtyiTlIiESNSVSNxcPfzAFzeTbXFQkZfAwBbo0B1qMSG8nUABx+Gd+YrbKrQ==", - "dev": true, - "engines": { - "node": ">=6" - } - }, "node_modules/normalize-package-data": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz", @@ -7844,23 +7813,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/qunit": { - "version": "2.19.4", - "resolved": "https://registry.npmjs.org/qunit/-/qunit-2.19.4.tgz", - "integrity": "sha512-aqUzzUeCqlleWYKlpgfdHHw9C6KxkB9H3wNfiBg5yHqQMzy0xw/pbCRHYFkjl8MsP/t8qkTQE+JTYL71azgiew==", - "dev": true, - "dependencies": { - "commander": "7.2.0", - "node-watch": "0.7.3", - "tiny-glob": "0.2.9" - }, - "bin": { - "qunit": "bin/qunit.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -8888,16 +8840,6 @@ "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==", "dev": true }, - "node_modules/tiny-glob": { - "version": "0.2.9", - "resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz", - "integrity": "sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==", - "dev": true, - "dependencies": { - "globalyzer": "0.1.0", - "globrex": "^0.1.2" - } - }, "node_modules/tldts": { "version": "6.1.71", "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.71.tgz", @@ -12039,12 +11981,6 @@ "delayed-stream": "~1.0.0" } }, - "commander": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", - "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==", - "dev": true - }, "commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -13021,12 +12957,6 @@ "define-properties": "^1.1.3" } }, - "globalyzer": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/globalyzer/-/globalyzer-0.1.0.tgz", - "integrity": "sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==", - "dev": true - }, "globby": { "version": "13.2.0", "resolved": "https://registry.npmjs.org/globby/-/globby-13.2.0.tgz", @@ -13048,12 +12978,6 @@ } } }, - "globrex": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz", - "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==", - "dev": true - }, "gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -14263,12 +14187,6 @@ "integrity": "sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==", "dev": true }, - "node-watch": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/node-watch/-/node-watch-0.7.3.tgz", - "integrity": "sha512-3l4E8uMPY1HdMMryPRUAl+oIHtXtyiTlIiESNSVSNxcPfzAFzeTbXFQkZfAwBbo0B1qMSG8nUABx+Gd+YrbKrQ==", - "dev": true - }, "normalize-package-data": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz", @@ -14925,17 +14843,6 @@ "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==", "dev": true }, - "qunit": { - "version": "2.19.4", - "resolved": "https://registry.npmjs.org/qunit/-/qunit-2.19.4.tgz", - "integrity": "sha512-aqUzzUeCqlleWYKlpgfdHHw9C6KxkB9H3wNfiBg5yHqQMzy0xw/pbCRHYFkjl8MsP/t8qkTQE+JTYL71azgiew==", - "dev": true, - "requires": { - "commander": "7.2.0", - "node-watch": "0.7.3", - "tiny-glob": "0.2.9" - } - }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -15724,16 +15631,6 @@ "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==", "dev": true }, - "tiny-glob": { - "version": "0.2.9", - "resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz", - "integrity": "sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==", - "dev": true, - "requires": { - "globalyzer": "0.1.0", - "globrex": "^0.1.2" - } - }, "tldts": { "version": "6.1.71", "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.71.tgz", diff --git a/package.json b/package.json index ad9e62a5..a1089334 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,6 @@ "jsdom": "^25.0.1", "mocha": "^10.8.2", "nyc": "^17.1.0", - "qunit": "^2.19.4", "rollup": "^4.5.0", "rollup-plugin-copy": "^3.4.0", "selenium-webdriver": "^4.11.1", diff --git a/tests/e2e/spec/legacy-ray_charles.e2e.spec.js b/tests/e2e/spec/legacy-ray_charles.e2e.spec.js index 974ba81b..c7d20743 100644 --- a/tests/e2e/spec/legacy-ray_charles.e2e.spec.js +++ b/tests/e2e/spec/legacy-ray_charles.e2e.spec.js @@ -256,13 +256,9 @@ function runTests (driver, modes, keepDriver) { // const articleLink = await driver.findElement(By.linkText('This Little Girl of Mine')); assert.equal('This Little Girl of Mine', text); // Scroll the element into view and navigate to it - await driver.wait(async function () { - const elementIsVisible = await driver.executeScript('var el=arguments[0]; el.scrollIntoView(true); setTimeout(function () {el.click();}, 50); return el.offsetParent;', articleLink); - // console.log('Element is visible: ' + elementIsVisible); - return elementIsVisible; - }, 10000); - // Pause for 1 second to allow article to load - await driver.sleep(1300); + await driver.executeScript('var el=arguments[0]; el.scrollIntoView(true); setTimeout(function () {el.click();}, 50); return el.offsetParent;', articleLink); + // Pause for 2 seconds to allow article to load + await driver.sleep(2000); let elementText = ''; try { // Find the mwYw element in JavaScript and get its content @@ -308,7 +304,7 @@ function runTests (driver, modes, keepDriver) { console.log('\x1b[33m%s\x1b[0m', ' - Following test skipped:'); this.skip(); } - await driver.switchTo().defaultContent(); + // await driver.switchTo().defaultContent(); const prefix = await driver.findElement(By.id('prefix')); // Search by setting the value of the prefix element using JavaScript await driver.executeScript('arguments[0].value = "Ray"; document.getElementById("searchArticles").click();', prefix); diff --git a/tests/unit/index.html b/tests/unit/index.html deleted file mode 100644 index 1bd7e3a9..00000000 --- a/tests/unit/index.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - Kiwix-js Unit tests - - - - - - - - - - - NOTE: Firefox and Chrome do not allow access to some local filesystem files used in testing. So, if you're opening this through a file:// URL, you should instead go through a web server : either through a local one (http://localhost/...) or through a remote one (but you need SSL : https://webserver/...).
- Another option is to force your browser to accept that (but you'll open a security breach) : on Chrome, you can start it with --allow-file-access-from-files command-line argument; on Firefox, you can set privacy.file_unique_origin to false in about:config -
-
- - diff --git a/www/index.html b/www/index.html index 9bf43f63..70515045 100644 --- a/www/index.html +++ b/www/index.html @@ -421,7 +421,7 @@
  • jQuery 3.7, released under the MIT Licence
  • Bootstrap 4, released under an MIT Licence
  • Fontawesome Free, icons licensed under CC BY 4.0 Licence, code licensed under a MIT Licence
  • -
  • QUnit 2, released under the MIT Licence
  • +
  • Mocha, released under a Creative Commons Licence
  • Kiwix logo from kiwix.org, released under the Creative Commons Attribution Share Alike Licence
  • OpenZIM specifications from www.openzim.org, released under the Creative Commons Attribution Share Alike Licence
  • Emscripten to generate XZ and ZSTD decompressors in javascript : https://github.com/kripken/emscripten, released under the MIT Licence