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