Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/browser/_bootstrap.js

Issue 30025555: Issue 6820 - Move tests to mocha (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased Created April 10, 2019, 6:33 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/browser.js ('k') | test/browser/elemHideEmulation.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/browser/_bootstrap.js
===================================================================
--- a/test/browser/_bootstrap.js
+++ b/test/browser/_bootstrap.js
@@ -12,87 +12,53 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
-/* globals nodeunit */
-require("nodeunit");
-
-function runTests(moduleNames)
-{
- function bold(str)
- {
- return "\u001B[1m" + str + "\u001B[22m";
- }
-
- function ok(str)
- {
- return "\u001B[32m" + str + "\u001B[39m";
- }
+require("mocha");
- function error(str)
- {
- return "\u001B[31m" + str + "\u001B[39m";
- }
-
- let tests = {};
- for (let module of moduleNames)
- tests[module] = nodeunit.testCase(require("./" + module + ".js"));
+if (typeof window._consoleLogs == "undefined")
+ window._consoleLogs = {passes: 0, failures: 0, log: []};
- return new Promise((resolve, reject) =>
- {
- nodeunit.runModules(tests, {
- moduleStart(name)
- {
- if (typeof window._consoleLogs == "undefined")
- window._consoleLogs = {failures: 0, log: []};
- console.log(bold(name));
- },
- testDone(name, assertions)
- {
- let errors = assertions.filter(assertion => assertion.failed())
- .map(assertion => assertion.error);
+function Reporter(runner)
+{
+ mocha.reporters.Base.call(this, runner);
- if (errors.length == 0)
- console.log("\u2714 " + name);
- else
- {
- console.log(error("\u2716 " + name) + "\n");
- errors.forEach(e =>
- {
- if (e.stack)
- console.log(e.stack);
- else
- console.log(String(e));
- console.log("");
- });
- }
- },
- done(assertions)
- {
- let failures = assertions.filter(assertion => assertion.failed());
- if (failures.length)
- {
- window._consoleLogs.failures += failures.length;
- console.log(
- "\n" +
- bold(error("FAILURES: ")) +
- failures.length + "/" + assertions.length + " assertions failed"
- );
- }
- else
- {
- console.log(
- `\n ${bold(ok("OK: "))}${assertions.length} assertions (${assertions.duration}ms)`
- );
- }
+ runner.on("pass", test =>
+ {
+ window._consoleLogs.passes++;
+ console.log("pass: %s", test.fullTitle());
+ });
- resolve();
- }
- });
+ runner.on("fail", (test, err) =>
+ {
+ window._consoleLogs.failures++;
+ console.log("fail: %s -- error: %s", test.fullTitle(), err.message);
+ });
+
+ runner.on("end", () =>
+ {
+ console.log("end: %d/%d", window._consoleLogs.passes,
+ window._consoleLogs.passes + window._consoleLogs.failures);
});
}
-module.exports = runTests;
+function run(moduleNames)
+{
+ mocha.setup("bdd");
+ mocha.reporter = Reporter;
+
+ for (let module of moduleNames)
+ {
+ describe(module, () =>
+ {
+ require("./" + module + ".js");
+ });
+ }
+
+ mocha.run();
+}
+
+module.exports = run;
« no previous file with comments | « test/browser.js ('k') | test/browser/elemHideEmulation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld