aboutsummaryrefslogtreecommitdiff
path: root/node_modules/mocha/lib/reporters/json.js
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-27 00:03:48 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-27 00:03:48 +0000
commit714368c049f8749ed22c6d1d07bb3adc783dc349 (patch)
tree8952248ebf3f85b141ef0d18ecf6a1becdc8b89b /node_modules/mocha/lib/reporters/json.js
parent8beb37ed67b5f2fa0f9aa85499a8f11b39c9d067 (diff)
parentb65166302f5296165da115ed96ce112433157a2d (diff)
Merge branch 'master' of https://github.com/HumairAK/solutions_repo
Diffstat (limited to 'node_modules/mocha/lib/reporters/json.js')
-rw-r--r--node_modules/mocha/lib/reporters/json.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/node_modules/mocha/lib/reporters/json.js b/node_modules/mocha/lib/reporters/json.js
new file mode 100644
index 0000000..cd9ec28
--- /dev/null
+++ b/node_modules/mocha/lib/reporters/json.js
@@ -0,0 +1,90 @@
+/**
+ * Module dependencies.
+ */
+
+var Base = require('./base');
+
+/**
+ * Expose `JSON`.
+ */
+
+exports = module.exports = JSONReporter;
+
+/**
+ * Initialize a new `JSON` reporter.
+ *
+ * @api public
+ * @param {Runner} runner
+ */
+function JSONReporter(runner) {
+ Base.call(this, runner);
+
+ var self = this;
+ var tests = [];
+ var pending = [];
+ var failures = [];
+ var passes = [];
+
+ runner.on('test end', function(test) {
+ tests.push(test);
+ });
+
+ runner.on('pass', function(test) {
+ passes.push(test);
+ });
+
+ runner.on('fail', function(test) {
+ failures.push(test);
+ });
+
+ runner.on('pending', function(test) {
+ pending.push(test);
+ });
+
+ runner.on('end', function() {
+ var obj = {
+ stats: self.stats,
+ tests: tests.map(clean),
+ pending: pending.map(clean),
+ failures: failures.map(clean),
+ passes: passes.map(clean)
+ };
+
+ runner.testResults = obj;
+
+ process.stdout.write(JSON.stringify(obj, null, 2));
+ });
+}
+
+/**
+ * Return a plain-object representation of `test`
+ * free of cyclic properties etc.
+ *
+ * @api private
+ * @param {Object} test
+ * @return {Object}
+ */
+function clean(test) {
+ return {
+ title: test.title,
+ fullTitle: test.fullTitle(),
+ duration: test.duration,
+ currentRetry: test.currentRetry(),
+ err: errorJSON(test.err || {})
+ };
+}
+
+/**
+ * Transform `error` into a JSON object.
+ *
+ * @api private
+ * @param {Error} err
+ * @return {Object}
+ */
+function errorJSON(err) {
+ var res = {};
+ Object.getOwnPropertyNames(err).forEach(function(key) {
+ res[key] = err[key];
+ }, err);
+ return res;
+}