Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ide/gha-update-image/lib/jb-stable-version.test.ts
2499 views
1
// Copyright (c) 2024 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
import { expect, test, mock, describe } from "bun:test";
6
import { JetBrainsIDE, getStableVersionsInfo } from "./jb-stable-version";
7
import { SemVer } from "semver";
8
9
describe("stableVersion", () => {
10
const testIdes: JetBrainsIDE[] = [
11
{
12
productName: "IntelliJ IDEA Ultimate",
13
productId: "intellij",
14
productCode: "IIU",
15
productType: "release",
16
exampleRepo: "https://github.com/gitpod-samples/spring-petclinic",
17
},
18
{
19
productName: "GoLand",
20
productId: "goland",
21
productCode: "GO",
22
productType: "release",
23
exampleRepo: "https://github.com/gitpod-samples/template-golang-cli",
24
},
25
];
26
27
interface args {
28
IUBuildVersion: string;
29
IUMajorVersion: string;
30
GOBuildVersion: string;
31
GOMajorVersion: string;
32
}
33
interface expect {
34
err?: string;
35
buildVersion?: SemVer;
36
majorVersion?: string;
37
}
38
39
const toAxiosData = (ide: JetBrainsIDE, majorVersion: string, buildVersion: string) => [
40
{
41
name: ide.productName,
42
link: ide.productCode,
43
releases: [
44
{
45
majorVersion: majorVersion,
46
build: buildVersion,
47
downloads: {
48
linux: { link: ide.productCode },
49
},
50
},
51
],
52
},
53
];
54
55
test("getStableVersionsInfo", async () => {
56
const tests: { name: string; args: args; expect: expect }[] = [
57
{
58
name: "happy path",
59
args: {
60
IUBuildVersion: "2024.1.1",
61
IUMajorVersion: "2024.1",
62
63
GOBuildVersion: "2024.1.1",
64
GOMajorVersion: "2024.1",
65
},
66
expect: { err: undefined, buildVersion: new SemVer("2024.1.1"), majorVersion: "2024.1" },
67
},
68
{
69
name: "happy path with minimal build version",
70
args: {
71
IUBuildVersion: "2024.1.300",
72
IUMajorVersion: "2024.1",
73
74
GOBuildVersion: "2024.2.200",
75
GOMajorVersion: "2024.1",
76
},
77
expect: { err: undefined, buildVersion: new SemVer("2024.1.300"), majorVersion: "2024.1" },
78
},
79
{
80
name: "happy path with minimal build version#2",
81
args: {
82
IUBuildVersion: "2024.20.300",
83
IUMajorVersion: "2024.1",
84
85
GOBuildVersion: "2024.2.200",
86
GOMajorVersion: "2024.1",
87
},
88
expect: { err: undefined, buildVersion: new SemVer("2024.2.200"), majorVersion: "2024.1" },
89
},
90
{
91
name: "happy path with minimal build version#3",
92
args: {
93
IUBuildVersion: "2024.1.300",
94
IUMajorVersion: "2024.1",
95
96
GOBuildVersion: "2024.1.1200",
97
GOMajorVersion: "2024.1",
98
},
99
expect: { err: undefined, buildVersion: new SemVer("2024.1.300"), majorVersion: "2024.1" },
100
},
101
{
102
name: "multiple major versions",
103
args: {
104
IUBuildVersion: "2024.1.300",
105
IUMajorVersion: "2024.1",
106
107
GOBuildVersion: "2024.2.200",
108
GOMajorVersion: "2024.2",
109
},
110
expect: { err: "Multiple major versions found, skipping update: 2024.1, 2024.2" },
111
},
112
{
113
name: "multiple build versions",
114
args: {
115
IUBuildVersion: "2024.1.300",
116
IUMajorVersion: "2024.1",
117
118
GOBuildVersion: "2025.2.200",
119
GOMajorVersion: "2024.1",
120
},
121
expect: { err: "Multiple build versions (major) found, skipping update: 2024, 2025" },
122
},
123
];
124
for (const tt of tests) {
125
mock.module("axios", () => ({
126
default: (url: string) => {
127
if (url.includes("IIU")) {
128
return {
129
data: toAxiosData(testIdes[0], tt.args.IUMajorVersion, tt.args.IUBuildVersion),
130
};
131
} else if (url.includes("GO")) {
132
return {
133
data: toAxiosData(testIdes[1], tt.args.GOMajorVersion, tt.args.GOBuildVersion),
134
};
135
}
136
},
137
}));
138
139
if (tt.expect.err) {
140
expect(() => getStableVersionsInfo(testIdes)).toThrow(tt.expect.err);
141
} else if (tt.expect.buildVersion && tt.expect.majorVersion) {
142
const got = await getStableVersionsInfo(testIdes);
143
expect(got.majorVersion).toBe(tt.expect.majorVersion);
144
expect(String(got.buildVersion)).toBe(String(tt.expect.buildVersion));
145
}
146
}
147
});
148
});
149
150