chore: Upgrade to Vitest 4 and regroup tests for performance (#2618)

This commit is contained in:
Dermot Duffy
2026-07-26 11:28:58 -07:00
committed by GitHub
parent a0fd464d23
commit 0c3d46ad3d
36 changed files with 1041 additions and 1207 deletions
@@ -1,6 +1,7 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { MediaQueryWatcher } from '../../../src/condition-trigger/common/media-query-watcher';
import { stubMatchMedia } from '../../test-utils';
// @vitest-environment jsdom
describe('MediaQueryWatcher', () => {
@@ -9,7 +10,7 @@ describe('MediaQueryWatcher', () => {
});
it('should report whether the query matches', () => {
vi.spyOn(window, 'matchMedia').mockReturnValue({
stubMatchMedia().mockReturnValue({
matches: true,
} as unknown as MediaQueryList);
@@ -18,7 +19,7 @@ describe('MediaQueryWatcher', () => {
it('should invoke the callback on a media-query change', () => {
const addEventListener = vi.fn();
vi.spyOn(window, 'matchMedia').mockReturnValue({
stubMatchMedia().mockReturnValue({
addEventListener,
removeEventListener: vi.fn(),
} as unknown as MediaQueryList);
@@ -35,7 +36,7 @@ describe('MediaQueryWatcher', () => {
it('should stop listening and ignore changes after teardown', () => {
const addEventListener = vi.fn();
const removeEventListener = vi.fn();
vi.spyOn(window, 'matchMedia').mockReturnValue({
stubMatchMedia().mockReturnValue({
addEventListener,
removeEventListener,
} as unknown as MediaQueryList);
@@ -8,6 +8,7 @@ import {
createMockTemplateRenderer,
createStateEntity,
stubConnectedHomeAssistant,
stubMatchMedia,
} from '../../test-utils';
// A mock renderer for the orchestration tests, which never render templates.
@@ -71,7 +72,7 @@ describe('ConditionsManager', () => {
it('should re-evaluate and notify when a subscribed condition source changes', () => {
const addEventListener = vi.fn();
const removeEventListener = vi.fn();
vi.spyOn(window, 'matchMedia')
stubMatchMedia()
.mockReturnValueOnce({
addEventListener: addEventListener,
removeEventListener: removeEventListener,
@@ -1,6 +1,7 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { createConditionEvaluator } from '../../../../src/condition-trigger/conditions/factory';
import { stubMatchMedia } from '../../../test-utils';
import { createEvaluatorContext } from './test-utils';
// @vitest-environment jsdom
@@ -10,7 +11,7 @@ describe('screen condition', () => {
});
it('should evaluate the media query', () => {
vi.spyOn(window, 'matchMedia').mockReturnValue({
stubMatchMedia().mockReturnValue({
matches: true,
} as unknown as MediaQueryList);
@@ -30,7 +31,7 @@ describe('screen condition', () => {
});
it('should not match or expose a source without a media query', () => {
const matchMedia = vi.spyOn(window, 'matchMedia');
const matchMedia = stubMatchMedia();
const evaluator = createConditionEvaluator(
{ condition: 'screen' as const },
createEvaluatorContext(),
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi, type Mock } from 'vitest';
import { ScreenTrigger } from '../../../../src/condition-trigger/triggers/triggers/screen';
import type { TriggerOfType } from '../../../../src/condition-trigger/triggers/triggers/types';
import { stubMatchMedia } from '../../../test-utils';
// @vitest-environment jsdom
describe('ScreenTrigger', () => {
@@ -10,7 +11,7 @@ describe('ScreenTrigger', () => {
const removeEventListener = vi.fn();
const mockMatchMedia = (): void => {
vi.spyOn(window, 'matchMedia').mockImplementation(
stubMatchMedia().mockImplementation(
() =>
({
get matches(): boolean {