diff options
author | Stefan Giehl <stefan@matomo.org> | 2021-04-12 02:34:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-12 02:34:31 +0300 |
commit | 4850faed9e3d657321445c15ad6ae35292a02d0e (patch) | |
tree | 4ffc75b2963a9f23133de4654f7a40c2c41a27e3 /tests/javascript | |
parent | 3b1e602cfc9f814dfccca27a4eac2b3a68a5b044 (diff) |
Run JavaScript tests also with node/puppeteer (#17432)
* Run Javascript tests on node / puppeteer
* fix js tests for modern browsers supporting sendBeacon
* run js tests on phantomjs & on node/puppeteer
* updates travis submodule
Diffstat (limited to 'tests/javascript')
-rw-r--r-- | tests/javascript/index.php | 11 | ||||
-rw-r--r-- | tests/javascript/testrunnerNode.js | 67 | ||||
-rw-r--r-- | tests/javascript/testrunnerPhantom.js (renamed from tests/javascript/testrunner.js) | 0 |
3 files changed, 74 insertions, 4 deletions
diff --git a/tests/javascript/index.php b/tests/javascript/index.php index aae7e4d09d..36f3ed44af 100644 --- a/tests/javascript/index.php +++ b/tests/javascript/index.php @@ -3276,16 +3276,18 @@ function PiwikTest() { tracker.setSiteId(1); tracker.setCustomData({ "token": '---' }); tracker.setRequestMethod('POST'); + ok(tracker.isUsingAlwaysUseSendBeacon()); + tracker.setRequestMethod('GeT'); + ok(!tracker.isUsingAlwaysUseSendBeacon()); + tracker.setRequestMethod('POST'); + tracker.disableAlwaysUseSendBeacon(); // disable send beacon to force sending a xhr var callbackCalled = false; tracker.trackPageView('withCredentialsTest', null, function (event) { callbackCalled = true; ok(event.success, 'succeeded'); ok(event.xhr && event.xhr.withCredentials, 'withCredentials is true'); }); - ok(tracker.isUsingAlwaysUseSendBeacon()); - tracker.setRequestMethod('GeT'); - ok(!tracker.isUsingAlwaysUseSendBeacon()); stop(); setTimeout(function() { @@ -5116,13 +5118,14 @@ if ($mysql) { var msSinceStarted = (stopTime.getTime() - startTime.getTime()); ok( msSinceStarted < 510, 'beforeUnloadHandler(): ' + msSinceStarted + ' was greater than 510 ' ); + tracker.disableAlwaysUseSendBeacon(); tracker.setLinkTrackingTimer(2000); startTime = new Date(); tracker.trackPageView(); tracker.hook.test._beforeUnloadHandler(); stopTime = new Date(); var diffTime = (stopTime.getTime() - startTime.getTime()); - ok( diffTime >= 2000, 'setLinkTrackingTimer()' ); + ok( diffTime >= 2000, 'setLinkTrackingTimer(): ' + diffTime); }); <?php diff --git a/tests/javascript/testrunnerNode.js b/tests/javascript/testrunnerNode.js new file mode 100644 index 0000000000..5b97d93eec --- /dev/null +++ b/tests/javascript/testrunnerNode.js @@ -0,0 +1,67 @@ +/*! + * Matomo - free/libre analytics platform + * + * UI test runner script + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; // ignore ssl errors + +const puppeteer = require('puppeteer'); +const url = process.argv[2] || 'http://localhost/tests/javascript/'; + +main(); + +async function main() { + + const browser = await puppeteer.launch({args: ['--no-sandbox', '--ignore-certificate-errors']}); + const page = await browser.newPage(); + + page.on('console', async (consoleMessage) => { + console.log("[" + consoleMessage.type() + "] " + consoleMessage.text()); + }); + + await page.goto(url); + await page.waitFor(() => window.QUnit); + + await page.evaluate(() => { + window.testsDone = false; + window.testsSuccessfull = false; + + QUnit.done(function (obj) { + console.info("Tests passed: " + obj.passed); + console.info("Tests failed: " + obj.failed); + console.info("Total tests: " + obj.total); + console.info("Runtime (ms): " + obj.runtime); + window.testsDone = true; + window.testsSuccessfull = (obj.failed == 0); + }); + + QUnit.log(function (obj) { + if (!obj.result) { + var errorMessage = "Test failed in module " + obj.module + ": '" + obj.name + "' \nError: " + obj.message; + + if (obj.actual) { + errorMessage += " \nActual: " + obj.actual; + } + + if (obj.expected) { + errorMessage += " \nExpected: " + obj.expected; + } + + errorMessage += " \nSource: " + obj.source + "\n\n"; + + console.info(errorMessage); + } + }); + }); + + await page.waitFor(() => !!window.testsDone, {timeout: 600000}); + + var success = await page.evaluate(function() { + return window.testsSuccessfull; + }); + + process.exit(success ? 0 : 1); +}
\ No newline at end of file diff --git a/tests/javascript/testrunner.js b/tests/javascript/testrunnerPhantom.js index 7194540ec8..7194540ec8 100644 --- a/tests/javascript/testrunner.js +++ b/tests/javascript/testrunnerPhantom.js |