mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-08-03 11:16:38 -04:00
Clean up and separate unit and e2e tests, remove QUnit, update documentation (#1324)
* Try uncluttering code * Fully remove QUnit tests * Update test documentation * Remove more mentions of Testafé * Don't autorun Unit Tests
This commit is contained in:
parent
f37ed3c1c1
commit
6d5d5000bf
@ -1,6 +1,5 @@
|
||||
{
|
||||
"extension": ["js"],
|
||||
"spec": "tests/unit/**/*.test.js",
|
||||
"timeout": 5000,
|
||||
"recursive": true,
|
||||
"exit": true,
|
||||
|
21
TESTS.md
21
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
|
||||
|
||||
|
103
package-lock.json
generated
103
package-lock.json
generated
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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);
|
||||
|
@ -1,43 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta charset="utf-8">
|
||||
<base href="../../">
|
||||
<title>Kiwix-js Unit tests</title>
|
||||
|
||||
<!--
|
||||
Copyright 2013-2016 Mossroy, Peter-x and contributors
|
||||
Licence GPL v3:
|
||||
|
||||
This file is part of Kiwix.
|
||||
|
||||
Kiwix is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public Licence as published by
|
||||
the Free Software Foundation, either version 3 of the Licence, or
|
||||
(at your option) any later version.
|
||||
|
||||
Kiwix is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public Licence for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public Licence
|
||||
along with Kiwix (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
|
||||
-->
|
||||
|
||||
<link rel="stylesheet" href="node_modules/qunit/qunit/qunit.css" />
|
||||
<script src="node_modules/qunit/qunit/qunit.js"></script>
|
||||
<script>
|
||||
QUnit.config.autostart = false;
|
||||
</script>
|
||||
<script type="text/javascript" src="./tests/unit/js/init.js"></script>
|
||||
<script type="module" src="./tests/unit/spec/tests.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<b>NOTE:</b> 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/...).<br/>
|
||||
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
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
</body>
|
||||
</html>
|
@ -421,7 +421,7 @@
|
||||
<li><a href="https://jquery.com/" target="_blank">jQuery</a> 3.7, released under the <a href="https://jquery.org/license" target="_blank">MIT Licence</a></li>
|
||||
<li><a href="https://getbootstrap.com/" target="_blank">Bootstrap 4</a>, released under an <a href="https://github.com/twbs/bootstrap/blob/master/LICENSE" target="_blank">MIT Licence</a></li>
|
||||
<li><a href="https://github.com/FortAwesome/Font-Awesome" target="_blank">Fontawesome Free</a>, icons licensed under <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank">CC BY 4.0 Licence</a>, code licensed under a <a href="https://opensource.org/licenses/MIT" target="_blank">MIT Licence</a></li>
|
||||
<li><a href="https://qunitjs.com/" target="_blank">QUnit</a> 2, released under the <a href="https://jquery.org/license" target="_blank">MIT Licence</a></li>
|
||||
<li><a href="https://mochajs.org/" target="_blank">Mocha</a>, released under a <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank">Creative Commons Licence</a></li>
|
||||
<li>Kiwix logo from <a href="https://www.kiwix.org/" target="_blank">kiwix.org</a>, released under the <a href="https://creativecommons.org/licenses/by-sa/3.0/" target="_blank">Creative Commons Attribution Share Alike Licence</a></li>
|
||||
<li>OpenZIM specifications from <a href="https://wiki.openzim.org/wiki/OpenZIM" target="_blank">www.openzim.org</a>, released under the <a href="https://creativecommons.org/licenses/by-sa/3.0/" target="_blank">Creative Commons Attribution Share Alike Licence</a></li>
|
||||
<li>Emscripten to generate XZ and ZSTD decompressors in javascript : <a href="https://github.com/kripken/emscripten" target="_blank">https://github.com/kripken/emscripten</a>, released under the <a href="https://github.com/kripken/emscripten" target="_blank">MIT Licence</a></li>
|
||||
|
Loading…
x
Reference in New Issue
Block a user