Files
meteor/packages/package-version-parser/package-version-parser-tests.js
David Glasser 43e01c09eb Improve treatment of prerelease (dashed) packages
Drop the "at-least" constraint type entirely. It was not user-accessible
and was only used in the form ">=0.0.0" to represent a constraint with
no version constraint at all. This type of constraint is now called
"any-reasonable".

The definition of "any-reasonable" is:

  - Any version that is not a pre-release (has no dash)
  - Or a pre-release version that is explicitly mentioned in a TOP-LEVEL
    constraint passed to the constraint solver

For example, constraints from .meteor/packages, constraints from the
release, and constraints from the command line of "meteor add" end up
being top-level.

Why only top-level-constrained pre-release versions, and not versions we
find explicitly desired by some other desired version while walking the
graph?

The constraint solver assumes that adding a constraint to the resolver
state can't make previously impossible choices now possible.  If
pre-releases mentioned anywhere worked, then applying the constraints
"any reasonable" followed by "1.2.3-rc1" would result in "1.2.3-rc1"
ruled first impossible and then possible again. That's no good, so we
have to fix the meaning based on something at the start.  (We could try
to apply our prerelease-avoidance tactics solely in the cost functions,
but then it becomes a much less strict rule.)

At the very least, this change should allow you to run meteor on a
preview branch like cordova-hcp without getting a conflict between the
prerelease package on the branch/release and the lack of an explicit
constraint in .meteor/packages on that package, because we are
reintepreting the .meteor/packages constraint as meaning "anything
reasonable" and the in-the-release version counts as reasonable.
2014-08-26 21:54:48 -07:00

73 lines
2.0 KiB
JavaScript

var currentTest = null;
var t = function (versionString, expected, descr) {
currentTest.equal(
_.omit(PackageVersion.parseConstraint(versionString),
'constraintString'),
expected,
descr);
};
var FAIL = function (versionString) {
currentTest.throws(function () {
PackageVersion.parseConstraint(versionString);
});
};
Tinytest.add("Smart Package version string parsing - old format", function (test) {
currentTest = test;
t("foo", { name: "foo", version: null, type: "any-reasonable" });
t("foo-1234", { name: "foo-1234", version: null, type: "any-reasonable" });
FAIL("my_awesome_InconsitentPackage123");
});
Tinytest.add("Smart Package version string parsing - compatible version, compatible-with", function (test) {
currentTest = test;
t("foo@1.2.3", { name: "foo", version: "1.2.3", type: "compatible-with" });
t("foo-1233@1.2.3", { name: "foo-1233", version: "1.2.3", type: "compatible-with" });
t("foo-bar@3.2.1", { name: "foo-bar", version: "3.2.1", type: "compatible-with" });
FAIL("42@0.2.0");
FAIL("foo@1.2.3.4");
FAIL("foo@1.4");
FAIL("foo@1");
FAIL("foo@");
FAIL("foo@@");
FAIL("foo@x.y.z");
FAIL("foo@<1.2");
FAIL("foo<1.2");
t("foo", { name: "foo", version: null, type: "any-reasonable" });
});
Tinytest.add("Smart Package version string parsing - compatible version, exactly", function (test) {
currentTest = test;
t("foo@=1.2.3", { name: "foo", version: "1.2.3", type: "exactly" });
t("foo-bar@=3.2.1", { name: "foo-bar", version: "3.2.1", type: "exactly" });
FAIL("42@=0.2.0");
FAIL("foo@=1.2.3.4");
FAIL("foo@=1.4");
FAIL("foo@=1");
FAIL("foo@@=");
FAIL("foo@=@");
FAIL("foo@=x.y.z");
FAIL("foo@=<1.2");
FAIL("foo@<=1.2");
FAIL("foo<=1.2");
// We no longer support @>=.
FAIL("foo@>=1.2.3");
FAIL("foo-bar@>=3.2.1");
FAIL("42@>=0.2.0");
FAIL("foo@>=1.2.3.4");
FAIL("foo@>=1.4");
FAIL("foo@>=1");
FAIL("foo@@>=");
FAIL("foo@>=@");
FAIL("foo@>=x.y.z");
FAIL("foo@=>12.3.11");
});