Skip to content

Commit 445fd8b

Browse files
test: enhance ReleaseProcessor tests with console log suppression
1 parent 4efe8c0 commit 445fd8b

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

.github/scripts/release-index/build-releases.test.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ describe('VersionManager', () => {
102102
describe('ReleaseProcessor', () => {
103103
let processor;
104104
let mockVersionManager;
105+
let consoleSpy;
105106

106107
beforeEach(() => {
108+
// Mock console to suppress logs during tests
109+
consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
110+
107111
mockVersionManager = {
108112
detectChannel: jest.fn((v) => (v.includes('-') ? 'latest' : 'stable')),
109113
normalizeVersion: jest.fn((v) => v),
@@ -115,6 +119,10 @@ describe('ReleaseProcessor', () => {
115119
processor = new ReleaseProcessor(mockVersionManager, '### Security Fixes:');
116120
});
117121

122+
afterEach(() => {
123+
consoleSpy.mockRestore();
124+
});
125+
118126
describe('processReleases', () => {
119127
it('should process valid releases', () => {
120128
const rawReleases = [
@@ -138,13 +146,11 @@ describe('ReleaseProcessor', () => {
138146
},
139147
];
140148

141-
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
142149
const result = processor.processReleases(rawReleases);
143150

144151
expect(result.releases).toHaveLength(2);
145152
expect(result.channels.stable).toHaveLength(1);
146153
expect(result.channels.latest).toHaveLength(1);
147-
consoleSpy.mockRestore();
148154
});
149155

150156
it('should skip draft and prerelease', () => {
@@ -153,11 +159,9 @@ describe('ReleaseProcessor', () => {
153159
{ tag_name: '1.0.1', draft: false, prerelease: true },
154160
];
155161

156-
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
157162
const result = processor.processReleases(rawReleases);
158163

159164
expect(result.releases).toHaveLength(0);
160-
consoleSpy.mockRestore();
161165
});
162166

163167
it('should detect security fixes', () => {
@@ -173,11 +177,9 @@ describe('ReleaseProcessor', () => {
173177
},
174178
];
175179

176-
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
177180
const result = processor.processReleases(rawReleases);
178181

179182
expect(result.releases[0].hasSecurityFixes).toBe(true);
180-
consoleSpy.mockRestore();
181183
});
182184

183185
it('should skip invalid versions', () => {
@@ -195,11 +197,9 @@ describe('ReleaseProcessor', () => {
195197
},
196198
];
197199

198-
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
199200
const result = processor.processReleases(rawReleases);
200201

201202
expect(result.releases).toHaveLength(0);
202-
consoleSpy.mockRestore();
203203
});
204204
});
205205

@@ -215,7 +215,6 @@ describe('ReleaseProcessor', () => {
215215
getAppVersionFromChart: jest.fn().mockResolvedValue('1.2.3'),
216216
};
217217

218-
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
219218
const result = await processor.buildChannelData(
220219
releases,
221220
'stable',
@@ -226,7 +225,6 @@ describe('ReleaseProcessor', () => {
226225
expect(result.releases[0].version).toBe('1.0.2'); // Sorted desc
227226
expect(result.latestWithSecurityFixes).toBe('1.0.2');
228227
expect(result.latestRelease.version).toBe('1.0.2');
229-
consoleSpy.mockRestore();
230228
});
231229

232230
it('should mark upgrade available correctly', async () => {
@@ -239,7 +237,6 @@ describe('ReleaseProcessor', () => {
239237
getAppVersionFromChart: jest.fn().mockResolvedValue('1.2.3'),
240238
};
241239

242-
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
243240
const result = await processor.buildChannelData(
244241
releases,
245242
'stable',
@@ -249,7 +246,6 @@ describe('ReleaseProcessor', () => {
249246

250247
expect(result.releases[0].upgradeAvailable).toBe(false); // Latest
251248
expect(result.releases[1].upgradeAvailable).toBe(true); // Not latest
252-
consoleSpy.mockRestore();
253249
});
254250

255251
it('should mark security vulnerabilities correctly', async () => {
@@ -263,7 +259,6 @@ describe('ReleaseProcessor', () => {
263259
getAppVersionFromChart: jest.fn().mockResolvedValue('1.2.3'),
264260
};
265261

266-
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
267262
const result = await processor.buildChannelData(
268263
releases,
269264
'stable',
@@ -274,7 +269,6 @@ describe('ReleaseProcessor', () => {
274269
expect(result.releases[0].hasSecurityVulnerabilities).toBe(false);
275270
expect(result.releases[1].hasSecurityVulnerabilities).toBe(false);
276271
expect(result.releases[2].hasSecurityVulnerabilities).toBe(true);
277-
consoleSpy.mockRestore();
278272
});
279273

280274
it('should limit releases to maxReleases', async () => {
@@ -290,7 +284,6 @@ describe('ReleaseProcessor', () => {
290284
getAppVersionFromChart: jest.fn().mockResolvedValue('1.2.3'),
291285
};
292286

293-
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
294287
const result = await processor.buildChannelData(
295288
releases,
296289
'stable',
@@ -299,7 +292,6 @@ describe('ReleaseProcessor', () => {
299292
);
300293

301294
expect(result.releases).toHaveLength(5);
302-
consoleSpy.mockRestore();
303295
});
304296
});
305297
});

0 commit comments

Comments
 (0)