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

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: Split out non-mocha stuff 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
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..872279c47f9ce72a6c1bbba860b82490310e45bc
--- /dev/null
+++ b/chrome/test/data/webui/mocha_adapter.js
@@ -0,0 +1,52 @@
+// 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 browser tests.
+ *
+ * Mocha requires a browser (or node), so mocha and this adapter should be
+ * included as part of the WebUI (i.e., as opposed to using GEN_INCLUDE).
+ */
+
+/**
+ * Initialize a reporter for the browser test framework.
+ * @param {Runner} runner
+ */
+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++;
+ console.error('Test failed: ' + test.fullTitle());
+ // The error message given by test_api.js includes relevant details like
+ // actual and expected values. The stack trace of the error isn't useful.
+ console.error(err.message);
+ });
+
+ // Report the results to the browser test API.
+ runner.on('end', function() {
+ if (failures == 0)
+ testDone();
+ testDone([
michaelpg 2015/05/05 16:46:33 should be "else {... }"
+ false,
+ 'Test Errors: ' + failures + '/' + (passes + failures) + ' tests failed'
+ ]);
+ });
+}
+
+// Configure Mocha.
+mocha.setup({
+ // Use "tdd" interface instead of "bdd".
+ ui: 'tdd',
+ // Use custom reporter to interface with browser test.
+ reporter: BrowserTestReporter,
+});

Powered by Google App Engine
This is Rietveld 408576698