Skip to content

Commit

Permalink
protect some functions to run in wrong config mode
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskalmar committed Nov 18, 2023
1 parent e29cf77 commit cedf4e9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/checkDifferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import path from 'node:path';
import { mapLimit } from 'async';
import { compareImages } from './compare/compare';
import { log } from './log';
import { config } from './config';
import { config, isPlatformModeConfig } from './config';
import type { ShotItem } from './types';
import { shallGenerateMeta } from './utils';
import { featureNotSupported, shallGenerateMeta } from './utils';

export const checkDifferences = async (shotItems: ShotItem[]) => {
if (isPlatformModeConfig(config)) {
return featureNotSupported('checkDifferences()');
}

log.process(
'info',
'general',
Expand Down
7 changes: 6 additions & 1 deletion src/compare/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { readFileSync, writeFileSync } from 'node:fs';
import pixelmatch from 'pixelmatch';
import { compare as odiffCompare } from 'odiff-bin';
import { PNG } from 'pngjs';
import { config } from '../config';
import { config, isPlatformModeConfig } from '../config';
import { featureNotSupported } from '../utils';
import { resizeImage } from './utils';

export const checkThreshold = (
Expand Down Expand Up @@ -158,6 +159,10 @@ export const compareImages = async (
pixelDifferencePercentage: number;
isWithinThreshold: boolean;
}> => {
if (isPlatformModeConfig(config)) {
return featureNotSupported('compareImages()');
}

if (config.compareEngine === 'pixelmatch') {
return compareImagesViaPixelmatch(
threshold,
Expand Down
10 changes: 10 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,13 @@ export const hashFile = (filePath: string): string => {

return hashBuffer(file);
};

export const featureNotSupported = (feature: string) => {
log.process(
'error',
'general',
`${feature} is not supported in this configuration mode`,
);

process.exit(1);
};

0 comments on commit cedf4e9

Please sign in to comment.