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; |
| 20 | window.onerror = function() { |
| 21 | earlyError = Array.from(arguments); |
| 22 | }; |
| 23 | |
| 24 | // Run the test framework once everything is finished. |
Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 25 | window.onload = function() { |
Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 26 | hterm.defaultStorage = new lib.Storage.Memory(); |
| 27 | |
Mike Frysinger | d9900db | 2019-03-03 04:10:46 -0500 | [diff] [blame] | 28 | lib.init(() => { |
| 29 | mocha.run(); |
Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 30 | |
Mike Frysinger | d9900db | 2019-03-03 04:10:46 -0500 | [diff] [blame] | 31 | if (earlyError !== null) { |
| 32 | assert.fail(`uncaught exception detected:\n${earlyError.join('\n')}\n`); |
| 33 | } |
| 34 | }); |
Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 35 | }; |