@cuppet/core 2.0.1 → 2.0.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.
@@ -102,7 +102,7 @@ Before(async function (testCase) {
102
102
 
103
103
  // executed after every test
104
104
  After(async function (testCase) {
105
- if (testCase.result.status === Status.FAILED) {
105
+ if (testCase.result?.status !== Status.PASSED) {
106
106
  console.log(`Scenario: '${testCase.pickle.name}' - has failed...\r\n`);
107
107
  }
108
108
 
@@ -50,9 +50,9 @@ class KafkaManager {
50
50
  */
51
51
  async initialize() {
52
52
  try {
53
- // Create Kafka instance
53
+ // Create Kafka instance (no actual connection yet)
54
54
  this.kafka = new Kafka(this.options);
55
- console.log(`Successfully connected to Kafka`);
55
+ console.log('Kafka client instance created successfully.');
56
56
  this.isInitialized = true;
57
57
  } catch (error) {
58
58
  throw new Error(`Failed to initialize Kafka client: ${error.message}`);
@@ -68,9 +68,16 @@ class KafkaManager {
68
68
  if (!this.isInitialized) {
69
69
  throw new Error('Kafka client not initialized. Call initialize() first.');
70
70
  }
71
- this.producer = this.kafka.producer(producerOptions);
72
- await this.producer.connect();
73
- return this.producer;
71
+
72
+ try {
73
+ this.producer = this.kafka.producer(producerOptions);
74
+ await this.producer.connect();
75
+ console.log('Producer connected successfully to Kafka broker');
76
+ return this.producer;
77
+ } catch (error) {
78
+ this.producer = null;
79
+ throw new Error(`Failed to connect producer to Kafka broker: ${error.message}`);
80
+ }
74
81
  }
75
82
 
76
83
  /**
@@ -87,9 +94,15 @@ class KafkaManager {
87
94
  consumerOptions.groupId = `cuppet-test-${Math.random().toString(16).slice(2, 8)}`;
88
95
  }
89
96
 
90
- this.consumer = this.kafka.consumer(consumerOptions);
91
- await this.consumer.connect();
92
- return this.consumer;
97
+ try {
98
+ this.consumer = this.kafka.consumer(consumerOptions);
99
+ await this.consumer.connect();
100
+ console.log('Consumer connected successfully to Kafka broker');
101
+ return this.consumer;
102
+ } catch (error) {
103
+ this.consumer = null;
104
+ throw new Error(`Failed to connect consumer to Kafka broker: ${error.message}`);
105
+ }
93
106
  }
94
107
 
95
108
  /**
@@ -106,13 +119,18 @@ class KafkaManager {
106
119
  * @returns {Promise<void>}
107
120
  */
108
121
  async sendMessage(topic, message = {}) {
109
- if (!this.producer) {
110
- await this.createProducer();
122
+ try {
123
+ if (!this.producer) {
124
+ await this.createProducer();
125
+ }
126
+ await this.producer.send({
127
+ topic,
128
+ messages: [message],
129
+ });
130
+ console.log(`Message sent successfully to topic: ${topic}`);
131
+ } catch (error) {
132
+ throw new Error(`Failed to send message to topic '${topic}': ${error.message}`);
111
133
  }
112
- await this.producer.send({
113
- topic,
114
- messages: [message],
115
- });
116
134
  }
117
135
 
118
136
  /** Subscribe to a topic
@@ -120,24 +138,41 @@ class KafkaManager {
120
138
  * @returns {Promise<Object>} - Object with topic, partition, and message properties
121
139
  */
122
140
  async subscribeToTopics(topics = []) {
123
- if (!this.consumer) {
124
- await this.createConsumer();
141
+ try {
142
+ if (!this.consumer) {
143
+ await this.createConsumer();
144
+ }
145
+ await this.consumer.subscribe({
146
+ topics: topics,
147
+ });
148
+ console.log(`Successfully subscribed to topics: ${topics.join(', ')}`);
149
+ } catch (error) {
150
+ throw new Error(`Failed to subscribe to topics [${topics.join(', ')}]: ${error.message}`);
125
151
  }
126
- await this.consumer.subscribe({
127
- topics: topics,
128
- });
129
152
  }
130
153
 
131
154
  /** Consume a message from a topic
132
155
  * @returns {Promise<Object>} - Object with topic, partition, and message properties
133
156
  */
134
157
  async consumeMessage() {
135
- return new Promise((resolve) => {
136
- this.consumer.run({
137
- eachMessage: async ({ topic, partition, message }) => {
138
- resolve({ topic, partition, message });
139
- },
140
- });
158
+ if (!this.consumer) {
159
+ throw new Error('Consumer not initialized. Call subscribeToTopics() first.');
160
+ }
161
+
162
+ return new Promise((resolve, reject) => {
163
+ this.consumer
164
+ .run({
165
+ eachMessage: async ({ topic, partition, message }) => {
166
+ try {
167
+ resolve({ topic, partition, message });
168
+ } catch (error) {
169
+ reject(new Error(`Failed to process consumed message: ${error.message}`));
170
+ }
171
+ },
172
+ })
173
+ .catch((error) => {
174
+ reject(new Error(`Failed to consume message: ${error.message}`));
175
+ });
141
176
  });
142
177
  }
143
178
 
@@ -145,8 +180,18 @@ class KafkaManager {
145
180
  * @returns {Promise<void>}
146
181
  */
147
182
  async disconnect() {
148
- await this.consumer.stop();
149
- await this.consumer.disconnect();
183
+ if (!this.consumer) {
184
+ console.log('No consumer to disconnect');
185
+ return;
186
+ }
187
+
188
+ try {
189
+ await this.consumer.stop();
190
+ await this.consumer.disconnect();
191
+ console.log('Consumer disconnected successfully');
192
+ } catch (error) {
193
+ throw new Error(`Failed to disconnect consumer: ${error.message}`);
194
+ }
150
195
  }
151
196
 
152
197
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuppet/core",
3
- "version": "2.0.1",
3
+ "version": "2.0.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": [
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "@supercharge/strings": "^2.0.0",
33
33
  "@wdio/globals": "9.17.0",
34
- "appium": "3.0.1",
34
+ "appium": "3.1.2",
35
35
  "appium-uiautomator2-driver": "5.0",
36
36
  "axios": "^1.11.0",
37
37
  "backstopjs": "^6.3.25",
@@ -55,14 +55,14 @@
55
55
  "@html-eslint/parser": "^0.43.0",
56
56
  "@semantic-release/changelog": "^6.0.3",
57
57
  "@semantic-release/git": "^10.0.1",
58
- "@semantic-release/github": "^11.0.3",
59
- "@semantic-release/npm": "^12.0.1",
58
+ "@semantic-release/github": "^12.0.2",
59
+ "@semantic-release/npm": "^13.1.3",
60
60
  "config": "^4.1.0",
61
61
  "eslint": "^9.29.0",
62
62
  "eslint-config-prettier": "^10.1.5",
63
63
  "eslint-plugin-prettier": "^5.5.1",
64
64
  "prettier": "^3.6.1",
65
- "semantic-release": "^24.2.5"
65
+ "semantic-release": "^25.0.2"
66
66
  },
67
67
  "scripts": {
68
68
  "test": "cucumber-js features/tests/example.feature",
@@ -124,6 +124,9 @@ module.exports = {
124
124
  return this.response;
125
125
  } catch (error) {
126
126
  console.log('Request has failed, use response code step definition to validate the response!');
127
+ if (!error.response) {
128
+ throw new Error(`Request failed with: ${error}`);
129
+ }
127
130
  return (this.response = error.response);
128
131
  }
129
132
  },
@@ -168,8 +171,9 @@ module.exports = {
168
171
  current = current[keys[i]];
169
172
  }
170
173
 
174
+ const castedValue = helper.castPrimitiveType(value);
171
175
  // Set the final value
172
- current[keys[keys.length - 1]] = value;
176
+ current[keys[keys.length - 1]] = castedValue;
173
177
  return this.request;
174
178
  },
175
179