codeceptjs 3.6.4-beta.1 → 3.6.4-beta.2

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.
@@ -1,6 +1,5 @@
1
1
  const axios = require('axios').default;
2
2
  const Helper = require('@codeceptjs/helper');
3
- const { Agent } = require('https');
4
3
  const Secret = require('../secret');
5
4
 
6
5
  const { beautify } = require('../utils');
@@ -11,12 +10,12 @@ const { beautify } = require('../utils');
11
10
  * @typedef RESTConfig
12
11
  * @type {object}
13
12
  * @prop {string} [endpoint] - API base URL
14
- * @prop {boolean} [prettyPrintJson=false] - pretty print json for response/request on console logs
15
- * @prop {number} [timeout=1000] - timeout for requests in milliseconds. 10000ms by default
16
- * @prop {object} [defaultHeaders] - a list of default headers
17
- * @prop {object} [httpAgent] - create an agent with SSL certificate
18
- * @prop {function} [onRequest] - a async function which can update request object.
19
- * @prop {function} [onResponse] - a async function which can update response object.
13
+ * @prop {boolean} [prettyPrintJson=false] - pretty print json for response/request on console logs.
14
+ * @prop {boolean} [printCurl=false] - print cURL request on console logs. False by default.
15
+ * @prop {number} [timeout=1000] - timeout for requests in milliseconds. 10000ms by default.
16
+ * @prop {object} [defaultHeaders] - a list of default headers.
17
+ * @prop {function} [onRequest] - an async function which can update request object.
18
+ * @prop {function} [onResponse] - an async function which can update response object.
20
19
  * @prop {number} [maxUploadFileSize] - set the max content file size in MB when performing api calls.
21
20
  */
22
21
  const config = {};
@@ -42,24 +41,6 @@ const config = {};
42
41
  * }
43
42
  *}
