Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 1 | // 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 Frysinger | d9900db | 2019-03-03 04:10:46 -0500 | [diff] [blame] | 7 | /** |
| 8 | * @fileoverview Test framework setup when run inside the browser. |
| 9 | */ |
Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 10 | |
Mike Frysinger | d9900db | 2019-03-03 04:10:46 -0500 | [diff] [blame] | 11 | // Setup the mocha framework. |
| 12 | mocha.setup('bdd'); |
| 13 | mocha.checkLeaks(); |
| 14 | |
| 15 | // Add a global shortcut to the assert API. |
| 16 | const assert = chai.assert; |
| 17 | |
| 18 | // Catch any random errors before the test runner runs. |
| 19 | let earlyError = null; |
Mike Frysinger | 1db30cf | 2020-04-20 02:49:59 -0400 | [diff] [blame] | 20 | /** |
| 21 | * Catch any errors. |
| 22 | * |
| 23 | * @param {*} args Whatever arguments are passed in. |
| 24 | */ |
| 25 | window.onerror = function(...args) { |
| 26 | earlyError = Array.from(args); |
Mike Frysinger | d9900db | 2019-03-03 04:10:46 -0500 | [diff] [blame] | 27 | }; |
| 28 | |
Joel Hockey | 0f93358 | 2019-08-27 18:01:51 -0700 | [diff] [blame] | 29 | /** Run the test framework once everything is finished. */ |
Mike Frysinger | 46b5ed8 | 2020-06-12 23:58:20 -0400 | [diff] [blame^] | 30 | window.onload = async function() { |
Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 31 | hterm.defaultStorage = new lib.Storage.Memory(); |
| 32 | |
Mike Frysinger | 46b5ed8 | 2020-06-12 23:58:20 -0400 | [diff] [blame^] | 33 | await lib.init(); |
| 34 | mocha.run(); |
Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 35 | |
Mike Frysinger | 46b5ed8 | 2020-06-12 23:58:20 -0400 | [diff] [blame^] | 36 | if (earlyError !== null) { |
| 37 | assert.fail(`uncaught exception detected:\n${earlyError.join('\n')}\n`); |
| 38 | } |
Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 39 | }; |