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 | |
| 7 | var testManager; |
| 8 | var testRun; |
| 9 | |
| 10 | window.onload = function() { |
| 11 | lib.rtdep(hterm.testDeps); |
| 12 | |
| 13 | hterm.defaultStorage = new lib.Storage.Memory(); |
| 14 | |
| 15 | lib.init(lib.f.alarm(function() { |
| 16 | testManager = new lib.TestManager(); |
Mike Frysinger | 21571a7 | 2017-04-07 17:14:19 -0400 | [diff] [blame] | 17 | testManager.log.save = true; |
Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 18 | testRun = testManager.createTestRun({window: window}); |
| 19 | |
Mike Frysinger | 21571a7 | 2017-04-07 17:14:19 -0400 | [diff] [blame] | 20 | testManager.onTestRunComplete = (testRun) => { |
| 21 | var document = testRun.cx.window.document; |
| 22 | document.body.innerHTML = ''; |
| 23 | |
| 24 | var results = document.createElement('div'); |
| 25 | var p, pre; |
| 26 | |
| 27 | p = document.createElement('p'); |
| 28 | p.innerText = 'Check JavaScript console for test log/status.'; |
| 29 | results.appendChild(p); |
| 30 | |
| 31 | p = document.createElement('p'); |
| 32 | p.id = 'status'; |
| 33 | p.innerText = 'Finished.'; |
| 34 | p.className = (testRun.failures.length == 0) ? 'good' : 'bad'; |
| 35 | results.appendChild(p); |
| 36 | |
| 37 | p = document.createElement('p'); |
| 38 | p.id = 'passed'; |
| 39 | p.className = 'good'; |
| 40 | p.innerText = testRun.passes.length + ' tests passed.'; |
| 41 | results.appendChild(p); |
| 42 | |
| 43 | p = document.createElement('p'); |
| 44 | p.id = 'failed'; |
| 45 | p.className = 'bad'; |
| 46 | if (testRun.failures.length != 0) |
| 47 | p.innerText = 'ERROR: ' + testRun.failures.length + ' tests failed!'; |
| 48 | results.appendChild(p); |
| 49 | |
| 50 | pre = document.createElement('pre'); |
| 51 | pre.id = 'log'; |
| 52 | pre.innerText = testRun.testManager.log.data; |
| 53 | results.appendChild(pre); |
| 54 | |
| 55 | // Only clear the body if everything passed in case the current rendering |
| 56 | // is useful to debugging. Insert our log/results above it. |
| 57 | if (testRun.failures.length == 0) |
| 58 | document.body.innerText = ''; |
| 59 | document.body.insertBefore(results, document.body.firstChild); |
| 60 | }; |
| 61 | |
Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 62 | // Stop after the first failure to make it easier to debug in the |
| 63 | // JS console. |
| 64 | testRun.maxFailures = 1; |
| 65 | |
| 66 | testRun.selectPattern(testRun.ALL_TESTS); |
| 67 | testRun.run(); |
| 68 | |
| 69 | }), console.log.bind(console)); |
| 70 | }; |