[test]:Add missing tests for input validation and error wrapping in utilis.js
The utility function parseAsyncAPIDocumentFromFile contains non-trivial control flow that is currently not fully covered by tests, specifically around input validation and error handling.
While the happy path (successful parsing) is exercised indirectly via higher-level tests, two important behaviors remain unverified:
Input validation logic The function explicitly guards against invalid asyncapiFilepath values (non-string or empty/whitespace strings), but there are no direct tests asserting that these cases throw the expected error.
Error wrapping when parsing fails When the underlying AsyncAPI parser throws, the function catches the error and rethrows a new error with a normalized message. This wrapping behavior defines part of the public error contract, but it is currently untested.
Affected file :-generator\apps\keeper\src\utils.js
There are two missing test areas for parseAsyncAPIDocumentFromFile: input validation and error wrapping. For input validation, you should test that passing a non-string, empty string, or whitespace-only string as asyncapiFilepath throws an error with the message: Invalid "asyncapiFilepath" parameter: must be a non-empty string, received ${asyncapiFilepath} cite. For error wrapping, you should simulate the underlying parser throwing (e.g., by mocking fromFile().parse to reject) and assert that the function throws an error with the message: Failed to parse AsyncAPI document: ${error.message}.
You can add these tests in a new apps/keeper/test/utils.test.js or as a new describe block in the existing test file. Use Jest’s .toThrow for sync cases and .rejects.toThrow for async cases. For error wrapping, use jest.mock to force the parser to throw, then check that the error message is normalized as expected. This matches the patterns already used in the codebase for testing error handling and input validation.
Let me know if you want concrete code examples for these test cases.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
@moksha-hub please read the guidelines let the issue be approved also I have shown interest to solve the issue so please close you PR , Thanks.
@SHUBHANSHU602 the issue is valid you can work on it create a new file test folder utils.test.js. Do drop comment if you are working on it or not!
yes @Adi-204 I am working on it.
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.
Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.
Thank you for your patience :heart:
/approve
👋 Thanks for your patience. This issue has been reviewed and is ready to be worked on.
Before you start:
- Comment below to let others know you're working on it (avoids duplicate work)
- Read our CONTRIBUTING.md if you haven't already
- Fork the repo, create a feature branch, and open a draft PR early
Approved by @derberg