Welcome to mirror list, hosted at ThFree Co, Russian Federation.

testrunnerNode.js « javascript « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5b97d93eecde4d3f124e08098675a13a1bd08295 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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);
}