markdown.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _fs = _interopRequireDefault(require("fs"));
  7. var _path = _interopRequireDefault(require("path"));
  8. var _util = require("../util");
  9. var _base = require("./base");
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. /**
  12. * Copyright (c) Microsoft Corporation.
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License");
  15. * you may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. class MarkdownReporter extends _base.BaseReporter {
  27. constructor(options) {
  28. super();
  29. this._options = void 0;
  30. this._options = options;
  31. }
  32. printsToStdio() {
  33. return false;
  34. }
  35. async onEnd(result) {
  36. await super.onEnd(result);
  37. const summary = this.generateSummary();
  38. const lines = [];
  39. if (summary.fatalErrors.length) lines.push(`**${summary.fatalErrors.length} fatal errors, not part of any test**`);
  40. if (summary.unexpected.length) {
  41. lines.push(`**${summary.unexpected.length} failed**`);
  42. this._printTestList(':x:', summary.unexpected, lines);
  43. }
  44. if (summary.flaky.length) {
  45. lines.push(`<details>`);
  46. lines.push(`<summary><b>${summary.flaky.length} flaky</b></summary>`);
  47. this._printTestList(':warning:', summary.flaky, lines, ' <br/>');
  48. lines.push(`</details>`);
  49. lines.push(``);
  50. }
  51. if (summary.interrupted.length) {
  52. lines.push(`<details>`);
  53. lines.push(`<summary><b>${summary.interrupted.length} interrupted</b></summary>`);
  54. this._printTestList(':warning:', summary.interrupted, lines, ' <br/>');
  55. lines.push(`</details>`);
  56. lines.push(``);
  57. }
  58. const skipped = summary.skipped ? `, ${summary.skipped} skipped` : '';
  59. const didNotRun = summary.didNotRun ? `, ${summary.didNotRun} did not run` : '';
  60. lines.push(`**${summary.expected} passed${skipped}${didNotRun}**`);
  61. lines.push(`:heavy_check_mark::heavy_check_mark::heavy_check_mark:`);
  62. lines.push(``);
  63. const reportFile = (0, _util.resolveReporterOutputPath)('report.md', this._options.configDir, this._options.outputFile);
  64. await _fs.default.promises.mkdir(_path.default.dirname(reportFile), {
  65. recursive: true
  66. });
  67. await _fs.default.promises.writeFile(reportFile, lines.join('\n'));
  68. }
  69. _printTestList(prefix, tests, lines, suffix) {
  70. for (const test of tests) lines.push(`${prefix} ${(0, _base.formatTestTitle)(this.config, test)}${suffix || ''}`);
  71. lines.push(``);
  72. }
  73. }
  74. var _default = exports.default = MarkdownReporter;