chore: adopted new file structure and update README and example.js with postmanClient and hoppscotchClient.#1476
Conversation
|
|
""" WalkthroughThis change updates the JavaScript WebSocket client template by modifying import paths in the example and documentation to reference the specific Changes
Sequence Diagram(s)sequenceDiagram
participant TestRunner
participant Generator
participant FileSystem
TestRunner->>Generator: Generate client for Postman (output: client-postman/client.js)
Generator->>FileSystem: Write client.js to client-postman directory
TestRunner->>Generator: Generate client for Hoppscotch (output: client-hoppscotch/client.js)
Generator->>FileSystem: Write client.js to client-hoppscotch directory
TestRunner->>Generator: Generate custom Hoppscotch client (output: custom-client-hoppscotch/custom-client-hoppscotch.js)
Generator->>FileSystem: Write custom-client-hoppscotch.js to custom-client-hoppscotch directory
TestRunner->>FileSystem: Read client.js and README.md from each directory
TestRunner->>TestRunner: Run snapshot tests on outputs
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🔭 Outside diff range comments (7)
packages/templates/clients/websocket/javascript/test/integration.test.js (7)
32-33: 🛠️ Refactor suggestionUpdate test to use the new directory structure.
The test still reads the client file from the old location. Consider updating it to use the new
testResultPathPostmanconstant.- const client = await readFile(path.join(testResultPath, testOutputFile), 'utf8'); + const client = await readFile(path.join(testResultPathPostman, testOutputFile), 'utf8'); expect(client).toMatchSnapshot();
49-50: 🛠️ Refactor suggestionUpdate test to use the new directory structure.
Similar to the previous test, this one also reads the client file from the old location. Consider updating it to use the new
testResultPathHoppscotchconstant.- const client = await readFile(path.join(testResultPath, testOutputFile), 'utf8'); + const client = await readFile(path.join(testResultPathHoppscotch, testOutputFile), 'utf8'); expect(client).toMatchSnapshot();
65-69: 🛠️ Refactor suggestionUpdate test to use the new directory structure.
This test should also be updated to use the new directory structure for consistency.
- const clientOutputFile = path.join(testResultPath, defaultOutputFile); + const clientOutputFile = path.join(testResultPathClient, defaultOutputFile); const checkClientOutputFileExists = await stat(clientOutputFile); expect(checkClientOutputFileExists.isFile()).toBeTruthy();
22-28: 🛠️ Refactor suggestionUpdate Generator initialization to use the new path constants.
For the first test case, update the Generator initialization to use the new
testResultPathPostmanconstant.- const generator = new Generator(template, testResultPath, { + const generator = new Generator(template, testResultPathPostman, { forceWrite: true, templateParams: { server: 'echoServer', clientFileName: testOutputFile } });
39-45: 🛠️ Refactor suggestionUpdate Generator initialization to use the new path constants.
For the second test case, update the Generator initialization to use the new
testResultPathHoppscotchconstant.- const generator = new Generator(template, testResultPath, { + const generator = new Generator(template, testResultPathHoppscotch, { forceWrite: true, templateParams: { server: 'echoServer', clientFileName: testOutputFile } });
56-61: 🛠️ Refactor suggestionUpdate Generator initialization to use the new path constants.
For the third test case, update the Generator initialization to use the new
testResultPathClientconstant.- const generator = new Generator(template, testResultPath, { + const generator = new Generator(template, testResultPathClient, { forceWrite: true, templateParams: { server: 'echoServer', } });
75-80: 🛠️ Refactor suggestionUpdate Generator initialization to use the new path constants.
For consistency, update the Generator initialization in the fourth test case as well.
- const generator = new Generator(template, testResultPath, { + const generator = new Generator(template, testResultPathHoppscotch, { forceWrite: true, templateParams: { clientFileName: testOutputFile } });
🧹 Nitpick comments (11)
packages/templates/clients/websocket/javascript/README.md (1)
9-9: Improve readability with proper punctuation and articles.The added explanatory text would benefit from improved grammar to enhance clarity for users.
-> By default this is testing against Postman echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change first line to `const WSClient = require('./test/temp/snapshotTestResult/hoppscotchClient/client-hoppscotch.js');` and run `node example.js` again. You will see example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage` so each client generated has the same API. +> By default, this is testing against Postman echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change the first line to `const WSClient = require('./test/temp/snapshotTestResult/hoppscotchClient/client-hoppscotch.js');` and run `node example.js` again. You will see the example still works, but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage` so each client generated has the same API.🧰 Tools
🪛 LanguageTool
[uncategorized] ~9-~9: Did you mean: “By default,”?
Context: ...rated by the test:node example.js> By default this is testing against Postman echo se...(BY_DEFAULT_COMMA)
[uncategorized] ~9-~9: You might be missing the article “the” here.
Context: ...ocket/javascript/example.jsand change first line toconst WSClient = require('./te...(AI_EN_LECTOR_MISSING_DETERMINER_THE)
[uncategorized] ~9-~9: Possible missing article found.
Context: ...nnode example.jsagain. You will see example still works but now it is using a diffe...(AI_HYDRA_LEO_MISSING_THE)
[uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... again. You will see example still works but now it is using a different API. This i...(COMMA_COMPOUND_SENTENCE)
packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/postmanClient/client-postman.js (4)
12-12: Consider simplifying the class name to avoid redundancy.The class name
PostmanEchoWebSocketClientClientcontains a redundant "Client" suffix.-class PostmanEchoWebSocketClientClient { +class PostmanEchoWebSocketClient {Remember to also update the export statement at the end of the file:
-module.exports = PostmanEchoWebSocketClientClient; +module.exports = PostmanEchoWebSocketClient;
61-68: Fix method documentation comment.The comment above this method incorrectly states it's for registering error handlers, but it's actually for message handlers.
- // Method to register custom error handlers + // Method to register custom message handlers registerMessageHandler(handler) { if (typeof handler === 'function') { this.messageHandlers.push(handler); } else { console.warn('Message handler must be a function'); } }
25-29: Add connection state tracking.The
connectmethod doesn't track the connection state, which could lead to multiple connection attempts or attempts to use a disconnected socket.connect() { return new Promise((resolve, reject) => { + if (this.websocket && this.websocket.readyState === WebSocket.OPEN) { + console.log('Already connected to Postman Echo WebSocket Client server'); + resolve(); + return; + } + this.websocket = new WebSocket(this.url); // On successful connection this.websocket.onopen = () => { console.log('Connected to Postman Echo WebSocket Client server'); resolve(); };
90-96: Return a Promise from the close method for consistency.For consistency with the
connectmethod, consider making theclosemethod return a Promise as well.// Method to close the WebSocket connection close() { - if (this.websocket) { - this.websocket.close(); - console.log('WebSocket connection closed.'); - } + return new Promise((resolve) => { + if (!this.websocket) { + console.log('No WebSocket connection to close.'); + resolve(); + return; + } + + this.websocket.onclose = () => { + console.log('WebSocket connection closed.'); + this.websocket = null; + resolve(); + }; + + this.websocket.close(); + }); }packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/postmanClient/README.md (1)
37-44: Consider adding response type information.The documentation for
sendEchoMessagecould be enhanced by specifying what type of response to expect after sending a message. This would help users understand the complete request-response cycle.packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/hoppscotchClient/README.md (2)
5-5: Fix typo in overview section.There's a typo in "Undestand" which should be "Understand".
-Undestand how to use Hoppscotch Echo WebSocket as a client. Hoppscotch Echo WebSocket server echoes back any messages sent to it. You can use this to test WebSocket connections and message flows. +Understand how to use Hoppscotch Echo WebSocket as a client. Hoppscotch Echo WebSocket server echoes back any messages sent to it. You can use this to test WebSocket connections and message flows.
39-39: Add missing article in the sentence.Missing "the" before "server" makes the sentence grammatically incorrect.
-Receive the timestamp message sent from server every second. +Receive the timestamp message sent from the server every second.🧰 Tools
🪛 LanguageTool
[uncategorized] ~39-~39: You might be missing the article “the” here.
Context: ...Receive the timestamp message sent from server every second. Example: ```javascr...(AI_EN_LECTOR_MISSING_DETERMINER_THE)
packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/hoppscotchClient/client-hoppscotch.js (3)
59-60: Correct method comment for registerMessageHandler.The method comment incorrectly states this is for registering error handlers, but it's actually for message handlers.
- // Method to register custom error handlers + // Method to register custom message handlers registerMessageHandler(handler) {
83-85: Consider JSON handling consistency with documentation.The
sendEchoMessagemethod usesJSON.stringifyon all messages, but the README example (line 53) implies sending a simple string. This inconsistency could cause confusion. Consider either:
- Updating the method to handle both string and object types, or
- Clarifying in the documentation that all messages are automatically JSON-stringified
sendEchoMessage(message) { - this.websocket.send(JSON.stringify(message)); + const payload = typeof message === 'string' ? message : JSON.stringify(message); + this.websocket.send(payload); console.log('Sent message to echo server:', message); }
77-80: Simplify the handleMessage method.The current implementation is a simple wrapper that only calls the callback if it exists. This pattern is already used in other methods like the WebSocket's onmessage handler. Consider inlining this logic to reduce unnecessary abstraction.
- // Method to handle message with callback - handleMessage(message, cb) { - if (cb) cb(message); - }And update line 35:
- this.handleMessage(event.data, handler); + handler(event.data);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
packages/templates/clients/websocket/javascript/README.md(1 hunks)packages/templates/clients/websocket/javascript/example.js(1 hunks)packages/templates/clients/websocket/javascript/test/integration.test.js(1 hunks)packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/hoppscotchClient/README.md(1 hunks)packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/hoppscotchClient/client-hoppscotch.js(1 hunks)packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/postmanClient/README.md(1 hunks)packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/postmanClient/client-postman.js(1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
packages/templates/clients/websocket/javascript/test/integration.test.js (1)
packages/templates/clients/websocket/python/test/integration.test.js (1)
path(5-5)
packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/hoppscotchClient/client-hoppscotch.js (2)
packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/postmanClient/client-postman.js (1)
WebSocket(10-10)packages/templates/clients/websocket/javascript/example.js (1)
message(26-26)
🪛 LanguageTool
packages/templates/clients/websocket/javascript/README.md
[uncategorized] ~9-~9: Did you mean: “By default,”?
Context: ...rated by the test: node example.js > By default this is testing against Postman echo se...
(BY_DEFAULT_COMMA)
[uncategorized] ~9-~9: You might be missing the article “the” here.
Context: ...ocket/javascript/example.jsand change first line toconst WSClient = require('./te...
(AI_EN_LECTOR_MISSING_DETERMINER_THE)
[uncategorized] ~9-~9: Possible missing article found.
Context: ...n node example.js again. You will see example still works but now it is using a diffe...
(AI_HYDRA_LEO_MISSING_THE)
[uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... again. You will see example still works but now it is using a different API. This i...
(COMMA_COMPOUND_SENTENCE)
packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/hoppscotchClient/README.md
[uncategorized] ~39-~39: You might be missing the article “the” here.
Context: ...Receive the timestamp message sent from server every second. Example: ```javascr...
(AI_EN_LECTOR_MISSING_DETERMINER_THE)
🔇 Additional comments (2)
packages/templates/clients/websocket/javascript/example.js (1)
1-1: LGTM! Import path updated to reflect new directory structure.The path to the client module has been correctly updated to match the new file structure, which aligns with the PR objective to recreate the file structure.
packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/postmanClient/README.md (1)
46-93: Good implementation of the client testing example.The example provides a comprehensive demonstration of the client usage, including message and error handling, connection establishment, and a robust approach to sending messages periodically with proper error handling.
| #### `handleTimeStampMessage(payload)` | ||
| Receive the timestamp message sent from server every second. | ||
|
|
||
|
|
||
| **Example:** | ||
| ```javascript | ||
| client.handleTimeStampMessage("test"); | ||
| ``` |
There was a problem hiding this comment.
💡 Verification agent
❓ Verification inconclusive
Verify the implementation of handleTimeStampMessage.
The README documents a handleTimeStampMessage function, but there doesn't appear to be a corresponding implementation in the client-hoppscotch.js file. Additionally, the example shows this method being used with a string parameter "test", but the description suggests it's for receiving messages, not sending them.
🏁 Script executed:
#!/bin/bash
# Check if the handleTimeStampMessage method is implemented in the client-hoppscotch.js file
grep -n "handleTimeStampMessage" packages/templates/clients/websocket/javascript/test/temp/snapshotTestResult/hoppscotchClient/client-hoppscotch.jsLength of output: 147
Missing Implementation for handleTimeStampMessage in Client
It appears that the README documents a handleTimeStampMessage method with an example usage (client.handleTimeStampMessage("test")), yet no implementation was found in the corresponding client file. This discrepancy raises two concerns:
-
Implementation Gap:
Theclient-hoppscotch.jsfile does not contain any implementation ofhandleTimeStampMessage. Please verify if this method is defined elsewhere or if it was accidentally omitted. -
API Inconsistency:
The example passes a string parameter ("test"), which conflicts with the description that indicates the method should handle timestamp messages received from the server. Clarification is needed on whether the method is intended to process incoming messages rather than be invoked with a test string.
Please review and update the implementation or documentation accordingly.
🧰 Tools
🪛 LanguageTool
[uncategorized] ~39-~39: You might be missing the article “the” here.
Context: ...Receive the timestamp message sent from server every second. Example: ```javascr...
(AI_EN_LECTOR_MISSING_DETERMINER_THE)
fd25e4b to
77a43a4
Compare
c6fab20 to
1337ae5
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/templates/clients/websocket/javascript/README.md (1)
9-9: Refine README text for clarity and minor grammatical improvements.Consider updating this line by inserting a comma after "By default", adding the definite article "the" before "Postman echo service" and before "first line", and inserting a comma before "but" to separate independent clauses. This will improve readability and conform to standard English grammar. For example:
- > By default this is testing against Postman echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change first line to `const WSClient = require('./test/temp/snapshotTestResult/hoppscotch-client/client-hoppscotch.js');` again. You will see example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage` so each client generated has the same API. + > By default, this is testing against the Postman echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change the first line to `const WSClient = require('./test/temp/snapshotTestResult/hoppscotch-client/client-hoppscotch.js');` again. You will see that the example still works, but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage`, so each client generated has the same API.🧰 Tools
🪛 LanguageTool
[uncategorized] ~9-~9: Did you mean: “By default,”?
Context: ...rated by the test:node example.js> By default this is testing against Postman echo se...(BY_DEFAULT_COMMA)
[uncategorized] ~9-~9: You might be missing the article “the” here.
Context: ...ocket/javascript/example.jsand change first line toconst WSClient = require('./te...(AI_EN_LECTOR_MISSING_DETERMINER_THE)
[uncategorized] ~9-~9: Possible missing article found.
Context: ...t-hoppscotch.js');` again. You will see example still works but now it is using a diffe...(AI_HYDRA_LEO_MISSING_THE)
[uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... again. You will see example still works but now it is using a different API. This i...(COMMA_COMPOUND_SENTENCE)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/generator/lib/generator.js(1 hunks)packages/templates/clients/websocket/javascript/README.md(1 hunks)packages/templates/clients/websocket/javascript/example.js(2 hunks)packages/templates/clients/websocket/javascript/test/integration.test.js(6 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/templates/clients/websocket/javascript/example.js
- apps/generator/lib/generator.js
- packages/templates/clients/websocket/javascript/test/integration.test.js
🧰 Additional context used
🪛 LanguageTool
packages/templates/clients/websocket/javascript/README.md
[uncategorized] ~9-~9: Did you mean: “By default,”?
Context: ...rated by the test: node example.js > By default this is testing against Postman echo se...
(BY_DEFAULT_COMMA)
[uncategorized] ~9-~9: You might be missing the article “the” here.
Context: ...ocket/javascript/example.jsand change first line toconst WSClient = require('./te...
(AI_EN_LECTOR_MISSING_DETERMINER_THE)
[uncategorized] ~9-~9: Possible missing article found.
Context: ...t-hoppscotch.js');` again. You will see example still works but now it is using a diffe...
(AI_HYDRA_LEO_MISSING_THE)
[uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... again. You will see example still works but now it is using a different API. This i...
(COMMA_COMPOUND_SENTENCE)
c0dffa9 to
3d73066
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/templates/clients/websocket/javascript/README.md (1)
9-9: Improve Documentation Clarity & Grammar in the Example NoteThe updated example now correctly points to the
postman-clientlibrary, resolving the earlier naming discrepancy. However, there are a few grammatical improvements to boost clarity and readability:
- Insert a comma after “By default” and add the article “the” before “Postman Echo service.”
- Consider removing the word “again” after the import path instruction.
- Insert a comma before “but” in the sentence “You will see example still works but now it is using a different API.” This will better separate the independent clauses.
For instance, below is a suggested diff to refine the text:
- > By default this is testing against Postman echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change first line to `const WSClient = require('./test/temp/snapshotTestResult/postman-client/client-postman.js');` again. You will see example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage` so each client generated has the same API. + > By default, this is testing against the Postman Echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change the first line to `const WSClient = require('./test/temp/snapshotTestResult/postman-client/client-postman.js');`. You will see that the example still works, but now it uses a different API. This is possible since both AsyncAPI documents define the same operation name (`sendEchoMessage`), so each generated client has the same API.These changes will ensure the README is both technically correct and easier to understand.
🧰 Tools
🪛 LanguageTool
[uncategorized] ~9-~9: Did you mean: “By default,”?
Context: ...rated by the test:node example.js> By default this is testing against Postman echo se...(BY_DEFAULT_COMMA)
[uncategorized] ~9-~9: You might be missing the article “the” here.
Context: ...ocket/javascript/example.jsand change first line toconst WSClient = require('./te...(AI_EN_LECTOR_MISSING_DETERMINER_THE)
[uncategorized] ~9-~9: Possible missing article found.
Context: ...ient-postman.js');` again. You will see example still works but now it is using a diffe...(AI_HYDRA_LEO_MISSING_THE)
[uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... again. You will see example still works but now it is using a different API. This i...(COMMA_COMPOUND_SENTENCE)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/templates/clients/websocket/javascript/README.md(1 hunks)packages/templates/clients/websocket/javascript/example.js(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/templates/clients/websocket/javascript/example.js
🧰 Additional context used
🪛 LanguageTool
packages/templates/clients/websocket/javascript/README.md
[uncategorized] ~9-~9: Did you mean: “By default,”?
Context: ...rated by the test: node example.js > By default this is testing against Postman echo se...
(BY_DEFAULT_COMMA)
[uncategorized] ~9-~9: You might be missing the article “the” here.
Context: ...ocket/javascript/example.jsand change first line toconst WSClient = require('./te...
(AI_EN_LECTOR_MISSING_DETERMINER_THE)
[uncategorized] ~9-~9: Possible missing article found.
Context: ...ient-postman.js');` again. You will see example still works but now it is using a diffe...
(AI_HYDRA_LEO_MISSING_THE)
[uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... again. You will see example still works but now it is using a different API. This i...
(COMMA_COMPOUND_SENTENCE)
|
LGTM 👍 |
| const asyncapi_v3_path_postman = path.resolve(__dirname, './__fixtures__/asyncapi-postman-echo.yml'); | ||
| const asyncapi_v3_path_hoppscotch = path.resolve(__dirname, './__fixtures__/asyncapi-hoppscotch-echo.yml'); | ||
| const testResultPath = path.resolve(__dirname, './temp/snapshotTestResult'); | ||
| const testResultPathPostman = path.join(testResultPath, 'postman-client'); |
There was a problem hiding this comment.
please change this and below to client- - I mean that name of folder starts and not ends with client
also, since you introduce folders that contain the name of the service, I guess client-postman.js' and the other can also be changed?
so we end up with
client-postman/client.jsclient-hoppscotch/client.js
?
| const npmResolvedPath = requireg.resolve('npm') || ''; | ||
| const npmPath = npmResolvedPath ? npmResolvedPath.replace('index.js', '') : ''; |
There was a problem hiding this comment.
why is this change needed in this PR?
There was a problem hiding this comment.
While running the tests on the main Generator project, I encountered a 'resolve' related issue. I was able to identify and resolve it locally. However, since this issue is unrelated to the changes introduced in this PR, I will remove the corresponding fix from this pull request .
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/templates/clients/websocket/javascript/README.md (1)
9-9: Enhance sentence clarity and formatting
- Insert a comma after “By default,” and before “but” for proper compound-sentence punctuation.
- Wrap the
requirestatement in a fenced code block to improve readability.Suggested diff:
> By default, this is testing against the Postman echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change the first line to: +```js +const WSClient = require('./test/temp/snapshotTestResult/client-postman/client.js'); +``` >You will see the example still works, but now it is using a different API. This is possible since both AsyncAPI documents define the same operation name for sending messages: `sendEchoMessage`, so each client generated has the same API.🧰 Tools
🪛 LanguageTool
[uncategorized] ~9-~9: Did you mean: “By default,”?
Context: ...rated by the test:node example.js> By default this is testing against Postman echo se...(BY_DEFAULT_COMMA)
[uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...in. You will see the example still works but now it is using a different API. This i...(COMMA_COMPOUND_SENTENCE)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/templates/clients/websocket/javascript/README.md(1 hunks)packages/templates/clients/websocket/javascript/example.js(2 hunks)packages/templates/clients/websocket/javascript/test/integration.test.js(4 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/templates/clients/websocket/javascript/example.js
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/templates/clients/websocket/javascript/test/integration.test.js
🧰 Additional context used
🪛 LanguageTool
packages/templates/clients/websocket/javascript/README.md
[uncategorized] ~9-~9: Did you mean: “By default,”?
Context: ...rated by the test: node example.js > By default this is testing against Postman echo se...
(BY_DEFAULT_COMMA)
[uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...in. You will see the example still works but now it is using a different API. This i...
(COMMA_COMPOUND_SENTENCE)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Test generator as dependency with Node 20
- GitHub Check: Test generator as dependency with Node 18
🔇 Additional comments (1)
packages/templates/clients/websocket/javascript/README.md (1)
9-9: Correct Postman client require path to match new file structure
The updated path./test/temp/snapshotTestResult/client-postman/client.jsaligns with the reorganized output directory and ensures thatexample.jswill correctly load the generated Postman client.🧰 Tools
🪛 LanguageTool
[uncategorized] ~9-~9: Did you mean: “By default,”?
Context: ...rated by the test:node example.js> By default this is testing against Postman echo se...(BY_DEFAULT_COMMA)
[uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...in. You will see the example still works but now it is using a different API. This i...(COMMA_COMPOUND_SENTENCE)
| 4. Start example script that uses a client library generated by the test: `node example.js` | ||
|
|
||
| > By default this is testing against Hoppscotch echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change first line to `const WSClient = require('./tests/temp/snapshotTestResult/client-postman.js');` and run `node example.js` again. You will see example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage` so each client generated has the same API. No newline at end of file | ||
| > By default this is testing against Postman echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change the first line to `const WSClient = require('./test/temp/snapshotTestResult/client-postman/client.js');` and run `node example.js` again. You will see the example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage`, so each client generated has the same API. |
There was a problem hiding this comment.
@Light13008 actually in example.js it is discussed to keep HoppscotchClient generate by custom-client.
Discussion - #1513 (review)
| @@ -1,4 +1,6 @@ | |||
| const WSClient = require('./test/temp/snapshotTestResult/custom-client-hoppscotch.js'); | |||
|
|
|||
| const WSClient = require('./test/temp/snapshotTestResult/client-postman/client.js'); | |||
There was a problem hiding this comment.
Change import also accordingly.
| const testResultPathPostman = path.join(testResultPath, 'client-postman'); | ||
| const testResultPathHoppscotch = path.join(testResultPath, 'client-hoppscotch'); | ||
| const testResultPathClient = path.join(testResultPath, 'client'); | ||
| const template = path.resolve(__dirname, '../'); |
There was a problem hiding this comment.
add const testResultPathCustomHoppscotch = path.join(testResultPath, 'custom_client_hoppscotch'); and change path in below testcase also where you are generating custom path.
For ref - #1513
you can also see other websocket integration test.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/templates/clients/websocket/javascript/README.md (1)
9-9: Improve clarity and punctuation in the instruction.Add a comma after “By default”, a comma before “but” in the second sentence, and consider adding “the” before “Hoppscotch echo service” for consistency. For example:
- > By default this is testing against Hoppscotch echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change the first line to `const WSClient = require('./test/temp/snapshotTestResult/custom-client-hoppscotch.js');` and run `node example.js` again. You will see the example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage`, so each client generated has the same API. + > By default, this is testing against the Hoppscotch echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change the first line to: + > + > ```js + > const WSClient = require('./test/temp/snapshotTestResult/custom-client-hoppscotch.js'); + > ``` + > + > Then run `node example.js` again. You will see the example still works, but now it is using a different API. This is possible since both AsyncAPI documents define the same operation name for sending messages (`sendEchoMessage`), so each generated client has the same API. <details> <summary>🧰 Tools</summary> <details> <summary>🪛 LanguageTool</summary> [uncategorized] ~9-~9: Did you mean: “By default,”? Context: ...rated by the test: `node example.js` > By default this is testing against Hoppscotch echo... (BY_DEFAULT_COMMA) --- [uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short). Context: ...in. You will see the example still works but now it is using a different API. This i... (COMMA_COMPOUND_SENTENCE) </details> </details> </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between f87f1c2b91f014f96639bc787a26caece848e15d and d666c5c92dd37fd0c6677de1cc1ec7d501a01af1. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `packages/templates/clients/websocket/javascript/README.md` (1 hunks) * `packages/templates/clients/websocket/javascript/example.js` (2 hunks) * `packages/templates/clients/websocket/javascript/test/integration.test.js` (5 hunks) </details> <details> <summary>✅ Files skipped from review due to trivial changes (1)</summary> * packages/templates/clients/websocket/javascript/example.js </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary> * packages/templates/clients/websocket/javascript/test/integration.test.js </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🪛 LanguageTool</summary> <details> <summary>packages/templates/clients/websocket/javascript/README.md</summary> [uncategorized] ~9-~9: Did you mean: “By default,”? Context: ...rated by the test: `node example.js` > By default this is testing against Hoppscotch echo... (BY_DEFAULT_COMMA) --- [uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short). Context: ...in. You will see the example still works but now it is using a different API. This i... (COMMA_COMPOUND_SENTENCE) </details> </details> </details> <details> <summary>⏰ Context from checks skipped due to timeout of 90000ms (2)</summary> * GitHub Check: Test generator as dependency with Node 20 * GitHub Check: Test generator as dependency with Node 18 </details> <details> <summary>🔇 Additional comments (1)</summary><blockquote> <details> <summary>packages/templates/clients/websocket/javascript/README.md (1)</summary> `9-9`: <details> <summary>❓ Verification inconclusive</summary> **Verify the example.js require path matches the actual generated output.** Ensure that `custom-client-hoppscotch.js` exists under `test/temp/snapshotTestResult`. If the directory or filename differs (e.g., `client-hoppscotch/client.js`), update the path accordingly. --- 🏁 Script executed: ```shell #!/bin/bash # Verify the presence and path of the generated Hoppscotch client file fd custom-client-hoppscotch.js packages/templates/clients/websocket/javascriptLength of output: 80
🏁 Script executed:
#!/bin/bash # List any snapshotTestResult directories and their JavaScript contents find packages/templates/clients/websocket/javascript -type d -name 'snapshotTestResult' -exec echo "Directory: {}" \; -exec find {} -maxdepth 1 -type f -name '*.js' -print \; # Search the entire repo for the expected generated file fd custom-client-hoppscotch.js . # As a fallback, list all files under test/temp to see actual names find packages/templates/clients/websocket/javascript/test/temp -type f -printLength of output: 386
Confirm README require path for generated client
I couldn’t locatecustom-client-hoppscotch.jsunderpackages/templates/clients/websocket/javascript/test/temp/snapshotTestResult. Please verify the actual generated file name and its relative path, then update the example in the README accordingly.Locations to review:
- packages/templates/clients/websocket/javascript/README.md (line 9)
Suggested diff if the path differs:
- const WSClient = require('./test/temp/snapshotTestResult/custom-client-hoppscotch.js'); + const WSClient = require('<correct/relative/path/to/generated-client.js>');🧰 Tools
🪛 LanguageTool
[uncategorized] ~9-~9: Did you mean: “By default,”?
Context: ...rated by the test:node example.js> By default this is testing against Hoppscotch echo...(BY_DEFAULT_COMMA)
[uncategorized] ~9-~9: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...in. You will see the example still works but now it is using a different API. This i...(COMMA_COMPOUND_SENTENCE)
| @@ -1,4 +1,6 @@ | |||
|
|
|||
| const WSClient = require('./test/temp/snapshotTestResult/custom-client-hoppscotch.js'); | |||
There was a problem hiding this comment.
according to me we are generating clients inside folders then custom_client_hoppscotch should be folder and inside it will have client.js just like other clients than how this import is working?
you can look at other clients.
| 4. Start example script that uses a client library generated by the test: `node example.js` | ||
|
|
||
| > By default this is testing against Hoppscotch echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change first line to `const WSClient = require('./tests/temp/snapshotTestResult/client-postman.js');` and run `node example.js` again. You will see example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage` so each client generated has the same API. No newline at end of file | ||
| > By default this is testing against Hoppscotch echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change the first line to `const WSClient = require('./test/temp/snapshotTestResult/custom-client-hoppscotch.js');` and run `node example.js` again. You will see the example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage`, so each client generated has the same API. |
There was a problem hiding this comment.
just small change by default this is testing against Hoppscotch echo service then in changes we should give Postman.
Changes - the first line to const WSClient = require('./test/temp/snapshotTestResult/client_postman/client.js');
just read complete instruction once and you will understand what I am trying to say.
There was a problem hiding this comment.
yup, postman, not custom-client-hoppscotch.js
|
|
||
| it('generate simple client for hoppscotch echo', async () => { | ||
| const testOutputFile = 'client-hoppscotch.js'; | ||
| const testOutputFile = 'custom-client-hoppscotch.js'; |
There was a problem hiding this comment.
I think we should keep consistency in testing across clients. So keep structure similar like other clients where we created folder and inside it always client.js file.
Just refer to other clients generated structure and you will get better idea.
There was a problem hiding this comment.
I would leave it for now. These integration tests are over duplicated.
I already tried to generalize a bit, and introduces listFiles in my latest PR: https://github.com/asyncapi/generator/blob/master/packages/templates/clients/websocket/python/test/integration.test.js#L35
we need a separate issue that experiments how we can have one integration.test.js for all clients
|
@derberg in integration.test.js for
so my question is are we considering to write testcases for all params or for now simplicity it is fine to remove testcases for params and only 3 testcases. Then we can remove above mention 2 testcases I mention in this comment. wdyt 🤔? |
|
@Adi-204 I don't think this is in scope of this PR. Please look at #1476 (comment) -> imho we need separate discussion |
|
@derberg yeah I just dropped my thoughts we can create a discussion issue |
|
@Light13008 there is one readme comment you need to address and sorry for changing my mind, I misunderstood it initially, I agree with @Adi-204 regarding the output structure, each should be in individual folder, so instead of |
|
@derberg @Adi-204 , sorry for the delay, i will be starting to work as soon i get a final go from anyone of you. asking this because the comment history has created a lot of chaos 😨 |
|
@Light13008 you need to do following changes -
So basically I would suggest to have a look at python integration test and majority of code will be just copy and paste but we are going to solve this code duplication in "other PR" (not in the scope of the issue this PR is solving). In js integration test we do have 2 extra testcases for params but don't change anything in those for now. It is not in the scope of the issue this PR is solving, we can discuss it in issue - #1549 |
|
@Light13008 some of the scope, related to acceptance test will be solved with #1552 so wait until this PR is merged and then just fix the structure discussed above |
|
|
closing this PR |



Description
-This PR follows the new file structure and all the necessary endpoints were updated.
-Only updated for javascript.
-
postman-clientandhoppscotch-clientwere added with respectiveREADME.md-To work on echo we first need to adapt to the new file structure.
-Old pr made on this had to be canceled because of sudden update in file structure.
Fixes #1373
Related issue(s)
Fixes #1373Summary by CodeRabbit
Documentation
Bug Fixes
Tests