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.
6 * @fileoverview A mocha adapter for BrowserTests. To use, include mocha.js and
7 * mocha_adapter.js in a WebUIBrowserTest's extraLibraries array.
11 * Initializes a mocha reporter for the BrowserTest framework, which registers
12 * event listeners on the given Runner.
14 * @param {Runner} runner Runs the tests and provides hooks for test results
15 * (see Runner.prototype in mocha.js).
17 function BrowserTestReporter(runner) {
21 // Increment passes for each passed test.
22 runner.on('pass', function(test) {
26 // Report failures. Mocha only catches "assert" failures, because "expect"
27 // failures are caught by test_api.js.
28 runner.on('fail', function(test, err) {
30 var message = 'Mocha test failed: ' + test.fullTitle() + '\n';
32 // Remove unhelpful mocha lines from stack trace.
33 var stack = err.stack.split('\n');
34 for (var i = 0; i < stack.length; i++) {
35 if (stack[i].indexOf('mocha.js:') == -1)
36 message += stack[i] + '\n';
39 console.error(message);
42 // Report the results to the test API.
43 runner.on('end', function() {
50 'Test Errors: ' + failures + '/' + (passes + failures) +
51 ' tests had failed assertions.'
58 // Use TDD interface instead of BDD.
60 // Use custom reporter to interface with BrowserTests.
61 reporter: BrowserTestReporter,