github.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __getProtoOf = Object.getPrototypeOf;
  7. var __hasOwnProp = Object.prototype.hasOwnProperty;
  8. var __export = (target, all) => {
  9. for (var name in all)
  10. __defProp(target, name, { get: all[name], enumerable: true });
  11. };
  12. var __copyProps = (to, from, except, desc) => {
  13. if (from && typeof from === "object" || typeof from === "function") {
  14. for (let key of __getOwnPropNames(from))
  15. if (!__hasOwnProp.call(to, key) && key !== except)
  16. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  17. }
  18. return to;
  19. };
  20. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  21. // If the importer is in node compatibility mode or this is not an ESM
  22. // file that has been converted to a CommonJS file using a Babel-
  23. // compatible transform (i.e. "__esModule" has not been set), then set
  24. // "default" to the CommonJS "module.exports" for node compatibility.
  25. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  26. mod
  27. ));
  28. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  29. var github_exports = {};
  30. __export(github_exports, {
  31. GitHubReporter: () => GitHubReporter,
  32. default: () => github_default
  33. });
  34. module.exports = __toCommonJS(github_exports);
  35. var import_path = __toESM(require("path"));
  36. var import_utils = require("playwright-core/lib/utils");
  37. var import_utilsBundle = require("playwright-core/lib/utilsBundle");
  38. var import_base = require("./base");
  39. var import_util = require("../util");
  40. class GitHubLogger {
  41. _log(message, type = "notice", options = {}) {
  42. message = message.replace(/\n/g, "%0A");
  43. const configs = Object.entries(options).map(([key, option]) => `${key}=${option}`).join(",");
  44. process.stdout.write((0, import_util.stripAnsiEscapes)(`::${type} ${configs}::${message}
  45. `));
  46. }
  47. debug(message, options) {
  48. this._log(message, "debug", options);
  49. }
  50. error(message, options) {
  51. this._log(message, "error", options);
  52. }
  53. notice(message, options) {
  54. this._log(message, "notice", options);
  55. }
  56. warning(message, options) {
  57. this._log(message, "warning", options);
  58. }
  59. }
  60. class GitHubReporter extends import_base.TerminalReporter {
  61. constructor(options = {}) {
  62. super(options);
  63. this.githubLogger = new GitHubLogger();
  64. this.screen = { ...this.screen, colors: import_utils.noColors };
  65. }
  66. printsToStdio() {
  67. return false;
  68. }
  69. async onEnd(result) {
  70. await super.onEnd(result);
  71. this._printAnnotations();
  72. }
  73. onError(error) {
  74. const errorMessage = this.formatError(error).message;
  75. this.githubLogger.error(errorMessage);
  76. }
  77. _printAnnotations() {
  78. const summary = this.generateSummary();
  79. const summaryMessage = this.generateSummaryMessage(summary);
  80. if (summary.failuresToPrint.length)
  81. this._printFailureAnnotations(summary.failuresToPrint);
  82. this._printSlowTestAnnotations();
  83. this._printSummaryAnnotation(summaryMessage);
  84. }
  85. _printSlowTestAnnotations() {
  86. this.getSlowTests().forEach(([file, duration]) => {
  87. const filePath = workspaceRelativePath(import_path.default.join(process.cwd(), file));
  88. this.githubLogger.warning(`${filePath} took ${(0, import_utilsBundle.ms)(duration)}`, {
  89. title: "Slow Test",
  90. file: filePath
  91. });
  92. });
  93. }
  94. _printSummaryAnnotation(summary) {
  95. this.githubLogger.notice(summary, {
  96. title: "\u{1F3AD} Playwright Run Summary"
  97. });
  98. }
  99. _printFailureAnnotations(failures) {
  100. failures.forEach((test, index) => {
  101. const title = this.formatTestTitle(test);
  102. const header = this.formatTestHeader(test, { indent: " ", index: index + 1, mode: "error" });
  103. for (const result of test.results) {
  104. const errors = (0, import_base.formatResultFailure)(this.screen, test, result, " ");
  105. for (const error of errors) {
  106. const options = {
  107. file: workspaceRelativePath(error.location?.file || test.location.file),
  108. title
  109. };
  110. if (error.location) {
  111. options.line = error.location.line;
  112. options.col = error.location.column;
  113. }
  114. const message = [header, ...(0, import_base.formatRetry)(this.screen, result), error.message].join("\n");
  115. this.githubLogger.error(message, options);
  116. }
  117. }
  118. });
  119. }
  120. }
  121. function workspaceRelativePath(filePath) {
  122. return import_path.default.relative(process.env["GITHUB_WORKSPACE"] ?? "", filePath);
  123. }
  124. var github_default = GitHubReporter;
  125. // Annotate the CommonJS export names for ESM import in node:
  126. 0 && (module.exports = {
  127. GitHubReporter
  128. });