Skip to content

Commit

Permalink
update config defaults and optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskalmar committed Nov 18, 2023
1 parent 8c04049 commit dbf5180
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const PageScreenshotParameterSchema = z.object({
* Time to wait before taking a screenshot
* @default 1_000
*/
waitBeforeScreenshot: z.number().optional(),
waitBeforeScreenshot: z.number().default(1000),

/**
* Threshold for the difference between the baseline and current image
Expand All @@ -50,15 +50,15 @@ export const PageScreenshotParameterSchema = z.object({
* Values greater or equal to 1 are interpreted as pixel count.
* @default 0
*/
threshold: z.number().optional(),
threshold: z.number().default(0),

/**
* Define custom breakpoints for the page as width in pixels
* @default []
* @example
* [ 320, 768, 1280 ]
*/
breakpoints: z.array(z.number()).optional(),
breakpoints: z.array(z.number()),

/**
* Define a custom viewport for the page
Expand Down Expand Up @@ -116,7 +116,7 @@ export const LadleShotsSchema = z.object({
* @example
* [ 320, 768, 1280 ]
*/
breakpoints: z.array(z.number()).optional(),
breakpoints: z.array(z.number()).default([]).optional(),
});

export const HistoireShotsSchema = z.object({
Expand Down Expand Up @@ -196,6 +196,26 @@ const StoryLikeSchema = z.object({
parameters: z.record(z.unknown()).optional(),
});

export const TimeoutsSchema = z.object({
/**
* Timeout for fetching stories
* @default 30_000
*/
fetchStories: z.number().default(30_000),

/**
* Timeout for loading the state of the page
* @default 30_000
*/
loadState: z.number().default(30_000),

/**
* Timeout for waiting for network requests to finish
* @default 30_000
*/
networkRequests: z.number().default(30_000),
});

export const BaseConfigSchema = z.object({
/**
* Browser to use: chromium, firefox, or webkit
Expand Down Expand Up @@ -246,29 +266,15 @@ export const BaseConfigSchema = z.object({
* Number of concurrent shots to take
* @default 5
*/
shotConcurrency: z.number(),
shotConcurrency: z.number().default(5),

/**
* Timeouts for various stages of the test
*/
timeouts: z.object({
/**
* Timeout for fetching stories
* @default 30_000
*/
fetchStories: z.number().default(30_000),

/**
* Timeout for loading the state of the page
* @default 30_000
*/
loadState: z.number().default(30_000),

/**
* Timeout for waiting for network requests to finish
* @default 30_000
*/
networkRequests: z.number().default(30_000),
timeouts: TimeoutsSchema.default({
fetchStories: 30_000,
loadState: 30_000,
networkRequests: 30_000,
}),

/**
Expand Down Expand Up @@ -348,7 +354,7 @@ export const BaseConfigSchema = z.object({
.optional(),
});

const PlatformModeConfigSchema = BaseConfigSchema.extend({
export const PlatformModeConfigSchema = BaseConfigSchema.extend({
/**
* URL of the Lost Pixel API endpoint
* @default 'https://api.lost-pixel.com'
Expand Down Expand Up @@ -404,7 +410,7 @@ const PlatformModeConfigSchema = BaseConfigSchema.extend({
setPendingStatusCheck: z.boolean().default(false),
});

const GenerateOnlyModeConfigSchema = BaseConfigSchema.extend({
export const GenerateOnlyModeConfigSchema = BaseConfigSchema.extend({
/**
* Run in local mode
* @deprecated Defaults to running in generateOnly mode
Expand Down Expand Up @@ -441,6 +447,15 @@ const GenerateOnlyModeConfigSchema = BaseConfigSchema.extend({
compareEngine: z.enum(['pixelmatch', 'odiff']).default('pixelmatch'),
});

export const ConfigSchema = z.union([
PlatformModeConfigSchema.extend({
timeouts: TimeoutsSchema.partial(),
}).partial(),
GenerateOnlyModeConfigSchema.extend({
timeouts: TimeoutsSchema.partial(),
}).partial(),
]);

type BaseConfig = {
/**
* Browser to use: chromium, firefox, or webkit
Expand Down

0 comments on commit dbf5180

Please sign in to comment.