Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent test coverage backsliding for 100% coverage files #1391

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 78 additions & 10 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,92 @@
import { defineConfig } from 'vitest/config';

// These globs are expected to have 100% coverage.
const FULL_COVERAGE_FILES_RELATIVE = [
'camera-manager/*.ts',
'camera-manager/browse-media/camera.ts',
'camera-manager/frigate/camera.ts',
'camera-manager/frigate/icon.ts',
'camera-manager/frigate/requests.ts',
'camera-manager/frigate/util.ts',
'camera-manager/generic/*.ts',
'camera-manager/motioneye/icon.ts',
'card-controller/*.ts',
'components-lib/cached-value-controller.ts',
'components-lib/media-filter-controller.ts',
'components-lib/menu-button-controller.ts',
'components-lib/menu-controller.ts',
'components-lib/ptz-controller.ts',
'components-lib/zoom-controller.ts',
'config-mgmt.ts',
'config/types.ts',
'const.ts',
'src/view/*.ts',
'types.ts',
'utils/action.ts',
'utils/audio.ts',
'utils/basic.ts',
'utils/camera.ts',
'utils/debug.ts',
'utils/diagnostics.ts',
'utils/download.ts',
'utils/embla/**/*.ts',
'utils/ha/entity-registry/types.ts',
'utils/ha/types.ts',
'utils/media-info.ts',
'utils/media-to-view.ts',
'utils/media.ts',
'utils/ptz.ts',
'utils/screenshot.ts',
'utils/substream.ts',
'utils/timer.ts',
'utils/zod.ts',
];

interface Threshold {
statements: number;
branches: number;
functions: number;
lines: number;
perFile: boolean;
}

const fullCoverage: Threshold = {
statements: 100,
branches: 100,
functions: 100,
lines: 100,
perFile: true,
};

const calculateFullCoverageThresholds = (): Record<string, Threshold> => {
return FULL_COVERAGE_FILES_RELATIVE.reduce(
(a, v) => ({ ...a, ['**/src/' + v]: fullCoverage }),
{},
);
};

// ts-prune-ignore-next
export default defineConfig({
test: {
include: [
"tests/**/*.test.ts"
],
include: ['tests/**/*.test.ts'],
coverage: {
// Favor istanbul for coverage over v8 due to better accuracy.
provider: 'istanbul',

// Thresholds will automatically be updated as coverage improves to avoid
// back-sliding.
thresholds: {
// Thresholds will automatically be updated as coverage improves to avoid
// back-sliding.
autoUpdate: true,
statements: 51.11,
branches: 43.04,
functions: 51.03,
lines: 51.91,

// Expected thresholds for anything that does not have 100% coverage
// yet.
statements: 15.54,
branches: 10.38,
functions: 16.18,
lines: 15.84,

...calculateFullCoverageThresholds(),
},
},
},
});
});
Loading