Skip to content

🐛 Bug: beta versions should use semver-style dot numeric separator (instead of dash) #5763

@AviVahl

Description

@AviVahl

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

Using caret with a beta version should pick up newer beta.

Actual

12.0.0-beta-10 is NOT matched by "^12.0.0-beta-9 (or even "^12.0.0-beta-10" 🤯 )

Minimal, Complete and Verifiable Example

mkdir semver-behavior
cd semver-behavior
npm init -y
npm pkg set type=module
npm i semver
echo "import { gt } from 'semver'; console.log('12.0.0-beta-10 > 12.0.0-beta-9', gt('12.0.0-beta-10', '12.0.0-beta-9')); console.log('12.0.0-beta.10 > 12.0.0-beta.9', gt('12.0.0-beta.10', '12.0.0-beta.9'));" > main.js
node main.js

prints:

12.0.0-beta-10 > 12.0.0-beta-9 false
12.0.0-beta.10 > 12.0.0-beta.9 true

Versions

12.0.0-beta-*

Additional Info

semver, which is used by npm and many other packages, treats - differently from .

I believe it treats dot as a separator, parsing the numeric digits after it as a number, while it treats the dash as regular alphabet, sorting 10 before 9.

Neat one, isn't it?

Metadata

Metadata

Labels

status: accepting prsMocha can use your help with this one!type: buga defect, confirmed by a maintainer

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions