testcafe-reporter-qase 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -1,3 +1,9 @@
1
+ # qase-testcafe@2.0.6
2
+
3
+ ## What's new
4
+
5
+ Enhanced handling of start and end times for tests and steps, ensuring greater accuracy in reporting.
6
+
1
7
  # qase-testcafe@2.0.4
2
8
 
3
9
  ## What's new
package/dist/global.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Qase = void 0;
4
4
  class Qase {
5
+ reporter;
5
6
  constructor(reporter) {
6
7
  this.reporter = reporter;
7
8
  }
package/dist/qase.js CHANGED
@@ -2,7 +2,6 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- var _a;
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
7
6
  exports.qase = void 0;
8
7
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
@@ -10,182 +9,181 @@ const path_1 = __importDefault(require("path"));
10
9
  const qase_javascript_commons_1 = require("qase-javascript-commons");
11
10
  const uuid_1 = require("uuid");
12
11
  class qase {
13
- }
14
- exports.qase = qase;
15
- _a = qase;
16
- qase._qaseID = '';
17
- qase._qaseTitle = '';
18
- qase._qaseFields = '';
19
- qase._qaseParameters = '';
20
- qase._qaseGroupParameters = '';
21
- qase._qaseIgnore = '';
22
- /**
23
- * Set a Qase ID for the test case
24
- * Don't forget to call `create` method after setting all the necessary parameters
25
- * @param {number | number[]} value
26
- * @example
27
- * const q = qase.id(1).create();
28
- * test.meta(q)('Test case title', async t => { ... });
29
- * or
30
- * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
31
- */
32
- qase.id = (value) => {
33
- _a._qaseID = Array.isArray(value) ? value.join(',') : String(value);
34
- return _a;
35
- };
36
- /**
37
- * Set a title for the test case
38
- * Don't forget to call `create` method after setting all the necessary parameters
39
- * @param {string} value
40
- * @example
41
- * const q = qase.title('Test case title').create();
42
- * test.meta(q)('Test case title', async t => { ... });
43
- * or
44
- * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
45
- */
46
- qase.title = (value) => {
47
- _a._qaseTitle = value;
48
- return _a;
49
- };
50
- /**
51
- * Set a fields for the test case
52
- * Don't forget to call `create` method after setting all the necessary parameters
53
- * @param {Record<string, string>} values
54
- * @example
55
- * const q = qase.fields({ 'severity': 'high', 'priority': 'medium' }).create();
56
- * test.meta(q)('Test case title', async t => { ... });
57
- * or
58
- * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
59
- */
60
- qase.fields = (values) => {
61
- _a._qaseFields = _a.toNormalizeRecord(values);
62
- return _a;
63
- };
64
- /**
65
- * Set a parameters for the test case
66
- * Don't forget to call `create` method after setting all the necessary parameters
67
- * @param {Record<string, string>} values
68
- * @example
69
- * const q = qase.parameters({ 'severity': 'high', 'priority': 'medium' }).create();
70
- * test.meta(q)('Test case title', async t => { ... });
71
- * or
72
- * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
73
- */
74
- qase.parameters = (values) => {
75
- _a._qaseParameters = _a.toNormalizeRecord(values);
76
- return _a;
77
- };
78
- /**
79
- * Set a group parameters for the test case
80
- * Don't forget to call `create` method after setting all the necessary parameters
81
- * @param {Record<string, string>} values
82
- * @example
83
- * const q = qase.groupParameters({ 'severity': 'high', 'priority': 'medium' }).create();
84
- * test.meta(q)('Test case title', async t => { ... });
85
- * or
86
- * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
87
- */
88
- qase.groupParameters = (values) => {
89
- _a._qaseGroupParameters = _a.toNormalizeRecord(values);
90
- return _a;
91
- };
92
- /**
93
- * Set a ignore flag for the test case
94
- * Don't forget to call `create` method after setting all the necessary parameters
95
- * @example
96
- * const q = qase.ignore().create();
97
- * test.meta(q)('Test case title', async t => { ... });
98
- * or
99
- * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
100
- */
101
- qase.ignore = () => {
102
- _a._qaseIgnore = 'true';
103
- return _a;
104
- };
105
- /**
106
- * Add a step to the test case
107
- * @param name
108
- * @param body
109
- * @example
110
- * test.meta({userField: 123, ...q})('Test case title', async t => {
111
- * await qase.step("Step", () => {
112
- * expect(true).toBe(true);
113
- * });
114
- * expect(true).toBe(true);
115
- * });
116
- */
117
- qase.step = async (name, body) => {
118
- const runningStep = new qase_javascript_commons_1.QaseStep(name);
119
- // eslint-disable-next-line @typescript-eslint/require-await
120
- await runningStep.run(body, async (step) => global.Qase.step(step));
121
- };
122
- /**
123
- * Add an attachment to the test case
124
- * @param attach
125
- * @example
126
- * test.meta({userField: 123, ...q})('Test case title', async t => {
127
- * qase.attach({ name: 'attachment.txt', content: 'Hello, world!', type: 'text/plain' });
128
- * qase.attach({ paths: ['/path/to/file', '/path/to/another/file']});
129
- * expect(true).toBe(true);
130
- * });
131
- */
132
- qase.attach = (attach) => {
133
- if (attach.paths) {
134
- for (const file of attach.paths) {
135
- const attachmentName = path_1.default.basename(file);
136
- const contentType = (0, qase_javascript_commons_1.getMimeTypes)(file);
12
+ static _qaseID = '';
13
+ static _qaseTitle = '';
14
+ static _qaseFields = '';
15
+ static _qaseParameters = '';
16
+ static _qaseGroupParameters = '';
17
+ static _qaseIgnore = '';
18
+ /**
19
+ * Set a Qase ID for the test case
20
+ * Don't forget to call `create` method after setting all the necessary parameters
21
+ * @param {number | number[]} value
22
+ * @example
23
+ * const q = qase.id(1).create();
24
+ * test.meta(q)('Test case title', async t => { ... });
25
+ * or
26
+ * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
27
+ */
28
+ static id = (value) => {
29
+ this._qaseID = Array.isArray(value) ? value.join(',') : String(value);
30
+ return this;
31
+ };
32
+ /**
33
+ * Set a title for the test case
34
+ * Don't forget to call `create` method after setting all the necessary parameters
35
+ * @param {string} value
36
+ * @example
37
+ * const q = qase.title('Test case title').create();
38
+ * test.meta(q)('Test case title', async t => { ... });
39
+ * or
40
+ * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
41
+ */
42
+ static title = (value) => {
43
+ this._qaseTitle = value;
44
+ return this;
45
+ };
46
+ /**
47
+ * Set a fields for the test case
48
+ * Don't forget to call `create` method after setting all the necessary parameters
49
+ * @param {Record<string, string>} values
50
+ * @example
51
+ * const q = qase.fields({ 'severity': 'high', 'priority': 'medium' }).create();
52
+ * test.meta(q)('Test case title', async t => { ... });
53
+ * or
54
+ * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
55
+ */
56
+ static fields = (values) => {
57
+ this._qaseFields = this.toNormalizeRecord(values);
58
+ return this;
59
+ };
60
+ /**
61
+ * Set a parameters for the test case
62
+ * Don't forget to call `create` method after setting all the necessary parameters
63
+ * @param {Record<string, string>} values
64
+ * @example
65
+ * const q = qase.parameters({ 'severity': 'high', 'priority': 'medium' }).create();
66
+ * test.meta(q)('Test case title', async t => { ... });
67
+ * or
68
+ * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
69
+ */
70
+ static parameters = (values) => {
71
+ this._qaseParameters = this.toNormalizeRecord(values);
72
+ return this;
73
+ };
74
+ /**
75
+ * Set a group parameters for the test case
76
+ * Don't forget to call `create` method after setting all the necessary parameters
77
+ * @param {Record<string, string>} values
78
+ * @example
79
+ * const q = qase.groupParameters({ 'severity': 'high', 'priority': 'medium' }).create();
80
+ * test.meta(q)('Test case title', async t => { ... });
81
+ * or
82
+ * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
83
+ */
84
+ static groupParameters = (values) => {
85
+ this._qaseGroupParameters = this.toNormalizeRecord(values);
86
+ return this;
87
+ };
88
+ /**
89
+ * Set a ignore flag for the test case
90
+ * Don't forget to call `create` method after setting all the necessary parameters
91
+ * @example
92
+ * const q = qase.ignore().create();
93
+ * test.meta(q)('Test case title', async t => { ... });
94
+ * or
95
+ * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
96
+ */
97
+ static ignore = () => {
98
+ this._qaseIgnore = 'true';
99
+ return this;
100
+ };
101
+ /**
102
+ * Add a step to the test case
103
+ * @param name
104
+ * @param body
105
+ * @example
106
+ * test.meta({userField: 123, ...q})('Test case title', async t => {
107
+ * await qase.step("Step", () => {
108
+ * expect(true).toBe(true);
109
+ * });
110
+ * expect(true).toBe(true);
111
+ * });
112
+ */
113
+ static step = async (name, body) => {
114
+ const runningStep = new qase_javascript_commons_1.QaseStep(name);
115
+ // eslint-disable-next-line @typescript-eslint/require-await
116
+ await runningStep.run(body, async (step) => global.Qase.step(step));
117
+ };
118
+ /**
119
+ * Add an attachment to the test case
120
+ * @param attach
121
+ * @example
122
+ * test.meta({userField: 123, ...q})('Test case title', async t => {
123
+ * qase.attach({ name: 'attachment.txt', content: 'Hello, world!', type: 'text/plain' });
124
+ * qase.attach({ paths: ['/path/to/file', '/path/to/another/file']});
125
+ * expect(true).toBe(true);
126
+ * });
127
+ */
128
+ static attach = (attach) => {
129
+ if (attach.paths) {
130
+ for (const file of attach.paths) {
131
+ const attachmentName = path_1.default.basename(file);
132
+ const contentType = (0, qase_javascript_commons_1.getMimeTypes)(file);
133
+ global.Qase.attachment({
134
+ file_path: file,
135
+ size: 0,
136
+ id: (0, uuid_1.v4)(),
137
+ file_name: attachmentName,
138
+ mime_type: contentType,
139
+ content: '',
140
+ });
141
+ }
142
+ return;
143
+ }
144
+ if (attach.content) {
137
145
  global.Qase.attachment({
138
- file_path: file,
139
- size: 0,
146
+ file_path: null,
147
+ size: attach.content.length,
140
148
  id: (0, uuid_1.v4)(),
141
- file_name: attachmentName,
142
- mime_type: contentType,
143
- content: '',
149
+ file_name: attach.name ?? 'attachment',
150
+ mime_type: attach.type ?? 'application/octet-stream',
151
+ content: attach.content,
144
152
  });
145
153
  }
146
- return;
147
- }
148
- if (attach.content) {
149
- global.Qase.attachment({
150
- file_path: null,
151
- size: attach.content.length,
152
- id: (0, uuid_1.v4)(),
153
- file_name: attach.name ?? 'attachment',
154
- mime_type: attach.type ?? 'application/octet-stream',
155
- content: attach.content,
156
- });
157
- }
158
- };
159
- /**
160
- * Create a Qase metadata
161
- * Call this method after setting all the necessary parameters
162
- * @example
163
- * const q = qase.id(1).title('Test case title').fields({ 'severity': 'high', 'priority': 'medium' }).create();
164
- * test.meta(q)('Test case title', async t => { ... });
165
- * or
166
- * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
167
- */
168
- qase.create = () => {
169
- const meta = {
170
- QaseID: _a._qaseID,
171
- QaseTitle: _a._qaseTitle,
172
- QaseFields: _a._qaseFields,
173
- QaseParameters: _a._qaseParameters,
174
- QaseGroupParameters: _a._qaseGroupParameters,
175
- QaseIgnore: _a._qaseIgnore,
176
154
  };
177
- _a._qaseID = '';
178
- _a._qaseTitle = '';
179
- _a._qaseFields = '';
180
- _a._qaseParameters = '';
181
- _a._qaseGroupParameters = '';
182
- _a._qaseIgnore = '';
183
- return meta;
184
- };
185
- qase.toNormalizeRecord = (record) => {
186
- const stringRecord = {};
187
- for (const [key, value] of Object.entries(record)) {
188
- stringRecord[String(key)] = String(value);
189
- }
190
- return JSON.stringify(stringRecord);
191
- };
155
+ /**
156
+ * Create a Qase metadata
157
+ * Call this method after setting all the necessary parameters
158
+ * @example
159
+ * const q = qase.id(1).title('Test case title').fields({ 'severity': 'high', 'priority': 'medium' }).create();
160
+ * test.meta(q)('Test case title', async t => { ... });
161
+ * or
162
+ * test.meta({userField: 123, ...q})('Test case title', async t => { ... });
163
+ */
164
+ static create = () => {
165
+ const meta = {
166
+ QaseID: this._qaseID,
167
+ QaseTitle: this._qaseTitle,
168
+ QaseFields: this._qaseFields,
169
+ QaseParameters: this._qaseParameters,
170
+ QaseGroupParameters: this._qaseGroupParameters,
171
+ QaseIgnore: this._qaseIgnore,
172
+ };
173
+ this._qaseID = '';
174
+ this._qaseTitle = '';
175
+ this._qaseFields = '';
176
+ this._qaseParameters = '';
177
+ this._qaseGroupParameters = '';
178
+ this._qaseIgnore = '';
179
+ return meta;
180
+ };
181
+ static toNormalizeRecord = (record) => {
182
+ const stringRecord = {};
183
+ for (const [key, value] of Object.entries(record)) {
184
+ stringRecord[String(key)] = String(value);
185
+ }
186
+ return JSON.stringify(stringRecord);
187
+ };
188
+ }
189
+ exports.qase = qase;
@@ -67,6 +67,7 @@ export declare class TestcafeQaseReporter {
67
67
  private reporter;
68
68
  private steps;
69
69
  private attachments;
70
+ private testBeginTime;
70
71
  /**
71
72
  * @param {TestcafeQaseOptionsType} options
72
73
  * @param {ConfigLoaderInterface} configLoader
package/dist/reporter.js CHANGED
@@ -51,81 +51,19 @@ class TestcafeQaseReporter {
51
51
  }
52
52
  return attachments;
53
53
  }
54
+ /**
55
+ * @type {ReporterInterface}
56
+ * @private
57
+ */
58
+ reporter;
59
+ steps = [];
60
+ attachments = [];
61
+ testBeginTime = Date.now();
54
62
  /**
55
63
  * @param {TestcafeQaseOptionsType} options
56
64
  * @param {ConfigLoaderInterface} configLoader
57
65
  */
58
66
  constructor(options, configLoader = new qase_javascript_commons_1.ConfigLoader()) {
59
- this.steps = [];
60
- this.attachments = [];
61
- /**
62
- * @returns {Promise<void>}
63
- */
64
- this.startTestRun = () => {
65
- this.reporter.startTestRun();
66
- };
67
- this.reportTestStart = () => {
68
- this.steps = [];
69
- this.attachments = [];
70
- };
71
- /**
72
- * @param {string} title
73
- * @param {TestRunInfoType} testRunInfo
74
- * @param {Record<string, string>} meta
75
- * @param formatError
76
- */
77
- this.reportTestDone = async (title, testRunInfo, meta, formatError) => {
78
- const metadata = this.getMeta(meta);
79
- if (metadata[metadataEnum.ignore]) {
80
- return;
81
- }
82
- const errorLog = testRunInfo.errs
83
- .map((error, index) => formatError(error, `${index + 1} `).replace(
84
- // eslint-disable-next-line no-control-regex
85
- /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''))
86
- .join('\n');
87
- const attachments = TestcafeQaseReporter.transformAttachments(testRunInfo.screenshots);
88
- attachments.push(...this.attachments);
89
- await this.reporter.addTestResult({
90
- author: null,
91
- execution: {
92
- status: TestcafeQaseReporter.getStatus(testRunInfo),
93
- start_time: null,
94
- end_time: null,
95
- duration: testRunInfo.durationMs,
96
- stacktrace: errorLog,
97
- thread: null,
98
- },
99
- fields: metadata[metadataEnum.fields],
100
- message: errorLog ? errorLog.split('\n')[0] ?? '' : '',
101
- muted: false,
102
- params: metadata[metadataEnum.parameters],
103
- group_params: metadata[metadataEnum.groupParameters],
104
- relations: {
105
- suite: {
106
- data: [
107
- {
108
- title: testRunInfo.fixture.name,
109
- public_id: null,
110
- },
111
- ],
112
- },
113
- },
114
- run_id: null,
115
- signature: this.getSignature(testRunInfo.fixture, title, metadata[metadataEnum.id], metadata[metadataEnum.parameters]),
116
- steps: this.steps,
117
- id: (0, uuid_1.v4)(),
118
- testops_id: metadata[metadataEnum.id].length > 0 ? metadata[metadataEnum.id] : null,
119
- title: metadata[metadataEnum.title] != undefined ? metadata[metadataEnum.title] : title,
120
- attachments: attachments,
121
- });
122
- };
123
- /**
124
- * @returns {Promise<void>}
125
- */
126
- this.reportTaskDone = async () => {
127
- await this.reporter.publish();
128
- };
129
67
  const config = configLoader.load();
130
68
  this.reporter = qase_javascript_commons_1.QaseReporter.getInstance({
131
69
  ...(0, qase_javascript_commons_1.composeOptions)(options, config),
@@ -141,6 +79,75 @@ class TestcafeQaseReporter {
141
79
  addAttachment(attachment) {
142
80
  this.attachments.push(attachment);
143
81
  }
82
+ /**
83
+ * @returns {Promise<void>}
84
+ */
85
+ startTestRun = () => {
86
+ this.reporter.startTestRun();
87
+ };
88
+ reportTestStart = () => {
89
+ this.steps = [];
90
+ this.attachments = [];
91
+ this.testBeginTime = Date.now();
92
+ };
93
+ /**
94
+ * @param {string} title
95
+ * @param {TestRunInfoType} testRunInfo
96
+ * @param {Record<string, string>} meta
97
+ * @param formatError
98
+ */
99
+ reportTestDone = async (title, testRunInfo, meta, formatError) => {
100
+ const metadata = this.getMeta(meta);
101
+ if (metadata[metadataEnum.ignore]) {
102
+ return;
103
+ }
104
+ const errorLog = testRunInfo.errs
105
+ .map((error, index) => formatError(error, `${index + 1} `).replace(
106
+ // eslint-disable-next-line no-control-regex
107
+ /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''))
108
+ .join('\n');
109
+ const attachments = TestcafeQaseReporter.transformAttachments(testRunInfo.screenshots);
110
+ attachments.push(...this.attachments);
111
+ await this.reporter.addTestResult({
112
+ author: null,
113
+ execution: {
114
+ status: TestcafeQaseReporter.getStatus(testRunInfo),
115
+ start_time: this.testBeginTime / 1000,
116
+ end_time: (this.testBeginTime + testRunInfo.durationMs) / 1000,
117
+ duration: testRunInfo.durationMs,
118
+ stacktrace: errorLog,
119
+ thread: null,
120
+ },
121
+ fields: metadata[metadataEnum.fields],
122
+ message: errorLog ? errorLog.split('\n')[0] ?? '' : '',
123
+ muted: false,
124
+ params: metadata[metadataEnum.parameters],
125
+ group_params: metadata[metadataEnum.groupParameters],
126
+ relations: {
127
+ suite: {
128
+ data: [
129
+ {
130
+ title: testRunInfo.fixture.name,
131
+ public_id: null,
132
+ },
133
+ ],
134
+ },
135
+ },
136
+ run_id: null,
137
+ signature: this.getSignature(testRunInfo.fixture, title, metadata[metadataEnum.id], metadata[metadataEnum.parameters]),
138
+ steps: this.steps,
139
+ id: (0, uuid_1.v4)(),
140
+ testops_id: metadata[metadataEnum.id].length > 0 ? metadata[metadataEnum.id] : null,
141
+ title: metadata[metadataEnum.title] != undefined ? metadata[metadataEnum.title] : title,
142
+ attachments: attachments,
143
+ });
144
+ };
145
+ /**
146
+ * @returns {Promise<void>}
147
+ */
148
+ reportTaskDone = async () => {
149
+ await this.reporter.publish();
150
+ };
144
151
  getMeta(meta) {
145
152
  const metadata = {
146
153
  QaseID: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testcafe-reporter-qase",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Qase TMS TestCafe Reporter",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "author": "Qase Team <support@qase.io>",
41
41
  "license": "Apache-2.0",
42
42
  "dependencies": {
43
- "qase-javascript-commons": "~2.2.4",
43
+ "qase-javascript-commons": "~2.2.14",
44
44
  "uuid": "^9.0.0"
45
45
  },
46
46
  "peerDependencies": {