@cuppet/core 1.3.2 → 1.3.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.
@@ -27,7 +27,7 @@ When('I unsubscribe from MQTT topic {string}', async function (topic) {
27
27
  await mqttFunctions.unsubscribeFromTopic(this.mqttManager, topic);
28
28
  });
29
29
 
30
- When('I prepare MQTT message as JSON', async function (docString) {
30
+ When('I prepare a JSON as MQTT message', async function (docString) {
31
31
  const message = JSON.stringify(docString);
32
32
  await mqttFunctions.prepareMessage(message, true);
33
33
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuppet/core",
3
- "version": "1.3.2",
3
+ "version": "1.3.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": [
@@ -7,8 +7,8 @@ const helper = require('./helperFunctions');
7
7
  * Provides core MQTT testing operations following the same pattern as Puppeteer and Appium functions
8
8
  */
9
9
  module.exports = {
10
- /** @type {Object} */
11
- messageObject: null,
10
+ /** @type {string} */
11
+ messageString: null,
12
12
 
13
13
  /**
14
14
  * Prepare topic by replacing variables
@@ -28,8 +28,11 @@ module.exports = {
28
28
  const resolvedMessage = await storage.checkForMultipleVariables(message);
29
29
  if (json) {
30
30
  try {
31
- this.messageObject = JSON.parse(resolvedMessage);
32
- return this.messageObject;
31
+ // Validate JSON (do not assign the value to the message object)
32
+ JSON.parse(resolvedMessage);
33
+ // Pass it as a string
34
+ this.messageString = resolvedMessage;
35
+ return this.messageString;
33
36
  } catch (error) {
34
37
  throw new Error(`Invalid JSON message: ${error.message}`);
35
38
  }
@@ -86,9 +89,9 @@ module.exports = {
86
89
  */
87
90
  publishJsonMessage: async function (mqttManager, topic, jsonString = null, qos = 0, retain = false) {
88
91
  const resolvedTopic = await this.prepareTopic(topic);
89
- const resolvedJson = jsonString ? await this.prepareMessage(jsonString, true) : this.messageObject;
92
+ const resolvedJson = jsonString ? await this.prepareMessage(jsonString, true) : this.messageString;
90
93
  // Delete the message object before the message is published to avoid conflicts if the request fails.
91
- delete this.messageObject;
94
+ delete this.messageString;
92
95
  await mqttManager.publish(resolvedTopic, resolvedJson, { qos, retain });
93
96
  },
94
97