jmlue42 / spectral-jsonapi-ruleset

A Stoplight/Spectral linting ruleset for the JSON:API specification.
MIT License
12 stars 8 forks source link

Refactor and Extend jsonapi-query-parameters Test Suite #44

Closed ezenity closed 11 months ago

ezenity commented 1 year ago

This commit encompasses a comprehensive refactoring and extension of the test suite for the jsonapi-query-parameters ruleset. The following changes have been made:

  1. Common Setup: Moved the common setup logic into a beforeEach block to avoid redundancy. The Spectral ruleset is now set up once for all test cases.

    • Original: Separate Spectral object initialization in each test case.
    • Current: Unified Spectral object initialization in beforeEach.
  2. Async/Await: Replaced callback-based asynchronous code with async/await for better readability and error handling.

    • Original: Used done() callbacks.
    • Current: Using async/await.
  3. Parameterized Test Cases: Introduced parameterized test cases for different scenarios, making the test suite more exhaustive.

    • Original: Limited test cases with less coverage for edge cases.
    • Current: Added test cases for valid and invalid query parameters, including special characters and numbers.
  4. Error Handling: Improved error handling by throwing errors and providing detailed error messages.

    • Original: Used done(error) for error handling.
    • Current: Using throw new Error(error).
  5. Error Verification: Added checks for error codes and severity levels, ensuring that the right types of errors are being thrown.

    • Original: Only checked the length of the results array.
    • Current: Checks for specific error codes and severity levels.
  6. Code Comments: Added comments to describe the purpose and context of each test case.

    • Original: Minimal comments.
    • Current: Detailed comments explaining what each test case is doing and why.
  7. Code Formatting: Improved code formatting and structure for better readability.

    • Original: Less structured code.
    • Current: Well-structured and formatted code.

By making these changes, the test suite is now more robust, easier to understand, and covers more edge cases. This sets a strong foundation for future development and debugging.

jmlue42 commented 11 months ago

@ezenity thank you for your submission. Currently tests not passing.

ezenity commented 11 months ago

@ezenity thank you for your submission. Currently tests not passing.

I did same manual testing to see if I could reproduce this failed workflow. Here are my results.

Build (18.x) image

Build (16.x) image

After doing further analysis, I found what is causing this error.

I am using features from ES2017 (ie. async/await) and possibly features from ES2020. Since ESLint is complaining about syntax it doesn't understand, my assumption is it is linting against ES6 features only. By setting a specific supported ecmaVersion, this would resolve error message.

I will push the change to .eslintrc.yml

ezenity commented 11 months ago

Enabled Actions on forked repo and confirmed both workflows pass successfully:

image