44
43
  * ```
45
- * With httpAgent
46
- *
47
- * ```js
48
- * {
49
- * helpers: {
50
- * REST: {
51
- * endpoint: 'http://site.com/api',
52
- * prettyPrintJson: true,
53
- * httpAgent: {
54
- * key: fs.readFileSync(__dirname + '/path/to/keyfile.key'),
55
- * cert: fs.readFileSync(__dirname + '/path/to/certfile.cert'),
56
- * rejectUnauthorized: false,
57
- * keepAlive: true
58
- * }
59
- * }
60
- * }
61
- * }
62
- * ```
63
44
  *
64
45
  * ## Access From Helpers
65
46
  *
@@ -96,14 +77,7 @@ class REST extends Helper {
96
77
  this._setConfig(config);
97
78
 
98
79
  this.headers = { ...this.options.defaultHeaders };
99
-
100
- // Create an agent with SSL certificate
101
- if (this.options.httpAgent) {
102
- if (!this.options.httpAgent.key || !this.options.httpAgent.cert) throw Error('Please recheck your httpAgent config!');
103
- this.httpsAgent = new Agent(this.options.httpAgent);
104
- }
105
-
106
- this.axios = this.httpsAgent ? axios.create({ httpsAgent: this.httpsAgent }) : axios.create();
80
+ this.axios = axios.create();
107
81
  // @ts-ignore
108
82
  this.axios.defaults.headers = this.options.defaultHeaders;
109
83
  }
@@ -192,6 +166,7 @@ class REST extends Helper {
192
166
  }
193
167
 
194
168
  this.options.prettyPrintJson ? this.debugSection('Request', beautify(JSON.stringify(_debugRequest))) : this.debugSection('Request', JSON.stringify(_debugRequest));
169
+ if (this.options.printCurl) this.debugSection('CURL Request', curlize(request));
195
170
 
196
171
  let response;
197
172
  try {
@@ -372,3 +347,22 @@ class REST extends Helper {
372
347
  }
373
348
  }
374
349
  module.exports = REST;
350
+
351
+ function curlize(request) {
352
+ let curl = `curl --location --request ${request.method ? request.method.toUpperCase() : 'GET'} ${request.baseURL} `.replace("'", '');
353
+
354
+ if (request.headers) {
355
+ Object.entries(request.headers).forEach(([key, value]) => {
356
+ curl += `-H "${key}: ${value}" `;
357
+ });
358
+ }
359
+
360
+ if (!curl.toLowerCase().includes('content-type: application/json')) {
361
+ curl += '-H "Content-Type: application/json" ';
362
+ }
363
+
364
+ if (request.data) {
365
+ curl += `-d '${JSON.stringify(request.data)}'`;
366
+ }
367
+ return curl;
368
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "3.6.4-beta.01",
3
+ "version": "3.6.4-beta.2",
4
4
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
5
5
  "keywords": [
6
6
  "acceptance",
@@ -98,7 +98,7 @@
98
98
  "glob": "6.0.1",
99
99
  "html-minifier-terser": "7.2.0",
100
100
  "inquirer": "6.5.2",
101
- "joi": "17.13.0",
101
+ "joi": "17.13.1",
102
102
  "js-beautify": "1.15.1",
103
103
  "lodash.clonedeep": "4.5.0",
104
104
  "lodash.merge": "4.6.2",
@@ -128,7 +128,7 @@
128
128
  "@types/node": "20.11.30",
129
129
  "@wdio/sauce-service": "8.35.1",
130
130
  "@wdio/selenium-standalone-service": "8.3.2",
131
- "@wdio/utils": "8.36.1",
131
+ "@wdio/utils": "8.38.2",
132
132
  "@xmldom/xmldom": "0.8.10",
133
133
  "apollo-server-express": "2.25.3",
134
134
  "chai-as-promised": "7.1.2",
@@ -1155,7 +1155,6 @@ declare namespace CodeceptJS {
1155
1155
  * ## Methods
1156
1156
  */
1157
1157
  // @ts-ignore
1158
- // @ts-ignore
1159
1158
  class ExpectHelper {
1160
1159
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
1161
1160
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
@@ -1268,7 +1267,6 @@ declare namespace CodeceptJS {
1268
1267
  * ## Methods
1269
1268
  */
1270
1269
  // @ts-ignore
1271
- // @ts-ignore
1272
1270
  class ExpectHelper {
1273
1271
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
1274
1272
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
@@ -1941,7 +1939,6 @@ declare namespace CodeceptJS {
1941
1939
  * @property [httpsOpts] - key & cert values are the paths to .key and .crt files
1942
1940
  */
1943
1941
  // @ts-ignore
1944
- // @ts-ignore
1945
1942
  type MockServerConfig = {
1946
1943
  port?: number;
1947
1944
  host?: string;
@@ -2067,7 +2064,6 @@ declare namespace CodeceptJS {
2067
2064
  * ## Methods
2068
2065
  */
2069
2066
  // @ts-ignore
2070
- // @ts-ignore
2071
2067
  class MockServer {
2072
2068
  /**
2073
2069
  * Start the mock server
@@ -8192,24 +8188,6 @@ declare namespace CodeceptJS {
8192
8188
  * }
8193
8189
  * }
8194
8190
  * ```
8195
- * With httpAgent
8196
- *
8197
- * ```js
8198
- * {
8199
- * helpers: {
8200
- * REST: {
8201
- * endpoint: 'http://site.com/api',
8202
- * prettyPrintJson: true,
8203
- * httpAgent: {
8204
- * key: fs.readFileSync(__dirname + '/path/to/keyfile.key'),
8205
- * cert: fs.readFileSync(__dirname + '/path/to/certfile.cert'),
8206
- * rejectUnauthorized: false,
8207
- * keepAlive: true
8208
- * }
8209
- * }
8210
- * }
8211
- * }
8212
- * ```
8213
8191
  *
8214
8192
  * ## Access From Helpers
