Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

json-stream.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use strict';
  2. /**
  3. * @module JSONStream
  4. */
  5. /**
  6. * Module dependencies.
  7. */
  8. var Base = require('./base');
  9. var constants = require('../runner').constants;
  10. var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
  11. var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
  12. var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
  13. var EVENT_RUN_END = constants.EVENT_RUN_END;
  14. /**
  15. * Expose `JSONStream`.
  16. */
  17. exports = module.exports = JSONStream;
  18. /**
  19. * Constructs a new `JSONStream` reporter instance.
  20. *
  21. * @public
  22. * @class
  23. * @memberof Mocha.reporters
  24. * @extends Mocha.reporters.Base
  25. * @param {Runner} runner - Instance triggers reporter actions.
  26. * @param {Object} [options] - runner options
  27. */
  28. function JSONStream(runner, options) {
  29. Base.call(this, runner, options);
  30. var self = this;
  31. var total = runner.total;
  32. runner.once(EVENT_RUN_BEGIN, function() {
  33. writeEvent(['start', {total: total}]);
  34. });
  35. runner.on(EVENT_TEST_PASS, function(test) {
  36. writeEvent(['pass', clean(test)]);
  37. });
  38. runner.on(EVENT_TEST_FAIL, function(test, err) {
  39. test = clean(test);
  40. test.err = err.message;
  41. test.stack = err.stack || null;
  42. writeEvent(['fail', test]);
  43. });
  44. runner.once(EVENT_RUN_END, function() {
  45. writeEvent(['end', self.stats]);
  46. });
  47. }
  48. /**
  49. * Mocha event to be written to the output stream.
  50. * @typedef {Array} JSONStream~MochaEvent
  51. */
  52. /**
  53. * Writes Mocha event to reporter output stream.
  54. *
  55. * @private
  56. * @param {JSONStream~MochaEvent} event - Mocha event to be output.
  57. */
  58. function writeEvent(event) {
  59. process.stdout.write(JSON.stringify(event) + '\n');
  60. }
  61. /**
  62. * Returns an object literal representation of `test`
  63. * free of cyclic properties, etc.
  64. *
  65. * @private
  66. * @param {Test} test - Instance used as data source.
  67. * @return {Object} object containing pared-down test instance data
  68. */
  69. function clean(test) {
  70. return {
  71. title: test.title,
  72. fullTitle: test.fullTitle(),
  73. file: test.file,
  74. duration: test.duration,
  75. currentRetry: test.currentRetry()
  76. };
  77. }
  78. JSONStream.description = 'newline delimited JSON events';