Skip to content

Commit

Permalink
define shot items depending on config mode
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskalmar committed Nov 18, 2023
1 parent a2eed30 commit 32bad90
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 54 deletions.
16 changes: 7 additions & 9 deletions src/crawler/histoireScreenshots.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';
import axios from 'axios';
import { log } from '../log';
import { config } from '../config';
import { config, isPlatformModeConfig } from '../config';
import { type ShotItem } from '../types';

type HistoireStory = {
Expand Down Expand Up @@ -36,18 +36,16 @@ const generateShotItemsForStory = (
id: variant.id,
shotName: variantShotName,
url: `${baseUrl}/__sandbox.html?storyId=${story.id}&variantId=${variant.id}`,
filePathBaseline: path.join(
config.imagePathBaseline,
`${variantShotName}.png`,
),
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
: path.join(config.imagePathBaseline, `${variantShotName}.png`),
filePathCurrent: path.join(
config.imagePathCurrent,
`${variantShotName}.png`,
),
filePathDifference: path.join(
config.imagePathDifference,
`${variantShotName}.png`,
),
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
: path.join(config.imagePathDifference, `${variantShotName}.png`),
threshold: config.threshold,
});
}
Expand Down
36 changes: 19 additions & 17 deletions src/crawler/ladleScreenshots.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path';
import axios from 'axios';
import { config, type Mask } from '../config';
import { config, isPlatformModeConfig, type Mask } from '../config';
import type { ShotItem } from '../types';
import { selectBreakpoints, generateSizeLabel } from '../shots/utils';
import type { Story } from './storybook';
Expand Down Expand Up @@ -30,18 +30,16 @@ export const generateLadleShotItems = (
? config.shotNameGenerator({ ...ladleStory, shotMode: 'ladle' })
: ladleStory.id,
url: `${ladleUrl}?story=${ladleStory.story}&mode=preview`,
filePathBaseline: `${path.join(
config.imagePathBaseline,
ladleStory.story,
)}.png`,
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
: `${path.join(config.imagePathBaseline, ladleStory.story)}.png`,
filePathCurrent: `${path.join(
config.imagePathCurrent,
ladleStory.story,
)}.png`,
filePathDifference: `${path.join(
config.imagePathDifference,
ladleStory.story,
)}.png`,
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
: `${path.join(config.imagePathDifference, ladleStory.story)}.png`,
threshold: config.threshold,
mask: mask ?? [],
};
Expand All @@ -60,18 +58,22 @@ export const generateLadleShotItems = (
breakpoint,
breakpointGroup: ladleStory.story,
url: `${ladleUrl}?story=${ladleStory.story}&mode=preview&width=${breakpoint}`,
filePathBaseline: `${path.join(
config.imagePathBaseline,
ladleStory.story,
)}${sizeLabel}.png`,
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
: `${path.join(
config.imagePathBaseline,
ladleStory.story,
)}${sizeLabel}.png`,
filePathCurrent: `${path.join(
config.imagePathCurrent,
ladleStory.story,
)}${sizeLabel}.png`,
filePathDifference: `${path.join(
config.imagePathDifference,
ladleStory.story,
)}${sizeLabel}.png`,
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
: `${path.join(
config.imagePathDifference,
ladleStory.story,
)}${sizeLabel}.png`,
viewport: { width: breakpoint },
};
});
Expand Down
35 changes: 21 additions & 14 deletions src/crawler/pageScreenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import path from 'node:path';
import axios, { isAxiosError } from 'axios';
import { z } from 'zod';
import { log } from '../log';
import { type Mask, type PageScreenshotParameter, config } from '../config';
import {
type Mask,
type PageScreenshotParameter,
config,
isPlatformModeConfig,
} from '../config';
import type { ShotItem } from '../types';
import { selectBreakpoints, generateSizeLabel } from '../shots/utils';

Expand Down Expand Up @@ -56,12 +61,13 @@ export const generatePageShotItems = (
? config.shotNameGenerator({ ...page, shotMode: 'page' })
: page.name,
url: path.join(baseUrl, page.path),
filePathBaseline: `${path.join(config.imagePathBaseline, page.name)}.png`,
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
: `${path.join(config.imagePathBaseline, page.name)}.png`,
filePathCurrent: `${path.join(config.imagePathCurrent, page.name)}.png`,
filePathDifference: `${path.join(
config.imagePathDifference,
page.name,
)}.png`,
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
: `${path.join(config.imagePathDifference, page.name)}.png`,
browserConfig: generateBrowserConfig(page),
threshold: page.threshold ?? config.threshold,
waitBeforeScreenshot:
Expand All @@ -83,18 +89,19 @@ export const generatePageShotItems = (
breakpoint,
breakpointGroup: page.name,
url: path.join(baseUrl, page.path),
filePathBaseline: `${path.join(
config.imagePathBaseline,
page.name,
)}${sizeLabel}.png`,
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
: `${path.join(config.imagePathBaseline, page.name)}${sizeLabel}.png`,
filePathCurrent: `${path.join(
config.imagePathCurrent,
page.name,
)}${sizeLabel}.png`,
filePathDifference: `${path.join(
config.imagePathDifference,
page.name,
)}${sizeLabel}.png`,
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
: `${path.join(
config.imagePathDifference,
page.name,
)}${sizeLabel}.png`,
viewport: { width: breakpoint },
browserConfig: generateBrowserConfig({
...page,
Expand Down
27 changes: 13 additions & 14 deletions src/crawler/storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import kebabCase from 'lodash.kebabcase';
import type { BrowserContext } from 'playwright-core';
import { readFileSync } from 'fs-extra';
import type { ShotItem } from '../types';
import { type Mask, config } from '../config';
import { type Mask, config, isPlatformModeConfig } from '../config';
import { getBrowser } from '../utils';
import { log } from '../log';
import { selectBreakpoints, generateSizeLabel } from '../shots/utils';
Expand Down Expand Up @@ -301,12 +301,13 @@ export const generateStorybookShotItems = (
shotName: story.shotName,
importPath: story.importPath,
url: `${iframeUrl}?id=${story.id}&viewMode=story`,
filePathBaseline: path.join(config.imagePathBaseline, fileNameWithExt),
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
: path.join(config.imagePathBaseline, fileNameWithExt),
filePathCurrent: path.join(config.imagePathCurrent, fileNameWithExt),
filePathDifference: path.join(
config.imagePathDifference,
fileNameWithExt,
),
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
: path.join(config.imagePathDifference, fileNameWithExt),
browserConfig: generateBrowserConfig(story),
threshold: story.parameters?.lostpixel?.threshold ?? config.threshold,
waitBeforeScreenshot:
Expand Down Expand Up @@ -338,15 +339,13 @@ export const generateStorybookShotItems = (
shotName: `${story.shotName}${sizeLabel}`,
breakpoint,
breakpointGroup: story.id,
filePathBaseline: path.join(
config.imagePathBaseline,
fileNameWithExt,
),
filePathBaseline: isPlatformModeConfig(config)
? 'not supported'
: path.join(config.imagePathBaseline, fileNameWithExt),
filePathCurrent: path.join(config.imagePathCurrent, fileNameWithExt),
filePathDifference: path.join(
config.imagePathDifference,
fileNameWithExt,
),
filePathDifference: isPlatformModeConfig(config)
? 'not supported'
: path.join(config.imagePathDifference, fileNameWithExt),
viewport: {
width: breakpoint,
height: undefined,
Expand Down

0 comments on commit 32bad90

Please sign in to comment.