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