Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium 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 /** | |
| 6 * @fileoverview A mocha adapter for browser tests. | |
| 7 * | |
| 8 * Mocha requires a browser (or node), so mocha and this adapter should be | |
| 9 * included as part of the WebUI (i.e., as opposed to using GEN_INCLUDE). | |
| 10 */ | |
| 11 | |
| 12 /** | |
| 13 * Initialize a reporter for the browser test framework. | |
| 14 * @param {Runner} runner | |
| 15 */ | |
| 16 function BrowserTestReporter(runner) { | |
| 17 var passes = 0; | |
| 18 var failures = 0; | |
| 19 | |
| 20 // Increment passes for each passed test. | |
| 21 runner.on('pass', function(test) { | |
| 22 passes++; | |
| 23 }); | |
| 24 | |
| 25 // Report failures. Mocha only catches "assert" failures, because "expect" | |
| 26 // failures are caught by test_api.js. | |
| 27 runner.on('fail', function(test, err) { | |
| 28 failures++; | |
| 29 console.error('Test failed: ' + test.fullTitle()); | |
| 30 // The error message given by test_api.js includes relevant details like | |
| 31 // actual and expected values. The stack trace of the error isn't useful. | |
| 32 console.error(err.message); | |
| 33 }); | |
| 34 | |
| 35 // Report the results to the browser test API. | |
| 36 runner.on('end', function() { | |
| 37 if (failures == 0) | |
| 38 testDone(); | |
| 39 testDone([ | |
|
michaelpg
2015/05/05 16:46:33
should be "else {... }"
| |
| 40 false, | |
| 41 'Test Errors: ' + failures + '/' + (passes + failures) + ' tests failed' | |
| 42 ]); | |
| 43 }); | |
| 44 } | |
| 45 | |
| 46 // Configure Mocha. | |
| 47 mocha.setup({ | |
| 48 // Use "tdd" interface instead of "bdd". | |
| 49 ui: 'tdd', | |
| 50 // Use custom reporter to interface with browser test. | |
| 51 reporter: BrowserTestReporter, | |
| 52 }); | |
| OLD | NEW |