Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import path from 'path';
import { render } from '@asyncapi/generator-react-sdk';
import { Parser, fromFile } from '@asyncapi/parser';
import TimedConnection from '../../components/TimedConnection.js';

const parser = new Parser();
const asyncapiFilePath = path.resolve(__dirname, '../../../../test/__fixtures__/asyncapi-websocket-components.yml');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# 1. Search for the fixture file
echo "=== Searching for asyncapi-websocket-components.yml ==="
fd "asyncapi-websocket-components.yml" --type f 2>/dev/null || echo "File not found with fd"

# 2. Look for package.json in the quarkus directory and check it
echo -e "\n=== Checking package.json in quarkus package ==="
if [ -f packages/templates/clients/websocket/java/quarkus/package.json ]; then
  cat packages/templates/clients/websocket/java/quarkus/package.json
else
  echo "Not found at expected location"
fi

# 3. Check parent package.json files for module configuration
echo -e "\n=== Checking parent package.json files ==="
for pkgjson in packages/package.json packages/templates/package.json packages/templates/clients/package.json packages/templates/clients/websocket/package.json; do
  if [ -f "$pkgjson" ]; then
    echo "--- $pkgjson ---"
    cat "$pkgjson" | head -20
  fi
done

# 4. Check how other test files in the package handle __dirname
echo -e "\n=== Other test files in the quarkus package ==="
fd "\.test\.js$" packages/templates/clients/websocket/java/quarkus/ --type f

Repository: asyncapi/generator

Length of output: 2895


🏁 Script executed:

#!/bin/bash

# Check a couple of other test files to see if they use __dirname in the same way
echo "=== Checking ClientConnector.test.js ==="
head -20 packages/templates/clients/websocket/java/quarkus/test/components/ClientConnector.test.js

echo -e "\n=== Checking EchoWebSocket.test.js ==="
head -20 packages/templates/clients/websocket/java/quarkus/test/components/EchoWebSocket.test.js

# Also check the full TimedConnection.test.js to see the JSDoc situation
echo -e "\n=== Full TimedConnection.test.js ==="
cat -n packages/templates/clients/websocket/java/quarkus/test/components/TimedConnection.test.js

# Check if there's a jest.config.js or similar
echo -e "\n=== Jest configuration ==="
fd "jest.config" packages/templates/clients/websocket/java/quarkus/ --type f
if [ -f packages/templates/clients/websocket/java/quarkus/jest.config.js ]; then
  cat packages/templates/clients/websocket/java/quarkus/jest.config.js
fi

Repository: asyncapi/generator

Length of output: 4085


Add JSDoc comments for test functions and beforeAll callback to comply with coding guidelines.

The fixture path is correct—the file exists at packages/templates/clients/websocket/test/__fixtures__/asyncapi-websocket-components.yml and the path resolution from test/components/ is accurate. __dirname is also available: this project uses Babel transformation via babel-jest (configured in jest.config.js), which converts ES modules to CommonJS at runtime, making __dirname accessible. Other test files in the same directory (ClientConnector.test.js, EchoWebSocket.test.js) already use this identical pattern successfully.

However, the file lacks JSDoc comments for functions as required by the coding guidelines. Add JSDoc to:

  • The beforeAll callback (lines 13–18): describe what it does, that it's async, return type
  • Each test() callback (lines 20–51): describe what each test verifies
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/templates/clients/websocket/java/quarkus/test/components/TimedConnection.test.js`
at line 7, Add JSDoc comments above the beforeAll callback and each test
callback in TimedConnection.test.js: for the beforeAll callback (the async setup
function) add a JSDoc block describing that it initializes test fixtures and is
asynchronous, include `@async` and `@returns` {Promise<void>}; for each test()
callback add a JSDoc block that succinctly states what the test verifies (e.g.,
verifies connection establishment, message timing, or teardown behavior),
include `@async` if the test callback is async and `@returns` {Promise<void>} for
consistency; place the comments immediately above the beforeAll and each
test(...) so linters and coding guidelines recognize them.


describe('TimedConnection component (integration with AsyncAPI document)', () => {
let parsedAsyncAPIDocument;
let sendOperations;

beforeAll(async () => {
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
parsedAsyncAPIDocument = parseResult.document;
const operations = parsedAsyncAPIDocument.operations();
sendOperations = operations.filterBySend();
});
Comment on lines +13 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

beforeAll failure cascades to fixture-independent tests; add a document guard.

Two issues in this block:

  1. Missing validity guard: parseResult.document is undefined when the AsyncAPI document is invalid. Calling .operations() on it will throw a TypeError, making the error misleading. Add a guard:

    expect(parsedAsyncAPIDocument).toBeDefined();
  2. Unnecessary coupling: Tests 1–3 pass null, undefined, and [] directly and never read sendOperations. Because they share this describe/beforeAll, a fixture-load failure will fail them too, masking what actually broke. Consider moving them into a sibling describe block without a beforeAll, or into a nested describe that skips setup.

♻️ Proposed restructuring
-describe('TimedConnection component (integration with AsyncAPI document)', () => {
-  let parsedAsyncAPIDocument;
-  let sendOperations;
-
-  beforeAll(async () => {
-    const parseResult = await fromFile(parser, asyncapiFilePath).parse();
-    parsedAsyncAPIDocument = parseResult.document;
-    const operations = parsedAsyncAPIDocument.operations();
-    sendOperations = operations.filterBySend();
-  });
-
-  test('renders generic message when sendOperations is null', () => { ... });
-  test('renders generic message when sendOperations is undefined', () => { ... });
-  test('renders generic message when sendOperations is empty array', () => { ... });
-  test('renders specific message with operationId when sendOperations has data from fixture', () => { ... });
-});
+describe('TimedConnection component', () => {
+  describe('without fixture — edge cases', () => {
+    test('renders generic message when sendOperations is null', () => { ... });
+    test('renders generic message when sendOperations is undefined', () => { ... });
+    test('renders generic message when sendOperations is empty array', () => { ... });
+  });
+
+  describe('integration with AsyncAPI document', () => {
+    let parsedAsyncAPIDocument;
+    let sendOperations;
+
+    beforeAll(async () => {
+      const parseResult = await fromFile(parser, asyncapiFilePath).parse();
+      parsedAsyncAPIDocument = parseResult.document;
+      expect(parsedAsyncAPIDocument).toBeDefined();
+      sendOperations = parsedAsyncAPIDocument.operations().filterBySend();
+    });
+
+    test('renders specific message with operationId when sendOperations has data from fixture', () => { ... });
+  });
+});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/templates/clients/websocket/java/quarkus/test/components/TimedConnection.test.js`
around lines 13 - 18, Add a validity guard after parsing in the beforeAll so
parsedAsyncAPIDocument is asserted before calling
parsedAsyncAPIDocument.operations() (e.g., add
expect(parsedAsyncAPIDocument).toBeDefined()); and remove the coupling of the
three fixture-independent tests from this describe that uses beforeAll by
relocating those tests (the ones that call with null/undefined/[]) into a
sibling describe or a nested describe without the beforeAll so failures parsing
in beforeAll do not cascade to tests that don’t use sendOperations (references:
beforeAll, parsedAsyncAPIDocument, sendOperations).


