summaryrefslogtreecommitdiff
path: root/installed-tests/js/minijasmine-executor.js
blob: 3fe8b7827307bf91ba31c600369ef1a9132f636d (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
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2016 Philip Chimento <philip.chimento@gmail.com>
// SPDX-FileCopyrightText: 2022 Evan Welsh <contact@evanwelsh.com>

import * as system from 'system';

import GLib from 'gi://GLib';
import {environment, retval, errorsOutput, mainloop, mainloopLock} from './minijasmine.js';

/* jasmineEnv.execute() queues up all the tests and runs them
 * asynchronously. This should start after the main loop starts, otherwise
 * we will hit the main loop only after several tests have already run. For
 * consistency we should guarantee that there is a main loop running during
 * all tests.
 */
GLib.idle_add(GLib.PRIORITY_DEFAULT, function () {
    try {
        environment.execute();
    } catch (e) {
        print('Bail out! Exception occurred inside Jasmine:', e);

        mainloop.quit();

        system.exit(1);
    }

    return GLib.SOURCE_REMOVE;
});

// Keep running the mainloop while mainloopLock
// is not null and resolves true
do {
    // Run the mainloop

    // This rule is to encourage parallelizing async
    // operations, in this case we don't want that.
    // eslint-disable-next-line no-await-in-loop
    await mainloop.runAsync();
// eslint-disable-next-line no-await-in-loop
} while (await mainloopLock);

// On exit, check the return value and print any errors which occurred
if (retval !== 0) {
    printerr(errorsOutput.join('\n'));
    print('# Test script failed; see test log for assertions');
    system.exit(retval);
}