blob: 4ba2b9cceebc7a0a3f275e3c9b831d9510d90c11 [file] [log] [blame]
Robert Gindacf288e52012-10-15 11:13:52 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5'use strict';
6
Mike Frysingerd9900db2019-03-03 04:10:46 -05007/**
8 * @fileoverview Test framework setup when run inside the browser.
9 */
Robert Gindacf288e52012-10-15 11:13:52 -070010
Mike Frysingerd9900db2019-03-03 04:10:46 -050011// Setup the mocha framework.
12mocha.setup('bdd');
13mocha.checkLeaks();
14
15// Add a global shortcut to the assert API.
16const assert = chai.assert;
17
18// Catch any random errors before the test runner runs.
19let earlyError = null;
Mike Frysinger1db30cf2020-04-20 02:49:59 -040020/**
21 * Catch any errors.
22 *
23 * @param {*} args Whatever arguments are passed in.
24 */
25window.onerror = function(...args) {
26 earlyError = Array.from(args);
Mike Frysingerd9900db2019-03-03 04:10:46 -050027};
28
Joel Hockey0f933582019-08-27 18:01:51 -070029/** Run the test framework once everything is finished. */
Robert Gindacf288e52012-10-15 11:13:52 -070030window.onload = function() {
Robert Gindacf288e52012-10-15 11:13:52 -070031 hterm.defaultStorage = new lib.Storage.Memory();
32
Mike Frysingerd9900db2019-03-03 04:10:46 -050033 lib.init(() => {
34 mocha.run();
Robert Gindacf288e52012-10-15 11:13:52 -070035
Mike Frysingerd9900db2019-03-03 04:10:46 -050036 if (earlyError !== null) {
37 assert.fail(`uncaught exception detected:\n${earlyError.join('\n')}\n`);
38 }
39 });
Robert Gindacf288e52012-10-15 11:13:52 -070040};