Skip to content

Commit

Permalink
introduce constants
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskalmar committed Nov 18, 2023
1 parent a23697d commit ecf47d9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const notSupported = 'not supported';
5 changes: 3 additions & 2 deletions src/crawler/histoireScreenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import axios from 'axios';
import { log } from '../log';
import { config, isPlatformModeConfig } from '../config';
import { type ShotItem } from '../types';
import { notSupported } from '../constants';

type HistoireStory = {
id: string;
Expand Down Expand Up @@ -37,14 +38,14 @@ const generateShotItemsForStory = (
shotName: variantShotName,
url: `${baseUrl}/__sandbox.html?storyId=${story.id}&variantId=${variant.id}`,
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: path.join(config.imagePathBaseline, `${variantShotName}.png`),
filePathCurrent: path.join(
config.imagePathCurrent,
`${variantShotName}.png`,
),
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: path.join(config.imagePathDifference, `${variantShotName}.png`),
threshold: config.threshold,
});
Expand Down
9 changes: 5 additions & 4 deletions src/crawler/ladleScreenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { config, isPlatformModeConfig, type Mask } from '../config';
import type { ShotItem } from '../types';
import { selectBreakpoints, generateSizeLabel } from '../shots/utils';
import type { Story } from './storybook';
import { notSupported } from '../constants';

export const generateLadleShotItems = (
baseUrl: string,
Expand Down Expand Up @@ -31,14 +32,14 @@ export const generateLadleShotItems = (
: ladleStory.id,
url: `${ladleUrl}?story=${ladleStory.story}&mode=preview`,
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: `${path.join(config.imagePathBaseline, ladleStory.story)}.png`,
filePathCurrent: `${path.join(
config.imagePathCurrent,
ladleStory.story,
)}.png`,
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: `${path.join(config.imagePathDifference, ladleStory.story)}.png`,
threshold: config.threshold,
mask: mask ?? [],
Expand All @@ -59,7 +60,7 @@ export const generateLadleShotItems = (
breakpointGroup: ladleStory.story,
url: `${ladleUrl}?story=${ladleStory.story}&mode=preview&width=${breakpoint}`,
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: `${path.join(
config.imagePathBaseline,
ladleStory.story,
Expand All @@ -69,7 +70,7 @@ export const generateLadleShotItems = (
ladleStory.story,
)}${sizeLabel}.png`,
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: `${path.join(
config.imagePathDifference,
ladleStory.story,
Expand Down
9 changes: 5 additions & 4 deletions src/crawler/pageScreenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../config';
import type { ShotItem } from '../types';
import { selectBreakpoints, generateSizeLabel } from '../shots/utils';
import { notSupported } from '../constants';

const generateBrowserConfig = (page: PageScreenshotParameter) => {
const browserConfig = config.configureBrowser?.({
Expand Down Expand Up @@ -62,11 +63,11 @@ export const generatePageShotItems = (
: page.name,
url: path.join(baseUrl, page.path),
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: `${path.join(config.imagePathBaseline, page.name)}.png`,
filePathCurrent: `${path.join(config.imagePathCurrent, page.name)}.png`,
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: `${path.join(config.imagePathDifference, page.name)}.png`,
browserConfig: generateBrowserConfig(page),
threshold: page.threshold ?? config.threshold,
Expand All @@ -90,14 +91,14 @@ export const generatePageShotItems = (
breakpointGroup: page.name,
url: path.join(baseUrl, page.path),
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: `${path.join(config.imagePathBaseline, page.name)}${sizeLabel}.png`,
filePathCurrent: `${path.join(
config.imagePathCurrent,
page.name,
)}${sizeLabel}.png`,
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: `${path.join(
config.imagePathDifference,
page.name,
Expand Down
9 changes: 5 additions & 4 deletions src/crawler/storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { type Mask, config, isPlatformModeConfig } from '../config';
import { getBrowser } from '../utils';
import { log } from '../log';
import { selectBreakpoints, generateSizeLabel } from '../shots/utils';
import { notSupported } from '../constants';

export type StoryParameters = {
lostpixel?: {
Expand Down Expand Up @@ -302,11 +303,11 @@ export const generateStorybookShotItems = (
importPath: story.importPath,
url: `${iframeUrl}?id=${story.id}&viewMode=story`,
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: path.join(config.imagePathBaseline, fileNameWithExt),
filePathCurrent: path.join(config.imagePathCurrent, fileNameWithExt),
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: path.join(config.imagePathDifference, fileNameWithExt),
browserConfig: generateBrowserConfig(story),
threshold: story.parameters?.lostpixel?.threshold ?? config.threshold,
Expand Down Expand Up @@ -340,11 +341,11 @@ export const generateStorybookShotItems = (
breakpoint,
breakpointGroup: story.id,
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: path.join(config.imagePathBaseline, fileNameWithExt),
filePathCurrent: path.join(config.imagePathCurrent, fileNameWithExt),
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
? notSupported
: path.join(config.imagePathDifference, fileNameWithExt),
viewport: {
width: breakpoint,
Expand Down

0 comments on commit ecf47d9

Please sign in to comment.