Skip to content

Commit 8eb5443

Browse files
authored
Adding baseVersionForMinCompat for min compat version testing (#20060)
Every time we release, the base version in which N-i calculations are based changes. This causes issues at testing specially at bumping the release version. By hard coding the version in which these calculations are made, we decoupled the min version testing from the release process, although we will need to update this hard coded value shortly after the release as after work to make sure that min versions are going to work with the new version. I really believe this is the best attempt so far to test this functionality, given that it's a middle ground between both contending arguments of making the tests deterministic and at the same time not requiring too much of maintenance.
1 parent 921d486 commit 8eb5443

File tree

3 files changed

+53
-38
lines changed

3 files changed

+53
-38
lines changed

packages/test/test-version-utils/src/baseVersion.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ export const baseVersion = resolveVersion(
4040
false,
4141
);
4242

43+
/**
44+
* Base version used for N min compat versions calculations. Decoupled from baseVersion or codeVersion to avoid
45+
* running with issues while bumping a new version or releasing.
46+
*
47+
* @internal
48+
*/
49+
export const baseVersionForMinCompat = "2.0.0-rc.2.0.0";
4350
/**
4451
* The problem with just using the code version, is that the current version in the test is actually 0.0.0-xyz-test
4552
* we want to tell the test to use 0.0.0-xyz-test as the current version. If we are asking for an N-1 version, that

packages/test/test-version-utils/src/compatConfig.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ import {
1717
} from "../compatOptions.cjs";
1818
import { ensurePackageInstalled } from "./testApi.js";
1919
import { pkgVersion } from "./packageVersion.js";
20-
import { baseVersion, codeVersion, testBaseVersion } from "./baseVersion.js";
20+
import {
21+
baseVersion,
22+
baseVersionForMinCompat,
23+
codeVersion,
24+
testBaseVersion,
25+
} from "./baseVersion.js";
2126
import { getRequestedVersion } from "./versionUtils.js";
2227

2328
/**
@@ -253,7 +258,7 @@ export function isCompatVersionBelowMinVersion(minVersion: string, config: Compa
253258
? (config.loadVersion as string)
254259
: config.compatVersion;
255260
}
256-
const compatVersion = getRequestedVersion(testBaseVersion(lowerVersion), lowerVersion);
261+
const compatVersion = getRequestedVersion(baseVersionForMinCompat, lowerVersion);
257262
const minReqVersion = getRequestedVersion(testBaseVersion(minVersion), minVersion);
258263
return semver.compare(compatVersion, minReqVersion) < 0;
259264
}

packages/test/test-version-utils/src/test/minCompatVersion.spec.ts

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,15 @@
66
import { strict as assert } from "assert";
77
import { CompatKind } from "../../compatOptions.cjs";
88
import { isCompatVersionBelowMinVersion } from "../compatConfig.js";
9-
import { pkgVersion } from "../packageVersion.js";
10-
import { getRequestedVersion } from "../versionUtils.js";
11-
import { testBaseVersion } from "../baseVersion.js";
12-
13-
function transformVersion(version: string): string {
14-
const regex = /(\d+)\.(\d+)\.(\d+)-dev-(\w+)\.(\d+)\.(\d+)\.(\d+)\.\d+/;
15-
const matches = version.match(regex);
16-
17-
if (matches) {
18-
const [, major, minor, patch, label, num1, num2, num3] = matches;
19-
return `${major}.${minor}.${patch}-${label}.${num1}.${num2}.${num3}`;
20-
} else {
21-
return version;
22-
}
23-
}
9+
import { baseVersionForMinCompat } from "../baseVersion.js";
2410

2511
describe("Minimum Compat Version", () => {
26-
const minTestVersion = transformVersion(pkgVersion);
2712
const numCompatVersions = 9;
13+
const oldVersion = "1.3.7";
14+
// for cross compat unit testing
15+
const greaterVersion = "2.0.0-rc.1.0.0";
16+
const lowerVersion = "1.3.7";
17+
2818
it("bad min compat string", () => {
2919
const invalidString = "invalid string";
3020
assert.throws(
@@ -45,67 +35,80 @@ describe("Minimum Compat Version", () => {
4535
);
4636
});
4737

38+
// Making sure all previous versions get filtered.
4839
for (let i = 1; i < numCompatVersions; i++) {
49-
it(`compatVersion N-${i} < ${minTestVersion}`, () => {
40+
it(`compatVersion N-${i} < ${baseVersionForMinCompat}`, () => {
5041
assert.strictEqual(
51-
isCompatVersionBelowMinVersion(minTestVersion, {
42+
isCompatVersionBelowMinVersion(baseVersionForMinCompat, {
5243
name: `test`,
5344
kind: CompatKind.None,
5445
compatVersion: -i,
5546
}),
5647
true,
57-
`N-${i} version: "${getRequestedVersion(
58-
testBaseVersion(-i),
59-
-i,
60-
)}" is not lower than min version: ${minTestVersion}`,
48+
`N-${i} version is not lower than min version: ${baseVersionForMinCompat}`,
49+
);
50+
});
51+
}
52+
53+
// Making sure compatConfigs with old min compat don't get filtered.
54+
for (let i = 1; i < numCompatVersions; i++) {
55+
it(`compatVersion N-${i} > ${oldVersion}`, () => {
56+
assert.strictEqual(
57+
isCompatVersionBelowMinVersion(oldVersion, {
58+
name: `test`,
59+
kind: CompatKind.None,
60+
compatVersion: -i,
61+
}),
62+
false,
63+
`N-${i} version: is lower than min version: ${oldVersion}`,
6164
);
6265
});
6366
}
6467

6568
it("cross compat. filters out if loadVersion is lower than minVersion", () => {
6669
assert.strictEqual(
67-
isCompatVersionBelowMinVersion(minTestVersion, {
70+
isCompatVersionBelowMinVersion(greaterVersion, {
6871
name: "test",
6972
kind: CompatKind.CrossVersion,
70-
compatVersion: minTestVersion,
71-
loadVersion: "1.3.7",
73+
compatVersion: greaterVersion,
74+
loadVersion: lowerVersion,
7275
}),
7376
true,
7477
);
7578
});
7679

7780
it("cross compat. filters out if compatVersion is lower than minVersion", () => {
7881
assert.strictEqual(
79-
isCompatVersionBelowMinVersion(minTestVersion, {
82+
isCompatVersionBelowMinVersion(greaterVersion, {
8083
name: "test",
8184
kind: CompatKind.CrossVersion,
82-
compatVersion: "1.3.7",
83-
loadVersion: minTestVersion,
85+
compatVersion: lowerVersion,
86+
loadVersion: greaterVersion,
8487
}),
8588
true,
8689
);
8790
});
8891

8992
it("cross compat. does not filter out valid versions", () => {
9093
assert.strictEqual(
91-
isCompatVersionBelowMinVersion("1.3.7", {
94+
isCompatVersionBelowMinVersion(lowerVersion, {
9295
name: "test",
9396
kind: CompatKind.CrossVersion,
94-
compatVersion: minTestVersion,
95-
loadVersion: "1.3.7",
97+
compatVersion: greaterVersion,
98+
loadVersion: lowerVersion,
9699
}),
97100
false,
98-
`fails with minVersion: 1.3.7 compatversion: ${minTestVersion} loadVersion: 1.3.7`,
101+
`fails with minVersion: ${lowerVersion} compatversion: ${greaterVersion} loadVersion: ${lowerVersion}`,
99102
);
100103
assert.strictEqual(
101-
isCompatVersionBelowMinVersion("1.3.7", {
104+
isCompatVersionBelowMinVersion(lowerVersion, {
102105
name: "test",
103106
kind: CompatKind.CrossVersion,
104-
compatVersion: "1.3.7",
105-
loadVersion: minTestVersion,
107+
compatVersion: lowerVersion,
108+
loadVersion: greaterVersion,
106109
}),
107110
false,
108-
`fails with minVersion: 1.3.7 compatversion: 1.3.7 loadVersion: ${minTestVersion}`,
111+
`fails with minVersion: ${lowerVersion} compatversion: ${lowerVersion} loadVersion: ${greaterVersion}`,
109112
);
110113
});
111114
});

0 commit comments

Comments
 (0)