Skip to content

Commit b6478de

Browse files
committed
♻️ split server baseline routes
Pull the baseline, project, screenshot, and TDD handler route behavior into a standalone server slice.
1 parent 85d69bc commit b6478de

10 files changed

Lines changed: 497 additions & 577 deletions

File tree

src/server/handlers/tdd-handler.js

Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -730,82 +730,59 @@ export const createTddHandler = (
730730
let deletedCurrents = 0;
731731
let deletedDiffs = 0;
732732

733-
// Delete all baseline, current, and diff images
734-
for (const comparison of reportData.comparisons) {
735-
// Delete baseline image if it exists
736-
if (comparison.baseline) {
737-
const baselinePath = join(
738-
workingDir,
739-
'.vizzly',
740-
comparison.baseline.replace('/images/', '')
741-
);
742-
if (existsSync(baselinePath)) {
743-
try {
744-
const { unlinkSync } = await import('node:fs');
745-
unlinkSync(baselinePath);
746-
deletedBaselines++;
747-
// Silent deletion
748-
} catch (error) {
749-
output.warn(
750-
`Failed to delete baseline for ${comparison.name}: ${error.message}`
751-
);
752-
}
753-
}
754-
}
733+
let deleteResetFile = (imagePath, label, name) => {
734+
if (!imagePath) return 0;
755735

756-
// Delete current screenshot if it exists
757-
if (comparison.current) {
758-
const currentPath = join(
736+
try {
737+
let filePath = safePath(
759738
workingDir,
760739
'.vizzly',
761-
comparison.current.replace('/images/', '')
740+
imagePath.replace('/images/', '')
762741
);
763-
if (existsSync(currentPath)) {
764-
try {
765-
const { unlinkSync } = await import('node:fs');
766-
unlinkSync(currentPath);
767-
deletedCurrents++;
768-
// Silent deletion
769-
} catch (error) {
770-
output.warn(
771-
`Failed to delete current screenshot for ${comparison.name}: ${error.message}`
772-
);
773-
}
774-
}
775-
}
776742

777-
// Delete diff image if it exists
778-
if (comparison.diff) {
779-
const diffPath = join(
780-
workingDir,
781-
'.vizzly',
782-
comparison.diff.replace('/images/', '')
783-
);
784-
if (existsSync(diffPath)) {
785-
try {
786-
const { unlinkSync } = await import('node:fs');
787-
unlinkSync(diffPath);
788-
deletedDiffs++;
789-
output.debug(`Deleted diff for ${comparison.name}`);
790-
} catch (error) {
791-
output.warn(
792-
`Failed to delete diff for ${comparison.name}: ${error.message}`
793-
);
794-
}
743+
if (!existsSync(filePath)) return 0;
744+
745+
unlinkSync(filePath);
746+
if (label === 'diff') {
747+
output.debug(`Deleted diff for ${name}`);
795748
}
749+
return 1;
750+
} catch (error) {
751+
output.warn(
752+
`Failed to delete ${label} for ${name}: ${error.message}`
753+
);
754+
return 0;
796755
}
756+
};
757+
758+
// Delete all baseline, current, and diff images
759+
for (let comparison of reportData.comparisons) {
760+
deletedBaselines += deleteResetFile(
761+
comparison.baseline,
762+
'baseline',
763+
comparison.name
764+
);
765+
deletedCurrents += deleteResetFile(
766+
comparison.current,
767+
'current screenshot',
768+
comparison.name
769+
);
770+
deletedDiffs += deleteResetFile(
771+
comparison.diff,
772+
'diff',
773+
comparison.name
774+
);
797775
}
798776

799777
// Delete baseline metadata
800-
const metadataPath = join(
778+
let metadataPath = join(
801779
workingDir,
802780
'.vizzly',
803781
'baselines',
804782
'metadata.json'
805783
);
806784
if (existsSync(metadataPath)) {
807785
try {
808-
const { unlinkSync } = await import('node:fs');
809786
unlinkSync(metadataPath);
810787
output.debug('Deleted baseline metadata');
811788
} catch (error) {

0 commit comments

Comments
 (0)