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/testrunnerNode.js | |
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/testrunnerNode.js')
-rw-r--r-- | tests/javascript/testrunnerNode.js | 67 |
1 files changed, 67 insertions, 0 deletions
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 |