Skip to content

Add prerelease version edge case tests #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

BelfordZ
Copy link
Contributor

@BelfordZ BelfordZ commented May 22, 2025

User description

Summary

  • cover additional prerelease edge cases in version utilities

Testing

  • npm test

PR Type

Tests


Description

  • Add tests for prerelease version parsing edge cases

  • Test comparison logic for prerelease zero and invalid numbers

  • Validate prerelease handling in min/max version checks

  • Ensure errors are thrown for invalid prerelease formats


Changes walkthrough 📝

Relevant files
Tests
version.test.ts
Add prerelease edge case tests for version utilities         

test/unit/src/utils/functions/version.test.ts

  • Added tests for parsing prerelease zero and invalid prerelease numbers
  • Added comparison tests for prerelease versions around zero
  • Added validation tests for prerelease numbers in min/max version
    checks
  • Ensured invalid prerelease formats throw errors
  • +44/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🏅 Score: 97
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Test Coverage

    The new tests cover edge cases for prerelease version parsing and comparison. Ensure that all relevant edge cases, including negative and non-numeric prerelease values, are sufficiently covered and that error handling is robust.

    describe('Prerelease edge cases', () => {
      it('should parse prerelease zero and reject invalid prerelease numbers', () => {
        expect(parseSemVersion('1.0.0-prerelease.0')).toEqual({
          major: 1,
          minor: 0,
          patch: 0,
          prerelease: { number: 0 },
        })
    
        expect(() => parseSemVersion('1.0.0-prerelease.-1')).toThrow()
        expect(() => parseSemVersion('1.0.0-prerelease.not')).toThrow()
      })
    
      it('should compare prerelease versions around zero correctly', () => {
        expect(
          compareSemVersions(
            { major: 1, minor: 0, patch: 0, prerelease: { number: 0 } },
            { major: 1, minor: 0, patch: 0, prerelease: { number: 1 } }
          )
        ).toBe(VersionComparisonResult.LessThan)
    
        expect(
          compareSemVersions(
            { major: 1, minor: 0, patch: 0 },
            { major: 1, minor: 0, patch: 0, prerelease: { number: 0 } }
          )
        ).toBe(VersionComparisonResult.GreaterThan)
      })
    
      it('should validate prerelease numbers when checking min/max versions', () => {
        expect(
          meetsMinimumVersion('1.0.0-prerelease.0', '1.0.0-prerelease.1')
        ).toBe(VersionValidationResult.Success)
    
        expect(
          isWithinMaximumVersion('1.0.0-prerelease.1', '1.0.0-prerelease.0')
        ).toBe(VersionValidationResult.Success)
    
        expect(
          isWithinMaximumVersion('1.0.0-prerelease.1', '1.0.0')
        ).toBe(VersionValidationResult.ComparisonFailed)
      })
    })

    Copy link

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant