jest-qase-reporter 2.1.2 → 2.1.4

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,16 @@
1
+ # jest-qase-reporter@2.1.4
2
+
3
+ ## What's new
4
+
5
+ - Added support for expected results and data for steps.
6
+
7
+ # jest-qase-reporter@2.1.3
8
+
9
+ ## What's new
10
+
11
+ - Added support for status filter in the test run.
12
+ - Improved error handling.
13
+
1
14
  # jest-qase-reporter@2.1.0
2
15
 
3
16
  ## What's new
package/dist/jest.d.ts CHANGED
@@ -1,98 +1,14 @@
1
1
  import { StepFunction } from 'qase-javascript-commons';
2
2
  export declare const qase: {
3
3
  (caseId: number | string | number[] | string[], name: string): string;
4
- /**
5
- * Set a title for the test case
6
- * @param {string} value
7
- * @example
8
- * test('test', () => {
9
- * qase.title("Title");
10
- * expect(true).toBe(true);
11
- * });
12
- */
13
4
  title(value: string): void;
14
- /**
15
- * Ignore the test case
16
- * @example
17
- * test('test', () => {
18
- * qase.ignore();
19
- * expect(true).toBe(true);
20
- * });
21
- */
22
5
  ignore(): void;
23
- /**
24
- * Add a comment to the test case
25
- * @param {string} value
26
- * @example
27
- * test('test', () => {
28
- * qase.comment("Comment");
29
- * expect(true).toBe(true);
30
- * });
31
- */
32
6
  comment(value: string): void;
33
- /**
34
- * Set a suite for the test case
35
- * @param {string} value
36
- * @example
37
- * test('test', () => {
38
- * qase.suite("Suite");
39
- * expect(true).toBe(true);
40
- * });
41
- */
42
7
  suite(value: string): void;
43
- /**
44
- * Set fields for the test case
45
- * @param {Record<string, string>} values
46
- * @example
47
- * test('test', () => {
48
- * qase.fields({field: "value"});
49
- * expect(true).toBe(true);
50
- * });
51
- */
52
8
  fields(values: Record<string, string>): void;
53
- /**
54
- * Set parameters for the test case
55
- * @param {Record<string, string>} values
56
- * @example
57
- * test('test', () => {
58
- * qase.parameters({param: "value"});
59
- * expect(true).toBe(true);
60
- * });
61
- */
62
9
  parameters(values: Record<string, string>): void;
63
- /**
64
- * Set group params for the test case
65
- * @param {Record<string, string>} values
66
- * @example
67
- * test('test', () => {
68
- * qase.groupParameters({param: "value"});
69
- * expect(true).toBe(true);
70
- * });
71
- */
72
10
  groupParameters(values: Record<string, string>): void;
73
- /**
74
- * Add a step to the test case
75
- * @param name
76
- * @param body
77
- * @example
78
- * test('test', () => {
79
- * qase.step("Step", () => {
80
- * expect(true).toBe(true);
81
- * });
82
- * expect(true).toBe(true);
83
- * });
84
- */
85
- step(name: string, body: StepFunction): Promise<void>;
86
- /**
87
- * Add an attachment to the test case
88
- * @param attach
89
- * @example
90
- * test('test', () => {
91
- * qase.attach({ name: 'attachment.txt', content: 'Hello, world!', type: 'text/plain' });
92
- * qase.attach({ paths: ['/path/to/file', '/path/to/another/file']});
93
- * expect(true).toBe(true);
94
- * });
95
- */
11
+ step(name: string, body: StepFunction, expectedResult?: string, data?: string): Promise<void>;
96
12
  attach(attach: {
97
13
  name?: string;
98
14
  type?: string;
package/dist/jest.js CHANGED
@@ -22,6 +22,8 @@ exports.qase = qase;
22
22
  * });
23
23
  */
24
24
  exports.qase.title = (value) => {
25
+ // @ts-expect-error - global.Qase is dynamically added at runtime
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
25
27
  global.Qase.title(value);
26
28
  };
27
29
  /**
@@ -33,6 +35,8 @@ exports.qase.title = (value) => {
33
35
  * });
34
36
  */
35
37
  exports.qase.ignore = () => {
38
+ // @ts-expect-error - global.Qase is dynamically added at runtime
39
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
36
40
  global.Qase.ignore();
37
41
  };
38
42
  /**
@@ -45,6 +49,8 @@ exports.qase.ignore = () => {
45
49
  * });
46
50
  */
47
51
  exports.qase.comment = (value) => {
52
+ // @ts-expect-error - global.Qase is dynamically added at runtime
53
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
48
54
  global.Qase.comment(value);
49
55
  };
50
56
  /**
@@ -57,6 +63,8 @@ exports.qase.comment = (value) => {
57
63
  * });
58
64
  */
59
65
  exports.qase.suite = (value) => {
66
+ // @ts-expect-error - global.Qase is dynamically added at runtime
67
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
60
68
  global.Qase.suite(value);
61
69
  };
62
70
  /**
@@ -69,6 +77,8 @@ exports.qase.suite = (value) => {
69
77
  * });
70
78
  */
71
79
  exports.qase.fields = (values) => {
80
+ // @ts-expect-error - global.Qase is dynamically added at runtime
81
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
72
82
  global.Qase.fields(values);
73
83
  };
74
84
  /**
@@ -81,6 +91,8 @@ exports.qase.fields = (values) => {
81
91
  * });
82
92
  */
83
93
  exports.qase.parameters = (values) => {
94
+ // @ts-expect-error - global.Qase is dynamically added at runtime
95
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
84
96
  global.Qase.parameters(values);
85
97
  };
86
98
  /**
@@ -93,12 +105,16 @@ exports.qase.parameters = (values) => {
93
105
  * });
94
106
  */
95
107
  exports.qase.groupParameters = (values) => {
108
+ // @ts-expect-error - global.Qase is dynamically added at runtime
109
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
96
110
  global.Qase.groupParams(values);
97
111
  };
98
112
  /**
99
113
  * Add a step to the test case
100
114
  * @param name
101
115
  * @param body
116
+ * @param expectedResult
117
+ * @param data
102
118
  * @example
103
119
  * test('test', () => {
104
120
  * qase.step("Step", () => {
@@ -106,11 +122,25 @@ exports.qase.groupParameters = (values) => {
106
122
  * });
107
123
  * expect(true).toBe(true);
108
124
  * });
125
+ * @example
126
+ * test('test', () => {
127
+ * qase.step("Step", () => {
128
+ * expect(true).toBe(true);
129
+ * }, "Expected result", "Input data");
130
+ * expect(true).toBe(true);
131
+ * });
109
132
  */
110
- exports.qase.step = async (name, body) => {
111
- const runningStep = new qase_javascript_commons_1.QaseStep(name);
133
+ exports.qase.step = async (name, body, expectedResult, data) => {
134
+ const stepName = expectedResult || data
135
+ ? `${name} QaseExpRes:${expectedResult ? `: ${expectedResult}` : ''} QaseData:${data ? `: ${data}` : ''}`
136
+ : name;
137
+ const runningStep = new qase_javascript_commons_1.QaseStep(stepName);
112
138
  // eslint-disable-next-line @typescript-eslint/require-await
113
- await runningStep.run(body, async (step) => global.Qase.step(step));
139
+ await runningStep.run(body, async (step) => {
140
+ // @ts-expect-error - global.Qase is dynamically added at runtime
141
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return
142
+ return global.Qase.step(step);
143
+ });
114
144
  };
115
145
  /**
116
146
  * Add an attachment to the test case
@@ -127,6 +157,8 @@ exports.qase.attach = (attach) => {
127
157
  for (const file of attach.paths) {
128
158
  const attachmentName = path_1.default.basename(file);
129
159
  const contentType = (0, qase_javascript_commons_1.getMimeTypes)(file);
160
+ // @ts-expect-error - global.Qase is dynamically added at runtime
161
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
130
162
  global.Qase.attachment({
131
163
  file_path: file,
132
164
  size: 0,
@@ -139,6 +171,8 @@ exports.qase.attach = (attach) => {
139
171
  return;
140
172
  }
141
173
  if (attach.content) {
174
+ // @ts-expect-error - global.Qase is dynamically added at runtime
175
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
142
176
  global.Qase.attachment({
143
177
  file_path: null,
144
178
  size: attach.content.length,
@@ -103,5 +103,12 @@ export declare class JestQaseReporter implements Reporter {
103
103
  * @private
104
104
  */
105
105
  private removeQaseIdsFromTitle;
106
+ /**
107
+ * Extract expected result and data from step title and return cleaned string
108
+ * @param {string} input
109
+ * @returns {{expectedResult: string | null, data: string | null, cleanedString: string}}
110
+ * @private
111
+ */
112
+ private extractAndCleanStep;
106
113
  onRunnerEnd(): Promise<void>;
107
114
  }
package/dist/reporter.js CHANGED
@@ -63,6 +63,7 @@ class JestQaseReporter {
63
63
  frameworkName: 'jest',
64
64
  reporterName: 'jest-qase-reporter',
65
65
  });
