artes 1.2.24 → 1.2.26

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.
@@ -60,11 +60,13 @@ module.exports = {
60
60
  timeout: process.env.TIMEOUT
61
61
  ? Number(process.env.TIMEOUT) * 1000
62
62
  : artesConfig.timeout * 1000 || 30 * 1000, // Default timeout in seconds
63
- paths: process.env.FEATURES
64
- ? [path.join(moduleConfig.projectPath, process.env.FEATURES)]
65
- : artesConfig.features
66
- ? path.join(moduleConfig.projectPath, artesConfig.features)
67
- : [moduleConfig.featuresPath], // Paths to feature files
63
+ paths: process.env.RERUN
64
+ ? [`${path.join("../../", process.env.RERUN)}`]
65
+ : process.env.FEATURES
66
+ ? [path.join(moduleConfig.projectPath, process.env.FEATURES)]
67
+ : artesConfig.features
68
+ ? [path.join(moduleConfig.projectPath, artesConfig.features)]
69
+ : [moduleConfig.featuresPath], // Paths to feature files
68
70
  require: [
69
71
  process.env.STEP_DEFINITIONS
70
72
  ? [path.join(moduleConfig.projectPath, process.env.STEP_DEFINITIONS)]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "artes",
3
- "version": "1.2.24",
3
+ "version": "1.2.26",
4
4
  "description": "The simplest way to automate UI and API tests using Cucumber-style steps.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,15 +5,10 @@ const path = require("path");
5
5
  function runTests() {
6
6
  try {
7
7
  console.log("🧪 Running tests...");
8
- process.env.FORCE_COLOR = "1";
9
- process.env.FORCE_STDIO_TTY = "1";
10
8
 
11
9
  spawnSync(
12
10
  "cucumber-js",
13
- [
14
- "--config=cucumber.config.js",
15
- `${process.env.RERUN ? path.join("../../", process.env.RERUN) : ""}`,
16
- ],
11
+ [ "--config=cucumber.config.js"],
17
12
  {
18
13
  cwd: moduleConfig.modulePath,
19
14
  stdio: "inherit",
@@ -35,7 +35,7 @@ const moduleConfig = {
35
35
  stepsPath: path.join(projectPath, "/tests/steps/*.js"),
36
36
  pomPath: path.join(projectPath, "/tests/POMs"),
37
37
  cleanUpPaths:
38
- "allure-result allure-results test-results testsStatus EXIT_CODE.txt",
38
+ "allure-result allure-results test-results @rerun.txt testsStatus EXIT_CODE.txt",
39
39
  };
40
40
 
41
41
  module.exports = {
@@ -28,6 +28,58 @@ function getMimeType(filePath) {
28
28
  return mimeTypes[ext] || "application/octet-stream";
29
29
  }
30
30
 
31
+ function curlExtractor(url, method, headers, body, requestDataType) {
32
+ let curlCommand = `curl -X ${method} '${url}'`;
33
+
34
+ if (headers && Object.keys(headers).length > 0) {
35
+ for (const [key, value] of Object.entries(headers)) {
36
+ curlCommand += ` \\\n -H '${key}: ${value}'`;
37
+ }
38
+ }
39
+
40
+ if (body && Object.keys(body).length > 0) {
41
+ switch (requestDataType) {
42
+ case "multipart":
43
+ for (const [key, value] of Object.entries(body)) {
44
+ if (typeof value === "object" && value.buffer) {
45
+ curlCommand += ` \\\n -F '${key}=@${value.name}'`;
46
+ } else {
47
+ curlCommand += ` \\\n -F '${key}=${value}'`;
48
+ }
49
+ }
50
+ break;
51
+
52
+ case "urlencoded":
53
+ case "application/x-www-form-urlencoded":
54
+ const urlEncodedData = new URLSearchParams(body).toString();
55
+ curlCommand += ` \\\n --data-urlencode '${urlEncodedData}'`;
56
+ break;
57
+
58
+ case "form":
59
+ for (const [key, value] of Object.entries(body)) {
60
+ curlCommand += ` \\\n -F '${key}=${value}'`;
61
+ }
62
+ break;
63
+
64
+ default:
65
+ const hasContentType =
66
+ headers &&
67
+ Object.keys(headers).some(
68
+ (key) => key.toLowerCase() === "content-type",
69
+ );
70
+
71
+ if (!hasContentType) {
72
+ curlCommand += ` \\\n -H 'Content-Type: application/json'`;
73
+ }
74
+
75
+ curlCommand += ` \\\n --data-raw '${JSON.stringify(body)}'`;
76
+ break;
77
+ }
78
+ }
79
+
80
+ return curlCommand;
81
+ }
82
+
31
83
  function processForm(requestBody) {
32
84
  let formData = {};
33
85
  for (const [key, value] of Object.entries(requestBody)) {
@@ -108,7 +160,7 @@ async function requestMaker(headers, data, requestDataType) {
108
160
  return request;
109
161
  }
110
162
 
111
- async function responseMaker(request, response, duration) {
163
+ async function responseMaker(request, response, duration, curlCommand) {
112
164
  const responseObject = {};
113
165
 
114
166
  response &&
@@ -139,6 +191,8 @@ async function responseMaker(request, response, duration) {
139
191
  }
140
192
  }
141
193
 
194
+ curlCommand && Object.assign(responseObject, { "cURL Command": curlCommand });
195
+
142
196
  return responseObject;
143
197
  }
144
198
 
@@ -157,7 +211,15 @@ const api = {
157
211
 
158
212
  const duration = performance.now() - requestStarts;
159
213
 
160
- const response = responseMaker(payloadJSON, res, duration);
214
+ const curlCommand = curlExtractor(
215
+ res.url(),
216
+ "GET",
217
+ payloadJSON?.headers || {},
218
+ null,
219
+ null,
220
+ );
221
+
222
+ const response = responseMaker(payloadJSON, res, duration, curlCommand);
161
223
 
162
224
  context.response = await response;
163
225
  },
@@ -170,7 +232,9 @@ const api = {
170
232
 
171
233
  const duration = performance.now() - requestStarts;
172
234
 
173
- const response = responseMaker(payloadJSON, res, duration);
235
+ const curlCommand = curlExtractor(res.url(), "HEAD", {}, null, null);
236
+
237
+ const response = responseMaker(null, res, duration, curlCommand);
174
238
 
175
239
  context.response = await response;
176
240
  },
@@ -181,6 +245,7 @@ const api = {
181
245
  const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
182
246
 
183
247
  let req;
248
+ let bodyForCurl = payloadJSON?.body || {};
184
249
 
185
250
  switch (requestDataType) {
186
251
  case "multipart":
@@ -191,6 +256,7 @@ const api = {
191
256
  formRequest || {},
192
257
  requestDataType,
193
258
  );
259
+ bodyForCurl = formRequest;
194
260
  break;
195
261
  case "urlencoded":
196
262
  case "application/x-www-form-urlencoded":
@@ -223,7 +289,20 @@ const api = {
223
289
 
224
290
  const duration = performance.now() - requestStarts;
225
291
 
226
- const response = await responseMaker(payloadJSON, res, duration);
292
+ const curlCommand = curlExtractor(
293
+ res.url(),
294
+ "POST",
295
+ req.headers,
296
+ bodyForCurl,
297
+ requestDataType,
298
+ );
299
+
300
+ const response = await responseMaker(
301
+ payloadJSON,
302
+ res,
303
+ duration,
304
+ curlCommand,
305
+ );
227
306
 
228
307
  context.response = response;
229
308
  },
@@ -234,6 +313,7 @@ const api = {
234
313
  const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
235
314
 
236
315
  let req;
316
+ let bodyForCurl = payloadJSON?.body || {};
237
317
 
238
318
  switch (requestDataType) {
239
319
  case "multipart":
@@ -244,6 +324,7 @@ const api = {
244
324
  formRequest || {},
245
325
  requestDataType,
246
326
  );
327
+ bodyForCurl = formRequest;
247
328
  break;
248
329
  case "urlencoded":
249
330
  case "application/x-www-form-urlencoded":
@@ -276,7 +357,20 @@ const api = {
276
357
 
277
358
  const duration = performance.now() - requestStarts;
278
359
 
279
- const response = await responseMaker(payloadJSON, res, duration);
360
+ const curlCommand = curlExtractor(
361
+ res.url(),
362
+ "PUT",
363
+ req.headers,
364
+ bodyForCurl,
365
+ requestDataType,
366
+ );
367
+
368
+ const response = await responseMaker(
369
+ payloadJSON,
370
+ res,
371
+ duration,
372
+ curlCommand,
373
+ );
280
374
 
281
375
  context.response = response;
282
376
  },
@@ -287,6 +381,7 @@ const api = {
287
381
  const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
288
382
 
289
383
  let req;
384
+ let bodyForCurl = payloadJSON?.body || {};
290
385
 
291
386
  switch (requestDataType) {
292
387
  case "multipart":
@@ -297,6 +392,7 @@ const api = {
297
392
  formRequest || {},
298
393
  requestDataType,
299
394
  );
395
+ bodyForCurl = formRequest;
300
396
  break;
301
397
  case "urlencoded":
302
398
  case "application/x-www-form-urlencoded":
@@ -329,7 +425,20 @@ const api = {
329
425
 
330
426
  const duration = performance.now() - requestStarts;
331
427
 
332
- const response = await responseMaker(payloadJSON, res, duration);
428
+ const curlCommand = curlExtractor(
429
+ res.url(),
430
+ "PATCH",
431
+ req.headers,
432
+ bodyForCurl,
433
+ requestDataType,
434
+ );
435
+
436
+ const response = await responseMaker(
437
+ payloadJSON,
438
+ res,
439
+ duration,
440
+ curlCommand,
441
+ );
333
442
 
334
443
  context.response = response;
335
444
  },
@@ -350,7 +459,15 @@ const api = {
350
459
 
351
460
  const duration = performance.now() - requestStarts;
352
461
 
353
- const response = responseMaker(payloadJSON, res, duration);
462
+ const curlCommand = curlExtractor(
463
+ res.url(),
464
+ "DELETE",
465
+ payloadJSON?.headers || {},
466
+ payloadJSON?.body || {},
467
+ null,
468
+ );
469
+
470
+ const response = responseMaker(payloadJSON, res, duration, curlCommand);
354
471
 
355
472
  context.response = await response;
356
473
  },
@@ -144,7 +144,7 @@ After(async function ({ pickle, result }) {
144
144
  const shouldReport =
145
145
  cucumberConfig.default.successReport || result?.status !== Status.PASSED;
146
146
 
147
- if (shouldReport) {
147
+ if (shouldReport & (context.page.url() !== "about:blank")) {
148
148
  const screenshotPath = path.join(
149
149
  "test-results",
150
150
  "visualReport",
@@ -212,7 +212,11 @@ After(async function ({ pickle, result }) {
212
212
  await context.browser?.close();
213
213
  await context.request?.dispose();
214
214
 
215
- if (shouldReport && context.page.video) {
215
+ if (
216
+ shouldReport &&
217
+ context.page.video &&
218
+ context.page.url() !== "about:blank"
219
+ ) {
216
220
  const video = context.page.video();
217
221
  if (video) {
218
222
  const videoPath = await video.path();