Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Added `Base#epilogue()`

Tj Holowaychuka9eed99c6a9a
diff --git a/lib/reporters/base.js b/lib/reporters/base.js
index 3c7c21fa..821e92a9 100644
--- a/lib/reporters/base.js
+++ b/lib/reporters/base.js
@@ -156,4 +156,36 @@ function Base(runner) {
stats.end = new Date;
stats.duration = new Date - stats.start;
});
-}
\ No newline at end of file
+}
+
+/**
+ * Output common epilogue used by many of
+ * the bundled reporters.
+ *
+ * @api public
+ */
+
+Base.prototype.epilogue = function(){
+ var stats = this.stats;
+
+ console.log();
+
+ // failure
+ if (stats.failures) {
+ console.log(
+ color('fail message', ' ✖ %d of %d tests failed')
+ , stats.failures, stats.tests);
+ Base.list(self.failures);
+ console.log();
+ process.exit(stats.failures);
+ }
+
+ // pass
+ console.log(
+ color('pass message', ' ✔ %d tests completed in %dms')
+ , stats.tests || 0
+ , stats.duration);
+
+ console.log();
+ process.exit(0);
+};
diff --git a/lib/reporters/dot.js b/lib/reporters/dot.js
index 049e2687..a1e56450 100644
--- a/lib/reporters/dot.js
+++ b/lib/reporters/dot.js
@@ -49,10 +49,16 @@ function Dot(runner) {
runner.on('end', function(){
console.log('\n');
if (stats.failures) {
- console.log(color('fail message', ' ✖ %d of %d tests failed'), stats.failures, stats.tests);
+ console.log(
+ color('fail message', ' ✖ %d of %d tests failed')
+ , stats.failures
+ , stats.tests);
Base.list(self.failures);
} else {
- console.log(color('pass message', ' ✔ %d tests completed in %dms'), stats.tests || 0, stats.duration);
+ console.log(
+ color('pass message', ' ✔ %d tests completed in %dms')
+ , stats.tests || 0
+ , stats.duration);
}
console.log();
process.exit(stats.failures);
diff --git a/lib/reporters/landing.js b/lib/reporters/landing.js
index a3e9fefa..55904912 100644
--- a/lib/reporters/landing.js
+++ b/lib/reporters/landing.js
@@ -87,10 +87,16 @@ function Landing(runner) {
cursor.show();
console.log('\n');
if (stats.failures) {
- console.log(color('fail message', ' ✖ %d of the %d passengers didnt make it!'), stats.failures, stats.tests);
+ console.log(
+ color('fail message', ' ✖ %d of the %d passengers didnt make it!')
+ , stats.failures
+ , stats.tests);
Base.list(self.failures);
} else {
- console.log(color('pass message', ' ✔ %d passengers arrived safely in %dms!'), stats.tests || 0, stats.duration);
+ console.log(
+ color('pass message', ' ✔ %d passengers arrived safely in %dms!')
+ , stats.tests || 0
+ , stats.duration);
}
console.log();
process.exit(stats.failures);
diff --git a/lib/reporters/list.js b/lib/reporters/list.js
index 83127fc8..d36976c0 100644
--- a/lib/reporters/list.js
+++ b/lib/reporters/list.js
@@ -43,15 +43,11 @@ function List(runner) {
// tests are complete, output some stats
// and the failures if any
- runner.on('end', function(){
- console.log();
- if (stats.failures) {
- console.log(color('fail message', ' ✖ %d of %d tests failed'), stats.failures, stats.tests);
- Base.list(self.failures);
- } else {
- console.log(color('pass message', ' ✔ %d tests completed in %dms'), stats.tests || 0, stats.duration);
- }
- console.log();
- process.exit(stats.failures);
- });
-}
\ No newline at end of file
+ runner.on('end', self.epilogue.bind(self));
+}
+
+/**
+ * Inherit from `Base.prototype`.
+ */
+
+List.prototype.__proto__ = Base.prototype;
\ No newline at end of file