8215
8193
  *
@@ -1179,7 +1179,6 @@ declare namespace CodeceptJS {
1179
1179
  * ## Methods
1180
1180
  */
1181
1181
  // @ts-ignore
1182
- // @ts-ignore
1183
1182
  class ExpectHelper {
1184
1183
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
1185
1184
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
@@ -1292,7 +1291,6 @@ declare namespace CodeceptJS {
1292
1291
  * ## Methods
1293
1292
  */
1294
1293
  // @ts-ignore
1295
- // @ts-ignore
1296
1294
  class ExpectHelper {
1297
1295
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
1298
1296
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
@@ -1968,7 +1966,6 @@ declare namespace CodeceptJS {
1968
1966
  * @property [httpsOpts] - key & cert values are the paths to .key and .crt files
1969
1967
  */
1970
1968
  // @ts-ignore
1971
- // @ts-ignore
1972
1969
  type MockServerConfig = {
1973
1970
  port?: number;
1974
1971
  host?: string;
@@ -2094,7 +2091,6 @@ declare namespace CodeceptJS {
2094
2091
  * ## Methods
2095
2092
  */
2096
2093
  // @ts-ignore
2097
- // @ts-ignore
2098
2094
  class MockServer {
2099
2095
  /**
2100
2096
  * Start the mock server
@@ -8686,20 +8682,20 @@ declare namespace CodeceptJS {
8686
8682
  /**
8687
8683
  * ## Configuration
8688
8684
  * @property [endpoint] - API base URL
8689
- * @property [prettyPrintJson = false] - pretty print json for response/request on console logs
8690
- * @property [timeout = 1000] - timeout for requests in milliseconds. 10000ms by default
8691
- * @property [defaultHeaders] - a list of default headers
8692
- * @property [httpAgent] - create an agent with SSL certificate
8693
- * @property [onRequest] - a async function which can update request object.
8694
- * @property [onResponse] - a async function which can update response object.
8685
+ * @property [prettyPrintJson = false] - pretty print json for response/request on console logs.
8686
+ * @property [printCurl = false] - print cURL request on console logs. False by default.
8687
+ * @property [timeout = 1000] - timeout for requests in milliseconds. 10000ms by default.
8688
+ * @property [defaultHeaders] - a list of default headers.
8689
+ * @property [onRequest] - an async function which can update request object.
8690
+ * @property [onResponse] - an async function which can update response object.
8695
8691
  * @property [maxUploadFileSize] - set the max content file size in MB when performing api calls.
8696
8692
  */
8697
8693
  type RESTConfig = {
8698
8694
  endpoint?: string;
8699
8695
  prettyPrintJson?: boolean;
8696
+ printCurl?: boolean;
8700
8697
  timeout?: number;
8701
8698
  defaultHeaders?: any;
8702
- httpAgent?: any;
8703
8699
  onRequest?: (...params: any[]) => any;
8704
8700
  onResponse?: (...params: any[]) => any;
8705
8701
  maxUploadFileSize?: number;
@@ -8725,24 +8721,6 @@ declare namespace CodeceptJS {
8725
8721
  * }
8726
8722
  * }
8727
8723
  * ```
8728
- * With httpAgent
8729
- *
8730
- * ```js
8731
- * {
8732
- * helpers: {
8733
- * REST: {
8734
- * endpoint: 'http://site.com/api',
8735
- * prettyPrintJson: true,
8736
- * httpAgent: {
8737
- * key: fs.readFileSync(__dirname + '/path/to/keyfile.key'),
8738
- * cert: fs.readFileSync(__dirname + '/path/to/certfile.cert'),
8739
- * rejectUnauthorized: false,
8740
- * keepAlive: true
8741
- * }
8742
- * }
8743
- * }
8744
- * }
8745
- * ```
8746
8724
  *
8747
8725
  * ## Access From Helpers
8748
8726
  *