66
+ // @ts-expect-error - global.Qase is dynamically added at runtime
66
67
  global.Qase = new global_1.Qase(this);
67
68
  this.metadata = this.createEmptyMetadata();
68
69
  }
@@ -208,6 +209,17 @@ class JestQaseReporter {
208
209
  this.metadata.ignore = true;
209
210
  }
210
211
  addStep(step) {
212
+ // Parse expectedResult and data from step name if present
213
+ // Only process text steps (not gherkin steps)
214
+ // Check if step is a text step (either explicitly TEXT type, undefined, or string 'text')
215
+ const isTextStep = (qase_javascript_commons_1.StepType && step.step_type === qase_javascript_commons_1.StepType.TEXT) || step.step_type === undefined || step.step_type === 'text';
216
+ if (isTextStep && step.data && 'action' in step.data) {
217
+ const stepTextData = step.data;
218
+ const stepData = this.extractAndCleanStep(stepTextData.action);
219
+ stepTextData.action = stepData.cleanedString;
220
+ stepTextData.expected_result = stepData.expectedResult;
221
+ stepTextData.data = stepData.data;
222
+ }
211
223
  this.metadata.steps.push(step);
212
224
  }
213
225
  addAttachment(attachment) {
@@ -235,11 +247,13 @@ class JestQaseReporter {
235
247
  }
236
248
  const ids = JestQaseReporter.getCaseId(value.title);
237
249
  const filePath = this.getCurrentTestPath(path);
250
+ // Determine status based on error type
251
+ const testStatus = (0, qase_javascript_commons_1.determineTestStatus)(error ?? null, value.status);
238
252
  return {
239
253
  attachments: [],
240
254
  author: null,
241
255
  execution: {
242
- status: JestQaseReporter.statusMap[value.status],
256
+ status: testStatus,
243
257
  start_time: null,
244
258
  end_time: null,
245
259
  duration: value.duration ?? 0,
@@ -289,6 +303,32 @@ class JestQaseReporter {
289
303
  }
290
304
  return title;
291
305
  }
306
+ /**
307
+ * Extract expected result and data from step title and return cleaned string
308
+ * @param {string} input
309
+ * @returns {{expectedResult: string | null, data: string | null, cleanedString: string}}
310
+ * @private
311
+ */
312
+ extractAndCleanStep(input) {
313
+ let expectedResult = null;
314
+ let data = null;
315
+ let cleanedString = input;
316
+ const hasExpectedResult = input.includes('QaseExpRes:');
317
+ const hasData = input.includes('QaseData:');
318
+ if (hasExpectedResult || hasData) {
319
+ const regex = /QaseExpRes:\s*:?\s*(.*?)\s*(?=QaseData:|$)QaseData:\s*:?\s*(.*)?/;
320
+ const match = input.match(regex);
321
+ if (match) {
322
+ expectedResult = match[1]?.trim() ?? null;
323
+ data = match[2]?.trim() ?? null;
324
+ cleanedString = input
325
+ .replace(/QaseExpRes:\s*:?\s*.*?(?=QaseData:|$)/, '')
326
+ .replace(/QaseData:\s*:?\s*.*/, '')
327
+ .trim();
328
+ }
329
+ }
330
+ return { expectedResult, data, cleanedString };
331
+ }
292
332
  async onRunnerEnd() {
293
333
  await this.reporter.publish();
294
334
  }
package/docs/usage.md CHANGED
@@ -65,19 +65,37 @@ The reporter uses the title from the `test.step` function as the step title. By
65
65
  Additionally, these steps get their own result in the Qase Test run, offering a well-organized summary of the test flow. This helps quickly identify the cause of any failures.
66
66
 
67
67
  ```javascript
68
+ const { qase } = require("jest-qase-reporter/jest");
69
+
68
70
  test('A Test case with steps, updated from code', async () => {
69
- await test.step('Initialize the environment', async () => {
71
+ await qase.step('Initialize the environment', async () => {
70
72
  // Set up test environment
71
73
  });
72
- await test.step('Test Core Functionality of the app', async () => {
74
+ await qase.step('Test Core Functionality of the app', async () => {
73
75
  // Exercise core functionality
74
76
  });
75
77
 
76
- await test.step('Verify Expected Behavior of the app', async () => {
78
+ await qase.step('Verify Expected Behavior of the app', async () => {
77
79
  // Assert expected behavior
78
80
  });
79
81
  });
80
82
  ```
83
+
84
+ #### Steps with Expected Result and Data
85
+
86
+ ```javascript
87
+ const { qase } = require("jest-qase-reporter/jest");
88
+
89
+ test('A Test case with steps including expected results and data', async () => {
90
+ await qase.step('Click button', async () => {
91
+ // Click action
92
+ }, 'Button should be clicked', 'Button data');
93
+
94
+ await qase.step('Fill form', async () => {
95
+ // Form filling action
96
+ }, 'Form should be filled', 'Form input data');
97
+ });
98
+ ```
81
99
  <br>
82
100
 
83
101
  ### Fields
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-qase-reporter",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "Qase TMS Jest Reporter",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -45,18 +45,18 @@
45
45
  "dependencies": {
46
46
  "lodash.get": "^4.4.2",
47
47
  "lodash.has": "^4.5.2",
48
- "qase-javascript-commons": "~2.4.1",
49
- "uuid": "^9.0.0"
48
+ "qase-javascript-commons": "~2.4.13",
49
+ "uuid": "^9.0.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@jest/globals": "^29.5.0",
53
- "@jest/reporters": "^29.5.0",
54
- "@jest/test-result": "^29.5.0",
55
- "@types/jest": "^29.5.2",
56
- "@types/lodash.get": "^4.4.7",
57
- "@types/lodash.has": "^4.5.7",
58
- "jest": "^29.5.0",
59
- "ts-jest": "^29.1.0"
52
+ "@jest/globals": "^29.7.0",
53
+ "@jest/reporters": "^29.7.0",
54
+ "@jest/test-result": "^29.7.0",
55
+ "@types/jest": "^29.5.14",
56
+ "@types/lodash.get": "^4.4.9",
57
+ "@types/lodash.has": "^4.5.9",
58
+ "jest": "^29.7.0",
59
+ "ts-jest": "^29.4.5"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "jest": ">=28.0.0"
@@ -2,7 +2,9 @@
2
2
  "extends": "./tsconfig.json",
3
3
 
4
4
  "compilerOptions": {
5
- "noEmit": false
5
+ "noEmit": false,
6
+ "skipLibCheck": true,
7
+ "types": []
6
8
  },
7
9
 
8
10
  "include": ["./src/**/*.ts"]