test('renders generic message when sendOperations is null', () => {
const result = render(
<TimedConnection
sendOperations={null}
/>
);
expect(result.trim()).toMatchSnapshot();
});

test('renders generic message when sendOperations is undefined', () => {
const result = render(
<TimedConnection />
);
expect(result.trim()).toMatchSnapshot();
});

test('renders generic message when sendOperations is empty array', () => {
const result = render(
<TimedConnection
sendOperations={[]}
/>
);
expect(result.trim()).toMatchSnapshot();
});

test('renders specific message with operationId when sendOperations has data from fixture', () => {
const result = render(
<TimedConnection
sendOperations={sendOperations}
/>
);
expect(result.trim()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TimedConnection component (integration with AsyncAPI document) renders generic message when sendOperations is empty array 1`] = `
"WebSocketClientConnection connection = connector.connectAndAwait();
// Wait 2 seconds before first message
Thread.sleep(2000);
// Send 5 messages
for (int i = 1; i <= 5; i++) {
// Send a message to any available operation by including its operation ID (i.e. \\"null\\")
String msg = \\"Message #\\" + i + \\" from Quarkus\\";
connection.sendTextAndAwait(msg);
Log.info(\\"Sent: \\" + msg);
Thread.sleep(5000); // Wait 5 seconds between messages
}
// Wait 10 seconds after final message
Log.info(\\"All messages sent. Waiting 10 seconds before closing...\\");
Thread.sleep(10000);"
`;

exports[`TimedConnection component (integration with AsyncAPI document) renders generic message when sendOperations is null 1`] = `
"WebSocketClientConnection connection = connector.connectAndAwait();
// Wait 2 seconds before first message
Thread.sleep(2000);
// Send 5 messages
for (int i = 1; i <= 5; i++) {
// Send a message to any available operation by including its operation ID (i.e. \\"null\\")
String msg = \\"Message #\\" + i + \\" from Quarkus\\";
connection.sendTextAndAwait(msg);
Log.info(\\"Sent: \\" + msg);
Thread.sleep(5000); // Wait 5 seconds between messages
}
// Wait 10 seconds after final message
Log.info(\\"All messages sent. Waiting 10 seconds before closing...\\");
Thread.sleep(10000);"
`;

exports[`TimedConnection component (integration with AsyncAPI document) renders generic message when sendOperations is undefined 1`] = `
"WebSocketClientConnection connection = connector.connectAndAwait();
// Wait 2 seconds before first message
Thread.sleep(2000);
// Send 5 messages
for (int i = 1; i <= 5; i++) {
// Send a message to any available operation by including its operation ID (i.e. \\"null\\")
String msg = \\"Message #\\" + i + \\" from Quarkus\\";
connection.sendTextAndAwait(msg);
Log.info(\\"Sent: \\" + msg);
Thread.sleep(5000); // Wait 5 seconds between messages
}
// Wait 10 seconds after final message
Log.info(\\"All messages sent. Waiting 10 seconds before closing...\\");
Thread.sleep(10000);"
`;

exports[`TimedConnection component (integration with AsyncAPI document) renders specific message with operationId when sendOperations has data from fixture 1`] = `
"WebSocketClientConnection connection = connector.connectAndAwait();
// Wait 2 seconds before first message
Thread.sleep(2000);
// Send 5 messages
for (int i = 1; i <= 5; i++) {
// Send a message to any available operation by including its operation ID (i.e. \\"sendMessage\\")
String msg = \\"Message #\\" + i + \\" from Quarkus for sendMessage\\";
connection.sendTextAndAwait(msg);
Log.info(\\"Sent: \\" + msg);
Thread.sleep(5000); // Wait 5 seconds between messages
}
// Wait 10 seconds after final message
Log.info(\\"All messages sent. Waiting 10 seconds before closing...\\");
Thread.sleep(10000);"
`;