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