test: Silence superfluous console output during test runs (#2540)

This commit is contained in:
Dermot Duffy
2026-06-30 17:45:13 -07:00
committed by dermotduffy
parent 921d45e577
commit fcef48e75a
8 changed files with 23 additions and 25 deletions
@@ -25,7 +25,7 @@ describe('supports2WayAudio', () => {
vi.mocked(createProxiedEndpointIfNecessary).mockResolvedValue(endpoint);
vi.mocked(homeAssistantSignAndFetch).mockRejectedValue(new Error('fetch error'));
const spy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const spy = vi.spyOn(console, 'warn');
const result = await supports2WayAudio(hass, 2, endpoint);
expect(result).toBe(false);
@@ -70,7 +70,7 @@ describe('IssueStateManager', () => {
});
it('should isolate a failing issue and continue detecting the rest', async () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue();
const spy = vi.spyOn(console, 'warn');
assert(mockConfigUpgrade.detectStatic);
assert(mockLegacyResource.detectStatic);
assert(mockMediaLoad.detectStatic);
@@ -345,7 +345,7 @@ describe('IssueStateManager', () => {
describe('logging', () => {
it('should log on static detection when issue is active', async () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue();
const spy = vi.spyOn(console, 'warn');
const result = createIssueDescription({
notification: { body: { text: 'Legacy issue' } },
});
@@ -362,7 +362,7 @@ describe('IssueStateManager', () => {
});
it('should log on dynamic evaluation when issue becomes active', () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue();
const spy = vi.spyOn(console, 'warn');
const result = createIssueDescription({
notification: { body: { text: 'Stream issue' } },
});
@@ -379,7 +379,7 @@ describe('IssueStateManager', () => {
});
it('should log on trigger when the issue becomes active', () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue();
const spy = vi.spyOn(console, 'warn');
const result = createIssueDescription({
notification: { body: { text: 'Triggered' } },
});
@@ -393,7 +393,7 @@ describe('IssueStateManager', () => {
});
it('should not log on trigger when the issue stays inactive', () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue();
const spy = vi.spyOn(console, 'warn');
vi.mocked(mockMediaLoad.getIssue).mockReturnValue(null);
const manager = createManager();
@@ -404,7 +404,7 @@ describe('IssueStateManager', () => {
});
it('should not log on trigger for an unknown key', () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue();
const spy = vi.spyOn(console, 'warn');
const manager = createManager();
manager.trigger('unknown' as never, {} as never);
@@ -414,7 +414,7 @@ describe('IssueStateManager', () => {
});
it('should only log once per issue key', async () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue();
const spy = vi.spyOn(console, 'warn');
const result = createIssueDescription({
notification: { body: { text: 'Repeated' } },
});
@@ -430,7 +430,7 @@ describe('IssueStateManager', () => {
});
it('should not log when issue has no result', async () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue();
const spy = vi.spyOn(console, 'warn');
vi.mocked(mockLegacyResource.hasIssue).mockReturnValue(false);
const manager = createManager();
@@ -441,7 +441,7 @@ describe('IssueStateManager', () => {
});
it('should not log when issue result has no summarizable text', async () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue();
const spy = vi.spyOn(console, 'warn');
// Notification has neither body.text nor heading.text
const result = createIssueDescription({
notification: {},
@@ -457,7 +457,7 @@ describe('IssueStateManager', () => {
});
it('should log again after the issue clears and re-activates', async () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue();
const spy = vi.spyOn(console, 'warn');
const first = createIssueDescription({
notification: { body: { text: 'First' } },
});
@@ -490,7 +490,7 @@ describe('IssueStateManager', () => {
});
it('should log again after reset and re-activation', () => {
const spy = vi.spyOn(console, 'warn').mockReturnValue();
const spy = vi.spyOn(console, 'warn');
const description = createIssueDescription({
notification: { body: { text: 'Repeat' } },
});
@@ -285,7 +285,7 @@ describe('GalleryController', () => {
manager.getView.mockReturnValue(view);
const error = new Error('test error');
const spy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const spy = vi.spyOn(console, 'warn');
runner.extend.mockRejectedValue(error);
await controller.extend(runner, epoch, 'earlier');
@@ -416,8 +416,6 @@ describe('MediaNotificationController', () => {
assert(controls);
expect(controls).toHaveLength(4);
vi.spyOn(console, 'warn').mockImplementation(() => {});
// 1. Review control
expect(controls?.[0].tooltip).toBe('Mark as reviewed');
expect(controls?.[0].dismiss).toBe(false);
@@ -374,8 +374,6 @@ describe('SignedURLController', () => {
it('should handle errors gracefully', async () => {
const host = mock<ReactiveControllerHost>();
const hass = createHASS();
const consoleSpy = vi.spyOn(console, 'warn').mockReturnValue();
vi.mocked(createProxiedEndpointIfNecessary).mockRejectedValue(
new Error('test-error'),
);
@@ -399,7 +397,6 @@ describe('SignedURLController', () => {
expect(controller.getValue()).toBeNull();
expect(controller.getError()).toBe('proxy');
expect(host.requestUpdate).toBeCalledTimes(1);
consoleSpy.mockRestore();
});
it('should not retry after sign error with same inputs', async () => {
@@ -437,7 +434,6 @@ describe('SignedURLController', () => {
it('should set sign error when signing throws', async () => {
const host = mock<ReactiveControllerHost>();
const hass = createHASS();
const consoleSpy = vi.spyOn(console, 'error').mockReturnValue(undefined);
vi.mocked(createProxiedEndpointIfNecessary).mockResolvedValue({
endpoint: 'http://proxied-url.com',
@@ -462,7 +458,6 @@ describe('SignedURLController', () => {
expect(controller.getValue()).toBeNull();
expect(controller.getError()).toBe('sign');
consoleSpy.mockRestore();
});
it('should not fetch again if within cache TTL', async () => {
@@ -652,7 +647,6 @@ describe('SignedURLController', () => {
// Pending forever for request 2.
new Promise(() => {}),
);
vi.spyOn(console, 'warn').mockImplementation(() => {});
const controller = new SignedURLController(host, () => ({
hass,
+3 -3
View File
@@ -84,7 +84,7 @@ describe('MediaActions', () => {
const error = new Error('fail');
viewItemManager.reviewMedia.mockRejectedValue(error);
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const consoleSpy = vi.spyOn(console, 'warn');
expect(await toggleReviewed(item, viewItemManager)).toBe(false);
expect(consoleSpy).toHaveBeenCalledWith(error.message);
@@ -128,7 +128,7 @@ describe('MediaActions', () => {
const error = new Error('fail');
viewItemManager.favorite.mockRejectedValue(error);
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const consoleSpy = vi.spyOn(console, 'warn');
expect(await toggleFavorite(item, viewItemManager)).toBe(false);
expect(consoleSpy).toHaveBeenCalledWith(error.message);
@@ -158,7 +158,7 @@ describe('MediaActions', () => {
const error = new Error('fail');
viewItemManager.download.mockRejectedValue(error);
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const consoleSpy = vi.spyOn(console, 'warn');
expect(await downloadMedia(item, viewItemManager)).toBe(false);
expect(consoleSpy).toHaveBeenCalledWith(error.message);
+1 -1
View File
@@ -46,7 +46,7 @@ describe('task utilities', () => {
task.render.mockImplementation((renderers) =>
renderers.error?.(new Error('test error')),
);
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
const consoleSpy = vi.spyOn(console, 'warn');
const errorFunc = vi.fn().mockReturnValue(html`error`);
const result = renderTask(task, (r) => html`${r}`, { errorFunc });
+6
View File
@@ -30,6 +30,12 @@ export default defineConfig({
},
},
include: INCLUSIONS,
// Hide console writing to keep output clean, usual sources of noise:
// - Unnecessary Lit dev-mode warnings.
// - Various console outputs (that are expected/tested).
onConsoleLog: () => false,
coverage: {
exclude: EXCLUSIONS,