tapFormatter.js 4.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright 2017 Palantir Technologies, Inc.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. var tslib_1 = require("tslib");
  20. var abstractFormatter_1 = require("../language/formatter/abstractFormatter");
  21. var Utils = require("../utils");
  22. var Formatter = /** @class */ (function (_super) {
  23. tslib_1.__extends(Formatter, _super);
  24. function Formatter() {
  25. return _super !== null && _super.apply(this, arguments) || this;
  26. }
  27. /* tslint:enable:object-literal-sort-keys */
  28. Formatter.prototype.format = function (failures) {
  29. var output = ["TAP version 13"];
  30. if (failures.length === 0) {
  31. output = output.concat([
  32. "1..0 # SKIP No failures",
  33. ]);
  34. }
  35. else {
  36. output = output.concat(["1.." + failures.length]).concat(this.mapToMessages(failures));
  37. }
  38. return output.join("\n") + "\n";
  39. };
  40. Formatter.prototype.mapToMessages = function (failures) {
  41. return failures.map(function (failure, i) {
  42. var fileName = failure.getFileName();
  43. var failureString = failure.getFailure();
  44. var ruleName = failure.getRuleName();
  45. var failureMessage = failure.getFailure();
  46. var failureSeverity = failure.getRuleSeverity();
  47. var failureRaw = failure.getRawLines();
  48. var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
  49. return Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n not ok ", " - ", "\n ---\n message : ", "\n severity: ", "\n data:\n ruleName: ", "\n fileName: ", "\n line: ", "\n character: ", "\n failureString: ", "\n rawLines: ", "\n ..."], ["\n not ok ", " - ", "\n ---\n message : ", "\n severity: ", "\n data:\n ruleName: ", "\n fileName: ", "\n line: ", "\n character: ", "\n failureString: ", "\n rawLines: ", "\n ..."])), String(i + 1), failureMessage, failureMessage, failureSeverity, ruleName, fileName, String(lineAndCharacter.line), String(lineAndCharacter.character), failureString, failureRaw);
  50. });
  51. };
  52. /* tslint:disable:object-literal-sort-keys */
  53. Formatter.metadata = {
  54. formatterName: "tap",
  55. description: "Formats output as TAP stream.",
  56. descriptionDetails: "Provides error messages output in TAP13 format which can be consumed by any TAP formatter.",
  57. sample: Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n TAP version 13\n 1..1\n not ok 1 - Some error\n ---\n message: Variable has any type\n severity: error\n data:\n ruleName: no-any\n fileName: test-file.ts\n line: 10\n character: 10\n failureString: Some error\n rawLines: Some raw output\n ..."], ["\n TAP version 13\n 1..1\n not ok 1 - Some error\n ---\n message: Variable has any type\n severity: error\n data:\n ruleName: no-any\n fileName: test-file.ts\n line: 10\n character: 10\n failureString: Some error\n rawLines: Some raw output\n ..."]))),
  58. consumer: "machine",
  59. };
  60. return Formatter;
  61. }(abstractFormatter_1.AbstractFormatter));
  62. exports.Formatter = Formatter;
  63. var templateObject_1, templateObject_2;