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

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: Mocha adapter and Polymer BrowserTest. 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
« no previous file with comments | « no previous file | chrome/test/data/webui/polymer_browser_test_base.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
12 * @constructor
13 * @param {Runner} runner
James Hawkins 2015/06/01 20:18:17 nit: Please provide more details about what runner
michaelpg 2015/06/01 21:23:01 Done.
14 */
15 function BrowserTestReporter(runner) {
16 var passes = 0;
17 var failures = 0;
18
19 // Increment passes for each passed test.
20 runner.on('pass', function(test) {
21 passes++;
22 });
23
24 // Report failures. Mocha only catches "assert" failures, because "expect"
25 // failures are caught by test_api.js.
26 runner.on('fail', function(test, err) {
27 failures++;
28 var message = 'Mocha test failed: ' + test.fullTitle() + '\n';
29
30 // We don't need tracing past the first line pointing to mocha.js.
31 var stack = err.stack.split('\n');
32 for (var i = 0; i < stack.length; i++) {
33 if (stack[i].indexOf('(mocha.js:') != -1)
34 break;
35 }
36 // Include the stack up to the first function from mocha.js.
37 if (i < stack.length)
38 message += stack.slice(0, i + 1).join('\n');
39 else
40 message += err.stack;
41
42 console.error(message);
43 });
44
45 // Report the results to the test API.
46 runner.on('end', function() {
47 if (failures == 0) {
48 testDone();
49 return;
50 }
51 testDone([
52 false,
53 'Test Errors: ' + failures + '/' + (passes + failures) +
54 ' tests had failed assertions.'
55 ]);
56 });
57 }
58
59 // Configure mocha.
60 mocha.setup({
61 // Use TDD interface instead of BDD.
62 ui: 'tdd',
63 // Use custom reporter to interface with BrowserTests.
64 reporter: BrowserTestReporter,
65 });
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webui/polymer_browser_test_base.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698