@cuppet/core 1.1.1 → 1.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuppet/core",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Core testing framework components for Cuppet - BDD framework based on Cucumber and Puppeteer",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -43,9 +43,9 @@ module.exports = {
43
43
  'Content-Type': 'application/json',
44
44
  Accept: 'application/json',
45
45
  };
46
- if (this.formData) {
46
+ if (this.request instanceof FormData) {
47
47
  defaultHeaders = {};
48
- Object.assign(defaultHeaders, this.formData.getHeaders());
48
+ Object.assign(defaultHeaders, this.request.getHeaders());
49
49
  }
50
50
  if (config.has('api.x-api-key')) {
51
51
  defaultHeaders['X-Api-Key'] = config.get('api.x-api-key');
@@ -114,6 +114,8 @@ module.exports = {
114
114
  ...((data instanceof FormData || Object.keys(data).length) && { data }),
115
115
  headers: requestHeaders,
116
116
  });
117
+ // Delete the request object after the request is sent to avoid conflicts with the next request.
118
+ delete this.request;
117
119
 
118
120
  return this.response;
119
121
  } catch (error) {
@@ -302,10 +304,14 @@ module.exports = {
302
304
  for (const [key, value] of Object.entries(data)) {
303
305
  if (key === 'file') {
304
306
  const mimeType = mime.contentType(value) || 'application/octet-stream';
305
- formData.append('file', fs.createReadStream(filePath + value), {
306
- filename: value,
307
- contentType: mimeType,
308
- });
307
+ if (fs.existsSync(filePath + value)) {
308
+ formData.append('file', fs.createReadStream(filePath + value), {
309
+ filename: value,
310
+ contentType: mimeType,
311
+ });
312
+ } else {
313
+ throw new Error(`File ${filePath + value} does not exist in the files folder!`);
314
+ }
309
315
  formData.append('type', mimeType);
310
316
  } else {
311
317
  formData.append(key, await storage.checkForSavedVariable(value));