dot.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _base = require("./base");
  7. /**
  8. * Copyright (c) Microsoft Corporation.
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. class DotReporter extends _base.BaseReporter {
  23. constructor(...args) {
  24. super(...args);
  25. this._counter = 0;
  26. }
  27. printsToStdio() {
  28. return true;
  29. }
  30. onBegin(suite) {
  31. super.onBegin(suite);
  32. console.log(this.generateStartingMessage());
  33. }
  34. onStdOut(chunk, test, result) {
  35. super.onStdOut(chunk, test, result);
  36. if (!this.config.quiet) process.stdout.write(chunk);
  37. }
  38. onStdErr(chunk, test, result) {
  39. super.onStdErr(chunk, test, result);
  40. if (!this.config.quiet) process.stderr.write(chunk);
  41. }
  42. onTestEnd(test, result) {
  43. super.onTestEnd(test, result);
  44. if (this._counter === 80) {
  45. process.stdout.write('\n');
  46. this._counter = 0;
  47. }
  48. ++this._counter;
  49. if (result.status === 'skipped') {
  50. process.stdout.write(_base.colors.yellow('°'));
  51. return;
  52. }
  53. if (this.willRetry(test)) {
  54. process.stdout.write(_base.colors.gray('×'));
  55. return;
  56. }
  57. switch (test.outcome()) {
  58. case 'expected':
  59. process.stdout.write(_base.colors.green('·'));
  60. break;
  61. case 'unexpected':
  62. process.stdout.write(_base.colors.red(result.status === 'timedOut' ? 'T' : 'F'));
  63. break;
  64. case 'flaky':
  65. process.stdout.write(_base.colors.yellow('±'));
  66. break;
  67. }
  68. }
  69. onError(error) {
  70. super.onError(error);
  71. console.log('\n' + (0, _base.formatError)(error, _base.colors.enabled).message);
  72. this._counter = 0;
  73. }
  74. async onEnd(result) {
  75. await super.onEnd(result);
  76. process.stdout.write('\n');
  77. this.epilogue(true);
  78. }
  79. }
  80. var _default = exports.default = DotReporter;