mirror of
https://github.com/actions/setup-node.git
synced 2025-04-22 09:21:00 +00:00
Fix nightly unit tests
This commit is contained in:
parent
6e2b26d097
commit
505679238a
2 changed files with 184 additions and 79 deletions
|
@ -108,11 +108,16 @@ describe('setup-node unit tests', () => {
|
|||
});
|
||||
|
||||
describe('Version spec matchers', () => {
|
||||
describe('semverVersionMatcher', () => {
|
||||
it('semverVersionMatcher should always work as semver.satisfies does', () => {
|
||||
const rangePlain = '1.1.1';
|
||||
const matcherPlain = semverVersionMatcherFactory(rangePlain);
|
||||
expect(matcherPlain('1.1.1')).toBe(semver.satisfies('1.1.1', rangePlain));
|
||||
expect(matcherPlain('1.1.2')).toBe(semver.satisfies('1.1.2', rangePlain));
|
||||
expect(matcherPlain('1.1.1')).toBe(
|
||||
semver.satisfies('1.1.1', rangePlain)
|
||||
);
|
||||
expect(matcherPlain('1.1.2')).toBe(
|
||||
semver.satisfies('1.1.2', rangePlain)
|
||||
);
|
||||
|
||||
const rangeEq = '=1.1.1';
|
||||
const matcherEq = semverVersionMatcherFactory(rangeEq);
|
||||
|
@ -122,6 +127,28 @@ describe('setup-node unit tests', () => {
|
|||
// TODO: add for discovered issues if any
|
||||
});
|
||||
|
||||
it("semverVersionMatcher should match release candidate as semver.satisfies does'", () => {
|
||||
const rangePlain = 'v19.0.0-rc.2';
|
||||
const matcherPlain = semverVersionMatcherFactory(rangePlain);
|
||||
expect(matcherPlain('v19.0.0-rc.2')).toBe(
|
||||
semver.satisfies('v19.0.0-rc.2', rangePlain)
|
||||
);
|
||||
expect(matcherPlain('v19.0.1-rc.2')).toBe(
|
||||
semver.satisfies('v19.0.01rc.2', rangePlain)
|
||||
);
|
||||
|
||||
const rangeEq = '=1.1.1';
|
||||
const matcherEq = semverVersionMatcherFactory(rangeEq);
|
||||
expect(matcherPlain('v19.0.0-rc.2')).toBe(
|
||||
semver.satisfies('v19.0.0-rc.2', rangePlain)
|
||||
);
|
||||
expect(matcherPlain('v19.0.1-rc.2')).toBe(
|
||||
semver.satisfies('v19.0.1-rc.2', rangePlain)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canaryExactVersionMatcher', () => {
|
||||
it('canaryExactVersionMatcher should match v20.0.0-v8-canary20221103f7e2421e91 only v20.0.0-v8-canary20221103f7e2421e91', () => {
|
||||
const version = semver.coerce('v20.0.0')!.version;
|
||||
const matcher = canaryExactVersionMatcherFactory(
|
||||
|
@ -132,8 +159,10 @@ describe('setup-node unit tests', () => {
|
|||
// see https://github.com/actions/setup-node/blob/00e1b6691b40cce14b5078cb411dd1ec7dab07f7/__tests__/verify-node.sh#L10
|
||||
expect(matcher('v20.0.0-v8-canary202211026bf85d0fb4')).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
it('canaryRangeVersionMatcherFactory should match v20-v8-canary to any minor and patch version', () => {
|
||||
describe('canaryRangeVersionMatcherFactory', () => {
|
||||
it('canaryRangeVersionMatcherFactory should match v20-v8-canary to any v20.x.x', () => {
|
||||
const version = semver.coerce('v20')!.version;
|
||||
const matcher = canaryRangeVersionMatcherFactory(version);
|
||||
expect(matcher('v20.0.0-v8-canary20221103f7e2421e91')).toBeTruthy();
|
||||
|
@ -154,7 +183,7 @@ describe('setup-node unit tests', () => {
|
|||
expect(matcher('v19.1.-v8-canary20221103f7e2421e91')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('canaryRangeVersionMatcherFactory should match v20.1-v8-canary to any v20.1 patch version and minor above or eq v20.1', () => {
|
||||
it('canaryRangeVersionMatcherFactory should match v20.1-v8-canary to any v20.1.x patch version and minor above or eq v20.1', () => {
|
||||
const version = semver.coerce('v20.1')!.version;
|
||||
const matcher = canaryRangeVersionMatcherFactory(version);
|
||||
expect(matcher('v20.1.0-v8-canary20221103f7e2421e91')).toBeTruthy();
|
||||
|
@ -163,7 +192,7 @@ describe('setup-node unit tests', () => {
|
|||
expect(matcher('v20.2.0-v8-canary20221103f7e2421e91')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('canaryRangeVersionMatcherFactory should not match canaryRangeVersionMatcherFactory to v21.x, v19.x, and v20 minor less v20.2', () => {
|
||||
it('canaryRangeVersionMatcherFactory should not match v20.2-v8-canary to v21.x, v19.x, and v20 minor less than v20.2', () => {
|
||||
const version = semver.coerce('v20.2')!.version;
|
||||
const matcher = canaryRangeVersionMatcherFactory(version);
|
||||
expect(matcher('v20.1.0-v8-canary20221103f7e2421e91')).toBeFalsy();
|
||||
|
@ -171,7 +200,7 @@ describe('setup-node unit tests', () => {
|
|||
expect(matcher('v19.0.0-v8-canary20221103f7e2421e91')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('canaryRangeVersionMatcherFactory should not match v20.1.1-v8-canary v20.1.x to patch versions above or eq v20.1.1', () => {
|
||||
it('canaryRangeVersionMatcherFactory should match v20.1.1-v8-canary to v20.1.x patch versions above or eq v20.1.1', () => {
|
||||
const version = semver.coerce('v20.1.1')!.version;
|
||||
const matcher = canaryRangeVersionMatcherFactory('v20.1.1-v8-canary');
|
||||
expect(matcher('v20.1.1-v8-canary20221103f7e2421e91')).toBeTruthy();
|
||||
|
@ -179,13 +208,6 @@ describe('setup-node unit tests', () => {
|
|||
expect(matcher('v20.2.0-v8-canary20221103f7e2421e91')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('canaryRangeVersionMatcherFactory should match v20.1.1-v8-canary to patch versions with any canary timestamp', () => {
|
||||
const version = semver.coerce('v20.1.1')!.version;
|
||||
const matcher = canaryRangeVersionMatcherFactory(version);
|
||||
expect(matcher('v20.1.1-v8-canary20221103f7e2421e91')).toBeTruthy();
|
||||
expect(matcher('v20.1.1-v8-canary202211026bf85d0fb4')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('canaryRangeVersionMatcherFactory should not match v20.1.1-v8-canary to any other minor versions and patch versions below v20.1.1', () => {
|
||||
const version = semver.coerce('v20.1.1')!.version;
|
||||
const matcher = canaryRangeVersionMatcherFactory(version);
|
||||
|
@ -193,6 +215,77 @@ describe('setup-node unit tests', () => {
|
|||
expect(matcher('v21.0.0-v8-canary20221103f7e2421e91')).toBeFalsy();
|
||||
expect(matcher('v19.0.0-v8-canary20221103f7e2421e91')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('canaryRangeVersionMatcherFactory should match v20.1.1-v8-canary to patch versions with any canary timestamp', () => {
|
||||
const version = semver.coerce('v20.1.1')!.version;
|
||||
const matcher = canaryRangeVersionMatcherFactory(version);
|
||||
expect(matcher('v20.1.1-v8-canary20221103f7e2421e91')).toBeTruthy();
|
||||
expect(matcher('v20.1.1-v8-canary202211026bf85d0fb4')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('nightlyRangeVersionMatcherFactory', () => {
|
||||
it('nightlyRangeVersionMatcherFactory should match v20-nightly to any v20.x.x', () => {
|
||||
const version = semver.coerce('v20')!.version;
|
||||
const matcher = nightlyRangeVersionMatcherFactory(version);
|
||||
expect(matcher('v20.0.0-nightly20221103f7e2421e91')).toBeTruthy();
|
||||
expect(matcher('v20.0.1-nightly20221103f7e2421e91')).toBeTruthy();
|
||||
expect(matcher('v20.1.0-nightly20221103f7e2421e91')).toBeTruthy();
|
||||
expect(matcher('v20.1.1-nightly20221103f7e2421e91')).toBeTruthy();
|
||||
expect(matcher('v20.0.0-nightly202211026bf85d0fb4')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('nightlyRangeVersionMatcherFactory should not match v20-nightly to v21.x & v19.x', () => {
|
||||
const version = semver.coerce('v20')!.version;
|
||||
const matcher = nightlyRangeVersionMatcherFactory(version);
|
||||
expect(matcher('v21.0.0-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
expect(matcher('v21.1.0-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
expect(matcher('v21.1.1-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
expect(matcher('v19.0.0-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
expect(matcher('v19.1.0-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
expect(matcher('v19.1.-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('nightlyRangeVersionMatcherFactory should match v20.1-nightly to any v20.1.x patch version and minor above or eq v20.1', () => {
|
||||
const version = semver.coerce('v20.1')!.version;
|
||||
const matcher = nightlyRangeVersionMatcherFactory(version);
|
||||
expect(matcher('v20.1.0-nightly20221103f7e2421e91')).toBeTruthy();
|
||||
expect(matcher('v20.1.1-nightly20221103f7e2421e91')).toBeTruthy();
|
||||
expect(matcher('v20.1.0-nightly202211026bf85d0fb4')).toBeTruthy();
|
||||
expect(matcher('v20.2.0-nightly20221103f7e2421e91')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('nightlyRangeVersionMatcherFactory should not match v20.2-nightly to v21.x, v19.x, and v20 minor less v20.2', () => {
|
||||
const version = semver.coerce('v20.2')!.version;
|
||||
const matcher = nightlyRangeVersionMatcherFactory(version);
|
||||
expect(matcher('v20.1.0-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
expect(matcher('v21.0.0-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
expect(matcher('v19.0.0-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('nightlyRangeVersionMatcherFactory should match v20.1.1-nightly to v20.1.x patch versions above or eq v20.1.1', () => {
|
||||
const version = semver.coerce('v20.1.1')!.version;
|
||||
const matcher = nightlyRangeVersionMatcherFactory('v20.1.1-nightly');
|
||||
expect(matcher('v20.1.1-nightly20221103f7e2421e91')).toBeTruthy();
|
||||
expect(matcher('v20.1.2-nightly20221103f7e2421e91')).toBeTruthy();
|
||||
expect(matcher('v20.2.0-nightly20221103f7e2421e91')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('nightlyRangeVersionMatcherFactory should not match v20.1.1-nightly to any other minor versions and patch versions below v20.1.1', () => {
|
||||
const version = semver.coerce('v20.1.1')!.version;
|
||||
const matcher = nightlyRangeVersionMatcherFactory(version);
|
||||
expect(matcher('v20.1.0-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
expect(matcher('v21.0.0-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
expect(matcher('v19.0.0-nightly20221103f7e2421e91')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('nightlyRangeVersionMatcherFactory should match v20.1.1-nightly to patch versions with any timestamp', () => {
|
||||
const version = semver.coerce('v20.1.1')!.version;
|
||||
const matcher = nightlyRangeVersionMatcherFactory(version);
|
||||
expect(matcher('v20.1.1-nightly20221103f7e2421e91')).toBeTruthy();
|
||||
expect(matcher('v20.1.1-nightly202211026bf85d0fb4')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('evaluateVersions', () => {
|
||||
|
|
|
@ -92,26 +92,38 @@ export const canaryExactVersionMatcherFactory = (
|
|||
export const nightlyRangeVersionMatcherFactory = (
|
||||
version: string
|
||||
): VersionMatcher => {
|
||||
const range = `${semver.validRange(`^${version}-0`)}-0`;
|
||||
const range = semver.validRange(`^${version}`);
|
||||
// TODO: this makes v20.1.1-nightly to do not match v20.1.1-nightly20221103f7e2421e91
|
||||
// const range = `${semver.validRange(`^${version}-0`)}-0`;
|
||||
const matcher = (potential: string): boolean =>
|
||||
distributionOf(potential) === Distributions.NIGHTLY &&
|
||||
semver.satisfies(potential.replace('-nightly', '-nightly.'), range, {
|
||||
// TODO: dmitry's variant was potential.replace('-nightly', '-nightly.') that made
|
||||
// all unit tests to fail
|
||||
semver.satisfies(
|
||||
potential.replace('-nightly', '+nightly.'),
|
||||
range /*, {
|
||||
// TODO: what is for?
|
||||
includePrerelease: true
|
||||
});
|
||||
}*/
|
||||
);
|
||||
matcher.factory = nightlyRangeVersionMatcherFactory;
|
||||
return matcher;
|
||||
};
|
||||
|
||||
export const nightlyExactVersionMatcherFactory = (
|
||||
version: string,
|
||||
prerelease_tag: string
|
||||
timestamp: string
|
||||
): VersionMatcher => {
|
||||
const range = `${version}-${prerelease_tag.replace('nightly', 'nightly.')}`;
|
||||
const range = `${version}-${timestamp.replace('nightly', 'nightly.')}`;
|
||||
const matcher = (potential: string): boolean =>
|
||||
distributionOf(potential) === Distributions.NIGHTLY &&
|
||||
semver.satisfies(potential.replace('-nightly', '-nightly.'), range, {
|
||||
semver.satisfies(
|
||||
potential.replace('-nightly', '-nightly.'),
|
||||
range /*, {
|
||||
// TODO: what is for?
|
||||
includePrerelease: true
|
||||
});
|
||||
}*/
|
||||
);
|
||||
matcher.factory = nightlyExactVersionMatcherFactory;
|
||||
return matcher;
|
||||
};
|
||||
|
@ -178,7 +190,7 @@ export async function getNode(
|
|||
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
|
||||
}
|
||||
|
||||
// TODO: 121-127 and 131-132 seems to be the same. Why do we need them?
|
||||
// TODO: 183-189 and 193-194 seems to be the same. Why do we need them?
|
||||
if (isLatestSyntax(versionSpec) || distribution == Distributions.CANARY) {
|
||||
nodeVersions = await getVersionsFromDist(versionSpec);
|
||||
versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions);
|
||||
|
|
Loading…
Add table
Reference in a new issue