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 | |
Mike Frysinger | 21571a7 | 2017-04-07 17:14:19 -0400 | [diff] [blame] | 19 | testManager.onTestRunComplete = (testRun) => { |
| 20 | var document = testRun.cx.window.document; |
| 21 | document.body.innerHTML = ''; |
| 22 | |
| 23 | var results = document.createElement('div'); |
| 24 | var p, pre; |
| 25 | |
| 26 | p = document.createElement('p'); |
| 27 | p.innerText = 'Check JavaScript console for test log/status.'; |
| 28 | results.appendChild(p); |
| 29 | |
| 30 | p = document.createElement('p'); |
| 31 | p.id = 'status'; |
| 32 | p.innerText = 'Finished.'; |
| 33 | p.className = (testRun.failures.length == 0) ? 'good' : 'bad'; |
| 34 | results.appendChild(p); |
| 35 | |
| 36 | p = document.createElement('p'); |
| 37 | p.id = 'passed'; |
| 38 | p.className = 'good'; |
Mike Frysinger | cd988ec | 2017-04-20 18:25:17 -0400 | [diff] [blame^] | 39 | document.title = p.innerText = testRun.passes.length + ' tests passed.'; |
Mike Frysinger | 21571a7 | 2017-04-07 17:14:19 -0400 | [diff] [blame] | 40 | results.appendChild(p); |
| 41 | |
| 42 | p = document.createElement('p'); |
| 43 | p.id = 'failed'; |
| 44 | p.className = 'bad'; |
| 45 | if (testRun.failures.length != 0) |
Mike Frysinger | cd988ec | 2017-04-20 18:25:17 -0400 | [diff] [blame^] | 46 | document.title = p.innerText = |
| 47 | 'ERROR: ' + testRun.failures.length + ' tests failed!'; |
Mike Frysinger | 21571a7 | 2017-04-07 17:14:19 -0400 | [diff] [blame] | 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 | |
Mike Frysinger | cd988ec | 2017-04-20 18:25:17 -0400 | [diff] [blame^] | 62 | testManager.testPreamble = (result, cx) => { |
| 63 | var testRun = result.testRun; |
| 64 | cx.window.document.title = |
| 65 | '[' + (testRun.passes.length + testRun.failures.length) + '] ' + |
| 66 | result.test.fullName; |
| 67 | }; |
| 68 | |
| 69 | testRun = testManager.createTestRun({window: window}); |
| 70 | |
Robert Ginda | cf288e5 | 2012-10-15 11:13:52 -0700 | [diff] [blame] | 71 | // Stop after the first failure to make it easier to debug in the |
| 72 | // JS console. |
| 73 | testRun.maxFailures = 1; |
| 74 | |
| 75 | testRun.selectPattern(testRun.ALL_TESTS); |
| 76 | testRun.run(); |
| 77 | |
| 78 | }), console.log.bind(console)); |
| 79 | }; |