1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | function _stripAnsi() {
|
9 | const data = _interopRequireDefault(require('strip-ansi'));
|
10 |
|
11 | _stripAnsi = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _jestMessageUtil() {
|
19 | const data = require('jest-message-util');
|
20 |
|
21 | _jestMessageUtil = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | var _BaseReporter = _interopRequireDefault(require('./BaseReporter'));
|
29 |
|
30 | function _interopRequireDefault(obj) {
|
31 | return obj && obj.__esModule ? obj : {default: obj};
|
32 | }
|
33 |
|
34 | function _classPrivateMethodInitSpec(obj, privateSet) {
|
35 | _checkPrivateRedeclaration(obj, privateSet);
|
36 | privateSet.add(obj);
|
37 | }
|
38 |
|
39 | function _checkPrivateRedeclaration(obj, privateCollection) {
|
40 | if (privateCollection.has(obj)) {
|
41 | throw new TypeError(
|
42 | 'Cannot initialize the same private elements twice on an object'
|
43 | );
|
44 | }
|
45 | }
|
46 |
|
47 | function _defineProperty(obj, key, value) {
|
48 | if (key in obj) {
|
49 | Object.defineProperty(obj, key, {
|
50 | value: value,
|
51 | enumerable: true,
|
52 | configurable: true,
|
53 | writable: true
|
54 | });
|
55 | } else {
|
56 | obj[key] = value;
|
57 | }
|
58 | return obj;
|
59 | }
|
60 |
|
61 | function _classPrivateMethodGet(receiver, privateSet, fn) {
|
62 | if (!privateSet.has(receiver)) {
|
63 | throw new TypeError('attempted to get private field on non-instance');
|
64 | }
|
65 | return fn;
|
66 | }
|
67 |
|
68 | const titleSeparator = ' \u203A ';
|
69 |
|
70 | var _getMessageDetails = new WeakSet();
|
71 |
|
72 | var _createAnnotation = new WeakSet();
|
73 |
|
74 | class GitHubActionsReporter extends _BaseReporter.default {
|
75 | constructor(...args) {
|
76 | super(...args);
|
77 |
|
78 | _classPrivateMethodInitSpec(this, _createAnnotation);
|
79 |
|
80 | _classPrivateMethodInitSpec(this, _getMessageDetails);
|
81 | }
|
82 |
|
83 | onTestFileResult({context}, {testResults}) {
|
84 | testResults.forEach(result => {
|
85 | var _result$retryReasons;
|
86 |
|
87 | const title = [...result.ancestorTitles, result.title].join(
|
88 | titleSeparator
|
89 | );
|
90 | (_result$retryReasons = result.retryReasons) === null ||
|
91 | _result$retryReasons === void 0
|
92 | ? void 0
|
93 | : _result$retryReasons.forEach((retryReason, index) => {
|
94 | _classPrivateMethodGet(
|
95 | this,
|
96 | _createAnnotation,
|
97 | _createAnnotation2
|
98 | ).call(this, {
|
99 | ..._classPrivateMethodGet(
|
100 | this,
|
101 | _getMessageDetails,
|
102 | _getMessageDetails2
|
103 | ).call(this, retryReason, context.config),
|
104 | title: `RETRY ${index + 1}: ${title}`,
|
105 | type: 'warning'
|
106 | });
|
107 | });
|
108 | result.failureMessages.forEach(failureMessage => {
|
109 | _classPrivateMethodGet(
|
110 | this,
|
111 | _createAnnotation,
|
112 | _createAnnotation2
|
113 | ).call(this, {
|
114 | ..._classPrivateMethodGet(
|
115 | this,
|
116 | _getMessageDetails,
|
117 | _getMessageDetails2
|
118 | ).call(this, failureMessage, context.config),
|
119 | title,
|
120 | type: 'error'
|
121 | });
|
122 | });
|
123 | });
|
124 | }
|
125 | }
|
126 |
|
127 | exports.default = GitHubActionsReporter;
|
128 |
|
129 | function _getMessageDetails2(failureMessage, config) {
|
130 | const {message, stack} = (0, _jestMessageUtil().separateMessageFromStack)(
|
131 | failureMessage
|
132 | );
|
133 | const stackLines = (0, _jestMessageUtil().getStackTraceLines)(stack);
|
134 | const topFrame = (0, _jestMessageUtil().getTopFrame)(stackLines);
|
135 | const normalizedStackLines = stackLines.map(line =>
|
136 | (0, _jestMessageUtil().formatPath)(line, config)
|
137 | );
|
138 | const messageText = [message, ...normalizedStackLines].join('\n');
|
139 | return {
|
140 | file: topFrame === null || topFrame === void 0 ? void 0 : topFrame.file,
|
141 | line: topFrame === null || topFrame === void 0 ? void 0 : topFrame.line,
|
142 | message: messageText
|
143 | };
|
144 | }
|
145 |
|
146 | function _createAnnotation2({file, line, message, title, type}) {
|
147 | message = (0, _stripAnsi().default)(
|
148 |
|
149 | message.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A')
|
150 | );
|
151 | this.log(`\n::${type} file=${file},line=${line},title=${title}::${message}`);
|
152 | }
|
153 |
|
154 | _defineProperty(GitHubActionsReporter, 'filename', __filename);
|