Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: chrome/test/data/webui/mocha_adapter.js

Issue 1124873002: Mocha adapter for Polymer browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 BrowserTests. To use, include mocha.js and
7 * mocha_adapter.js in a WebUIBrowserTest's extraLibraries array.
8 */
9
10 /**
11 * Initializes a mocha reporter for the BrowserTest framework, which registers
12 * event listeners on the given Runner.
13 * @constructor
14 * @param {Runner} runner Runs the tests and provides hooks for test results
15 * (see Runner.prototype in mocha.js).
16 */
17 function BrowserTestReporter(runner) {
18 var passes = 0;
19 var failures = 0;
20
21 // Increment passes for each passed test.
22 runner.on('pass', function(test) {
23 passes++;
Dan Beam 2015/06/02 18:11:16 what if a test accidentally passes twice and anoth
michaelpg 2015/06/02 19:32:59 All that junk is handled for free! Mocha throws an
24 });
25
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) {
29 failures++;
30 var message = 'Mocha test failed: ' + test.fullTitle() + '\n';
31
32 // We don't need tracing past the first line pointing to mocha.js.
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 break;
37 }
38 // Include the stack up to the first function from mocha.js.
39 if (i < stack.length)
40 message += stack.slice(0, i + 1).join('\n');
41 else
42 message += err.stack;
43
44 console.error(message);
45 });
46
47 // Report the results to the test API.
48 runner.on('end', function() {
49 if (failures == 0) {
50 testDone();
51 return;
52 }
53 testDone([
54 false,
55 'Test Errors: ' + failures + '/' + (passes + failures) +
56 ' tests had failed assertions.'
57 ]);
58 });
59 }
60
61 // Configure mocha.
62 mocha.setup({
63 // Use TDD interface instead of BDD.
64 ui: 'tdd',
65 // Use custom reporter to interface with BrowserTests.
66 reporter: BrowserTestReporter,
67 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698