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

Unified 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, 7 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/mocha_adapter.js
diff --git a/chrome/test/data/webui/mocha_adapter.js b/chrome/test/data/webui/mocha_adapter.js
new file mode 100644
index 0000000000000000000000000000000000000000..1c52426d4da1208453496d75cd47ec11bb0b5d3b
--- /dev/null
+++ b/chrome/test/data/webui/mocha_adapter.js
@@ -0,0 +1,65 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview A mocha adapter for BrowserTests. To use, include mocha.js and
+ * mocha_adapter.js in a WebUIBrowserTest's extraLibraries array.
+ */
+
+/**
+ * Initializes a mocha reporter for the BrowserTest framework.
+ * @constructor
+ * @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.
+ */
+function BrowserTestReporter(runner) {
+ var passes = 0;
+ var failures = 0;
+
+ // Increment passes for each passed test.
+ runner.on('pass', function(test) {
+ passes++;
+ });
+
+ // Report failures. Mocha only catches "assert" failures, because "expect"
+ // failures are caught by test_api.js.
+ runner.on('fail', function(test, err) {
+ failures++;
+ var message = 'Mocha test failed: ' + test.fullTitle() + '\n';
+
+ // We don't need tracing past the first line pointing to mocha.js.
+ var stack = err.stack.split('\n');
+ for (var i = 0; i < stack.length; i++) {
+ if (stack[i].indexOf('(mocha.js:') != -1)
+ break;
+ }
+ // Include the stack up to the first function from mocha.js.
+ if (i < stack.length)
+ message += stack.slice(0, i + 1).join('\n');
+ else
+ message += err.stack;
+
+ console.error(message);
+ });
+
+ // Report the results to the test API.
+ runner.on('end', function() {
+ if (failures == 0) {
+ testDone();
+ return;
+ }
+ testDone([
+ false,
+ 'Test Errors: ' + failures + '/' + (passes + failures) +
+ ' tests had failed assertions.'
+ ]);
+ });
+}
+
+// Configure mocha.
+mocha.setup({
+ // Use TDD interface instead of BDD.
+ ui: 'tdd',
+ // Use custom reporter to interface with BrowserTests.
+ reporter: BrowserTestReporter,
+});
« 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