summaryrefslogtreecommitdiffstats
path: root/remote/test/puppeteer/json-mocha-reporter.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /remote/test/puppeteer/json-mocha-reporter.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/test/puppeteer/json-mocha-reporter.js')
-rw-r--r--remote/test/puppeteer/json-mocha-reporter.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/remote/test/puppeteer/json-mocha-reporter.js b/remote/test/puppeteer/json-mocha-reporter.js
new file mode 100644
index 0000000000..47fc74a9c5
--- /dev/null
+++ b/remote/test/puppeteer/json-mocha-reporter.js
@@ -0,0 +1,68 @@
+const mocha = require('mocha');
+module.exports = JSONExtra;
+
+const constants = mocha.Runner.constants;
+
+/*
+
+This is a copy of
+https://github.com/mochajs/mocha/blob/master/lib/reporters/json-stream.js
+with more event hooks. mocha does not support extending reporters or using
+multiple reporters so a custom reporter is needed and it must be local
+to the project.
+
+*/
+
+function JSONExtra(runner, options) {
+ mocha.reporters.Base.call(this, runner, options);
+ const self = this;
+
+ runner.once(constants.EVENT_RUN_BEGIN, function () {
+ writeEvent(['start', { total: runner.total }]);
+ });
+
+ runner.on(constants.EVENT_TEST_PASS, function (test) {
+ writeEvent(['pass', clean(test)]);
+ });
+
+ runner.on(constants.EVENT_TEST_FAIL, function (test, err) {
+ test = clean(test);
+ test.err = err.message;
+ test.stack = err.stack || null;
+ writeEvent(['fail', test]);
+ });
+
+ runner.once(constants.EVENT_RUN_END, function () {
+ writeEvent(['end', self.stats]);
+ });
+
+ runner.on(constants.EVENT_TEST_BEGIN, function (test) {
+ writeEvent(['test-start', clean(test)]);
+ });
+
+ runner.on(constants.EVENT_TEST_PENDING, function (test) {
+ writeEvent(['pending', clean(test)]);
+ });
+}
+
+function writeEvent(event) {
+ process.stdout.write(JSON.stringify(event) + '\n');
+}
+
+/**
+ * Returns an object literal representation of `test`
+ * free of cyclic properties, etc.
+ *
+ * @private
+ * @param {Object} test - Instance used as data source.
+ * @return {Object} object containing pared-down test instance data
+ */
+function clean(test) {
+ return {
+ title: test.title,
+ fullTitle: test.fullTitle(),
+ file: test.file,
+ duration: test.duration,
+ currentRetry: test.currentRetry(),
+ };
+}