viewev 0.0.0-stage → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +148 -2
- package/assets/logo/Logo-horizontal.png +0 -0
- package/dist/adapters/storybook/index.d.ts +5 -0
- package/dist/adapters/storybook/index.js +4 -0
- package/dist/adapters/storybook/index.js.map +1 -0
- package/dist/adapters/storybook/provider.d.ts +24 -0
- package/dist/adapters/storybook/provider.js +114 -0
- package/dist/adapters/storybook/provider.js.map +1 -0
- package/dist/adapters/storybook/scenarios.d.ts +30 -0
- package/dist/adapters/storybook/scenarios.js +64 -0
- package/dist/adapters/storybook/scenarios.js.map +1 -0
- package/dist/adapters/storybook/static-server.d.ts +10 -0
- package/dist/adapters/storybook/static-server.js +105 -0
- package/dist/adapters/storybook/static-server.js.map +1 -0
- package/dist/adapters/storybook/storybook-index.d.ts +32 -0
- package/dist/adapters/storybook/storybook-index.js +35 -0
- package/dist/adapters/storybook/storybook-index.js.map +1 -0
- package/dist/baselines/environment-check.d.ts +7 -0
- package/dist/baselines/environment-check.js +24 -0
- package/dist/baselines/environment-check.js.map +1 -0
- package/dist/baselines/environment-key.d.ts +8 -0
- package/dist/baselines/environment-key.js +12 -0
- package/dist/baselines/environment-key.js.map +1 -0
- package/dist/baselines/file-store.d.ts +12 -0
- package/dist/baselines/file-store.js +81 -0
- package/dist/baselines/file-store.js.map +1 -0
- package/dist/baselines/git-store.d.ts +16 -0
- package/dist/baselines/git-store.js +150 -0
- package/dist/baselines/git-store.js.map +1 -0
- package/dist/baselines/memory-store.d.ts +3 -0
- package/dist/baselines/memory-store.js +15 -0
- package/dist/baselines/memory-store.js.map +1 -0
- package/dist/baselines/metadata.d.ts +16 -0
- package/dist/baselines/metadata.js +84 -0
- package/dist/baselines/metadata.js.map +1 -0
- package/dist/baselines/types.d.ts +33 -0
- package/dist/baselines/types.js +2 -0
- package/dist/baselines/types.js.map +1 -0
- package/dist/browser/playwright/capturer.d.ts +2 -0
- package/dist/browser/playwright/capturer.js +142 -0
- package/dist/browser/playwright/capturer.js.map +1 -0
- package/dist/browser/playwright/environment.d.ts +4 -0
- package/dist/browser/playwright/environment.js +36 -0
- package/dist/browser/playwright/environment.js.map +1 -0
- package/dist/browser/playwright/index.d.ts +1 -0
- package/dist/browser/playwright/index.js +2 -0
- package/dist/browser/playwright/index.js.map +1 -0
- package/dist/browser/types.d.ts +43 -0
- package/dist/browser/types.js +2 -0
- package/dist/browser/types.js.map +1 -0
- package/dist/ci/github-summary.d.ts +5 -0
- package/dist/ci/github-summary.js +110 -0
- package/dist/ci/github-summary.js.map +1 -0
- package/dist/cli/baseline-ref.d.ts +6 -0
- package/dist/cli/baseline-ref.js +11 -0
- package/dist/cli/baseline-ref.js.map +1 -0
- package/dist/cli/bin.d.ts +2 -0
- package/dist/cli/bin.js +13 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/commands/baseline.d.ts +3 -0
- package/dist/cli/commands/baseline.js +90 -0
- package/dist/cli/commands/baseline.js.map +1 -0
- package/dist/cli/commands/capture.d.ts +3 -0
- package/dist/cli/commands/capture.js +42 -0
- package/dist/cli/commands/capture.js.map +1 -0
- package/dist/cli/commands/config.d.ts +3 -0
- package/dist/cli/commands/config.js +25 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +3 -0
- package/dist/cli/commands/doctor.js +19 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/report.d.ts +3 -0
- package/dist/cli/commands/report.js +16 -0
- package/dist/cli/commands/report.js.map +1 -0
- package/dist/cli/commands/scenarios.d.ts +3 -0
- package/dist/cli/commands/scenarios.js +30 -0
- package/dist/cli/commands/scenarios.js.map +1 -0
- package/dist/cli/commands/test.d.ts +3 -0
- package/dist/cli/commands/test.js +285 -0
- package/dist/cli/commands/test.js.map +1 -0
- package/dist/cli/context.d.ts +21 -0
- package/dist/cli/context.js +22 -0
- package/dist/cli/context.js.map +1 -0
- package/dist/cli/doctor.d.ts +12 -0
- package/dist/cli/doctor.js +113 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/format.d.ts +17 -0
- package/dist/cli/format.js +128 -0
- package/dist/cli/format.js.map +1 -0
- package/dist/cli/impact.d.ts +16 -0
- package/dist/cli/impact.js +63 -0
- package/dist/cli/impact.js.map +1 -0
- package/dist/cli/program.d.ts +11 -0
- package/dist/cli/program.js +70 -0
- package/dist/cli/program.js.map +1 -0
- package/dist/cli/session.d.ts +27 -0
- package/dist/cli/session.js +53 -0
- package/dist/cli/session.js.map +1 -0
- package/dist/comparison/compare.d.ts +11 -0
- package/dist/comparison/compare.js +41 -0
- package/dist/comparison/compare.js.map +1 -0
- package/dist/comparison/types.d.ts +34 -0
- package/dist/comparison/types.js +2 -0
- package/dist/comparison/types.js.map +1 -0
- package/dist/config/load.d.ts +23 -0
- package/dist/config/load.js +93 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/schema.d.ts +473 -0
- package/dist/config/schema.js +157 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/core/artifacts.d.ts +6 -0
- package/dist/core/artifacts.js +2 -0
- package/dist/core/artifacts.js.map +1 -0
- package/dist/core/baseline-run.d.ts +37 -0
- package/dist/core/baseline-run.js +85 -0
- package/dist/core/baseline-run.js.map +1 -0
- package/dist/core/capture-settings.d.ts +6 -0
- package/dist/core/capture-settings.js +21 -0
- package/dist/core/capture-settings.js.map +1 -0
- package/dist/core/discovery.d.ts +3 -0
- package/dist/core/discovery.js +17 -0
- package/dist/core/discovery.js.map +1 -0
- package/dist/core/impact.d.ts +19 -0
- package/dist/core/impact.js +28 -0
- package/dist/core/impact.js.map +1 -0
- package/dist/core/pool.d.ts +5 -0
- package/dist/core/pool.js +21 -0
- package/dist/core/pool.js.map +1 -0
- package/dist/core/result.d.ts +117 -0
- package/dist/core/result.js +53 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/selection.d.ts +8 -0
- package/dist/core/selection.js +8 -0
- package/dist/core/selection.js.map +1 -0
- package/dist/core/test-run.d.ts +40 -0
- package/dist/core/test-run.js +141 -0
- package/dist/core/test-run.js.map +1 -0
- package/dist/impact/git.d.ts +17 -0
- package/dist/impact/git.js +55 -0
- package/dist/impact/git.js.map +1 -0
- package/dist/impact/storybook.d.ts +16 -0
- package/dist/impact/storybook.js +324 -0
- package/dist/impact/storybook.js.map +1 -0
- package/dist/impact/types.d.ts +28 -0
- package/dist/impact/types.js +23 -0
- package/dist/impact/types.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/reference/build.d.ts +10 -0
- package/dist/reference/build.js +36 -0
- package/dist/reference/build.js.map +1 -0
- package/dist/reference/git-worktree.d.ts +8 -0
- package/dist/reference/git-worktree.js +77 -0
- package/dist/reference/git-worktree.js.map +1 -0
- package/dist/reference/open.d.ts +13 -0
- package/dist/reference/open.js +66 -0
- package/dist/reference/open.js.map +1 -0
- package/dist/reporting/artifacts.d.ts +8 -0
- package/dist/reporting/artifacts.js +23 -0
- package/dist/reporting/artifacts.js.map +1 -0
- package/dist/reporting/html.d.ts +4 -0
- package/dist/reporting/html.js +251 -0
- package/dist/reporting/html.js.map +1 -0
- package/dist/reporting/report.d.ts +12 -0
- package/dist/reporting/report.js +55 -0
- package/dist/reporting/report.js.map +1 -0
- package/dist/reporting/results-json.d.ts +36 -0
- package/dist/reporting/results-json.js +38 -0
- package/dist/reporting/results-json.js.map +1 -0
- package/dist/scenarios/glob.d.ts +7 -0
- package/dist/scenarios/glob.js +21 -0
- package/dist/scenarios/glob.js.map +1 -0
- package/dist/scenarios/model.d.ts +61 -0
- package/dist/scenarios/model.js +31 -0
- package/dist/scenarios/model.js.map +1 -0
- package/dist/scenarios/schema.d.ts +8 -0
- package/dist/scenarios/schema.js +70 -0
- package/dist/scenarios/schema.js.map +1 -0
- package/dist/shared/environment.d.ts +23 -0
- package/dist/shared/environment.js +2 -0
- package/dist/shared/environment.js.map +1 -0
- package/dist/shared/errors.d.ts +23 -0
- package/dist/shared/errors.js +29 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/png.d.ts +3 -0
- package/dist/shared/png.js +14 -0
- package/dist/shared/png.js.map +1 -0
- package/dist/shared/size.d.ts +4 -0
- package/dist/shared/size.js +2 -0
- package/dist/shared/size.js.map +1 -0
- package/docs/architecture.md +176 -0
- package/docs/ci.md +86 -0
- package/docs/impact.md +61 -0
- package/docs/publishing.md +35 -0
- package/package.json +58 -4
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Size } from '../shared/size.js';
|
|
2
|
+
declare const scenarioIdBrand: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* Stable identifier of a scenario. It is also used as a file name for baselines, so it is
|
|
5
|
+
* restricted to a set of characters that is safe on macOS, Linux and Windows
|
|
6
|
+
* (case-insensitive file systems, reserved device names, no path separators).
|
|
7
|
+
*/
|
|
8
|
+
export type ScenarioId = string & {
|
|
9
|
+
readonly [scenarioIdBrand]: true;
|
|
10
|
+
};
|
|
11
|
+
export declare const MAX_SCENARIO_ID_LENGTH = 120;
|
|
12
|
+
/** Returns a human-readable reason when the value is not a valid scenario ID. */
|
|
13
|
+
export declare function scenarioIdProblem(value: string): string | undefined;
|
|
14
|
+
export declare function isValidScenarioId(value: string): value is ScenarioId;
|
|
15
|
+
export type ScenarioTarget = {
|
|
16
|
+
readonly kind: 'url';
|
|
17
|
+
readonly url: string;
|
|
18
|
+
};
|
|
19
|
+
/** Where a scenario came from. Opaque to the core; used for display and debugging. */
|
|
20
|
+
export interface ScenarioOrigin {
|
|
21
|
+
readonly provider: string;
|
|
22
|
+
readonly ref: string;
|
|
23
|
+
/** The source file that defines the scenario, when the provider knows it (for impact analysis). */
|
|
24
|
+
readonly source?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ScenarioCaptureOptions {
|
|
27
|
+
/** CSS selector that must be present before the screenshot is taken. */
|
|
28
|
+
readonly waitForSelector?: string;
|
|
29
|
+
readonly disableAnimations?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ScenarioComparisonOptions {
|
|
32
|
+
readonly colorThreshold?: number;
|
|
33
|
+
readonly maxDiffPixels?: number;
|
|
34
|
+
readonly maxDiffRatio?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A UI state that Viewev can capture and evaluate. Provider-independent: the target is always
|
|
38
|
+
* a resolved URL, so the core never needs to know how the scenario was discovered.
|
|
39
|
+
*/
|
|
40
|
+
export interface VisualScenario {
|
|
41
|
+
readonly id: ScenarioId;
|
|
42
|
+
readonly name: string;
|
|
43
|
+
readonly group?: readonly string[];
|
|
44
|
+
readonly target: ScenarioTarget;
|
|
45
|
+
readonly origin: ScenarioOrigin;
|
|
46
|
+
readonly viewport: Size;
|
|
47
|
+
/** Extra axes such as theme; part of the scenario identity, opaque to the core. */
|
|
48
|
+
readonly variant?: Readonly<Record<string, string>>;
|
|
49
|
+
readonly capture?: ScenarioCaptureOptions;
|
|
50
|
+
readonly comparison?: ScenarioComparisonOptions;
|
|
51
|
+
readonly tags?: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
export interface ScenarioProviderContext {
|
|
54
|
+
readonly signal: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
/** Discovers scenarios. Storybook is the first implementation. */
|
|
57
|
+
export interface ScenarioProvider {
|
|
58
|
+
readonly name: string;
|
|
59
|
+
discover(context: ScenarioProviderContext): Promise<readonly VisualScenario[]>;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const MAX_SCENARIO_ID_LENGTH = 120;
|
|
2
|
+
const SCENARIO_ID_PATTERN = /^[a-z0-9][a-z0-9._@-]*$/;
|
|
3
|
+
const WINDOWS_RESERVED_NAMES = new Set([
|
|
4
|
+
'con',
|
|
5
|
+
'prn',
|
|
6
|
+
'aux',
|
|
7
|
+
'nul',
|
|
8
|
+
...Array.from({ length: 9 }, (_, i) => `com${i + 1}`),
|
|
9
|
+
...Array.from({ length: 9 }, (_, i) => `lpt${i + 1}`),
|
|
10
|
+
]);
|
|
11
|
+
/** Returns a human-readable reason when the value is not a valid scenario ID. */
|
|
12
|
+
export function scenarioIdProblem(value) {
|
|
13
|
+
if (value.length === 0)
|
|
14
|
+
return 'must not be empty';
|
|
15
|
+
if (value.length > MAX_SCENARIO_ID_LENGTH) {
|
|
16
|
+
return `must be at most ${MAX_SCENARIO_ID_LENGTH} characters`;
|
|
17
|
+
}
|
|
18
|
+
if (!SCENARIO_ID_PATTERN.test(value)) {
|
|
19
|
+
return 'may only contain lowercase letters, digits, ".", "_", "@" and "-", and must start with a letter or digit';
|
|
20
|
+
}
|
|
21
|
+
if (value.endsWith('.'))
|
|
22
|
+
return 'must not end with "."';
|
|
23
|
+
const base = value.split('.')[0] ?? value;
|
|
24
|
+
if (WINDOWS_RESERVED_NAMES.has(base))
|
|
25
|
+
return `"${base}" is a reserved file name on Windows`;
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
export function isValidScenarioId(value) {
|
|
29
|
+
return scenarioIdProblem(value) === undefined;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/scenarios/model.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAE1C,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAEtD,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACrD,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;CACtD,CAAC,CAAC;AAEH,iFAAiF;AACjF,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,mBAAmB,CAAC;IACnD,IAAI,KAAK,CAAC,MAAM,GAAG,sBAAsB,EAAE,CAAC;QAC1C,OAAO,mBAAmB,sBAAsB,aAAa,CAAC;IAChE,CAAC;IACD,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,OAAO,0GAA0G,CAAC;IACpH,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,uBAAuB,CAAC;IACxD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC;IAC1C,IAAI,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,IAAI,sCAAsC,CAAC;IAC5F,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,OAAO,iBAAiB,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ScenarioId, VisualScenario } from './model.js';
|
|
3
|
+
export declare const scenarioIdSchema: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, ScenarioId, string>;
|
|
4
|
+
/**
|
|
5
|
+
* Validates scenarios returned by a provider. A provider that returns malformed or duplicate
|
|
6
|
+
* scenarios is a bug in that provider, reported as an execution error.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateScenarios(input: unknown, providerName: string): VisualScenario[];
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ExitCode, ViewevError } from '../shared/errors.js';
|
|
3
|
+
import { scenarioIdProblem } from './model.js';
|
|
4
|
+
export const scenarioIdSchema = z
|
|
5
|
+
.string()
|
|
6
|
+
.superRefine((value, ctx) => {
|
|
7
|
+
const problem = scenarioIdProblem(value);
|
|
8
|
+
if (problem !== undefined) {
|
|
9
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `Invalid scenario id: ${problem}` });
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
.transform((value) => value);
|
|
13
|
+
const dimension = z.number().int().min(1).max(10_000);
|
|
14
|
+
const sizeSchema = z.object({ width: dimension, height: dimension }).strict();
|
|
15
|
+
const scenarioSchema = z
|
|
16
|
+
.object({
|
|
17
|
+
id: scenarioIdSchema,
|
|
18
|
+
name: z.string().min(1),
|
|
19
|
+
group: z.array(z.string().min(1)).optional(),
|
|
20
|
+
target: z.object({ kind: z.literal('url'), url: z.string().url() }).strict(),
|
|
21
|
+
origin: z
|
|
22
|
+
.object({
|
|
23
|
+
provider: z.string().min(1),
|
|
24
|
+
ref: z.string().min(1),
|
|
25
|
+
source: z.string().min(1).optional(),
|
|
26
|
+
})
|
|
27
|
+
.strict(),
|
|
28
|
+
viewport: sizeSchema,
|
|
29
|
+
variant: z.record(z.string()).optional(),
|
|
30
|
+
capture: z
|
|
31
|
+
.object({
|
|
32
|
+
waitForSelector: z.string().min(1).optional(),
|
|
33
|
+
disableAnimations: z.boolean().optional(),
|
|
34
|
+
})
|
|
35
|
+
.strict()
|
|
36
|
+
.optional(),
|
|
37
|
+
comparison: z
|
|
38
|
+
.object({
|
|
39
|
+
colorThreshold: z.number().min(0).max(1).optional(),
|
|
40
|
+
maxDiffPixels: z.number().int().min(0).optional(),
|
|
41
|
+
maxDiffRatio: z.number().min(0).max(1).optional(),
|
|
42
|
+
})
|
|
43
|
+
.strict()
|
|
44
|
+
.optional(),
|
|
45
|
+
tags: z.array(z.string()).optional(),
|
|
46
|
+
})
|
|
47
|
+
.strict();
|
|
48
|
+
/**
|
|
49
|
+
* Validates scenarios returned by a provider. A provider that returns malformed or duplicate
|
|
50
|
+
* scenarios is a bug in that provider, reported as an execution error.
|
|
51
|
+
*/
|
|
52
|
+
export function validateScenarios(input, providerName) {
|
|
53
|
+
const parsed = z.array(scenarioSchema).safeParse(input);
|
|
54
|
+
if (!parsed.success) {
|
|
55
|
+
const details = parsed.error.issues
|
|
56
|
+
.slice(0, 10)
|
|
57
|
+
.map((issue) => ` - ${issue.path.join('.') || '(root)'}: ${issue.message}`)
|
|
58
|
+
.join('\n');
|
|
59
|
+
throw new ViewevError(`Scenario provider "${providerName}" returned invalid scenarios:\n${details}`, ExitCode.ExecutionError);
|
|
60
|
+
}
|
|
61
|
+
const seen = new Set();
|
|
62
|
+
for (const scenario of parsed.data) {
|
|
63
|
+
if (seen.has(scenario.id)) {
|
|
64
|
+
throw new ViewevError(`Scenario provider "${providerName}" returned duplicate scenario id "${scenario.id}".`, ExitCode.ExecutionError);
|
|
65
|
+
}
|
|
66
|
+
seen.add(scenario.id);
|
|
67
|
+
}
|
|
68
|
+
return parsed.data;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/scenarios/schema.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type BrowserEngine = 'chromium';
|
|
2
|
+
export type Platform = 'darwin' | 'linux' | 'win32';
|
|
3
|
+
/**
|
|
4
|
+
* Facts about the environment that produced a screenshot. Stored with every baseline and
|
|
5
|
+
* every report so differences caused by the environment can be told apart from real changes.
|
|
6
|
+
*/
|
|
7
|
+
export interface EnvironmentInfo {
|
|
8
|
+
readonly browser: {
|
|
9
|
+
readonly name: BrowserEngine;
|
|
10
|
+
readonly version: string;
|
|
11
|
+
};
|
|
12
|
+
readonly automation: {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly version: string;
|
|
15
|
+
};
|
|
16
|
+
readonly os: {
|
|
17
|
+
readonly platform: Platform;
|
|
18
|
+
readonly arch: string;
|
|
19
|
+
readonly release: string;
|
|
20
|
+
};
|
|
21
|
+
/** True when running inside a container (for example the Playwright Docker image). */
|
|
22
|
+
readonly container: boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/shared/environment.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process exit codes.
|
|
3
|
+
*
|
|
4
|
+
* 0 everything passed
|
|
5
|
+
* 1 visual failures (regressions, missing baselines, and obsolete baselines when configured)
|
|
6
|
+
* 2 at least one execution error; takes precedence over 1 because the run is incomplete
|
|
7
|
+
* 3 configuration or usage error
|
|
8
|
+
*/
|
|
9
|
+
export declare const ExitCode: {
|
|
10
|
+
readonly Ok: 0;
|
|
11
|
+
readonly VisualFailure: 1;
|
|
12
|
+
readonly ExecutionError: 2;
|
|
13
|
+
readonly ConfigError: 3;
|
|
14
|
+
};
|
|
15
|
+
export type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];
|
|
16
|
+
/** An error whose message is meant for the user and maps to a process exit code. */
|
|
17
|
+
export declare class ViewevError extends Error {
|
|
18
|
+
readonly exitCode: ExitCode;
|
|
19
|
+
constructor(message: string, exitCode?: ExitCode, options?: ErrorOptions);
|
|
20
|
+
}
|
|
21
|
+
export declare class ConfigError extends ViewevError {
|
|
22
|
+
constructor(message: string, options?: ErrorOptions);
|
|
23
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process exit codes.
|
|
3
|
+
*
|
|
4
|
+
* 0 everything passed
|
|
5
|
+
* 1 visual failures (regressions, missing baselines, and obsolete baselines when configured)
|
|
6
|
+
* 2 at least one execution error; takes precedence over 1 because the run is incomplete
|
|
7
|
+
* 3 configuration or usage error
|
|
8
|
+
*/
|
|
9
|
+
export const ExitCode = {
|
|
10
|
+
Ok: 0,
|
|
11
|
+
VisualFailure: 1,
|
|
12
|
+
ExecutionError: 2,
|
|
13
|
+
ConfigError: 3,
|
|
14
|
+
};
|
|
15
|
+
/** An error whose message is meant for the user and maps to a process exit code. */
|
|
16
|
+
export class ViewevError extends Error {
|
|
17
|
+
exitCode;
|
|
18
|
+
constructor(message, exitCode = ExitCode.ExecutionError, options) {
|
|
19
|
+
super(message, options);
|
|
20
|
+
this.name = new.target.name;
|
|
21
|
+
this.exitCode = exitCode;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class ConfigError extends ViewevError {
|
|
25
|
+
constructor(message, options) {
|
|
26
|
+
super(message, ExitCode.ConfigError, options);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/shared/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,EAAE,EAAE,CAAC;IACL,aAAa,EAAE,CAAC;IAChB,cAAc,EAAE,CAAC;IACjB,WAAW,EAAE,CAAC;CACN,CAAC;AAIX,oFAAoF;AACpF,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,QAAQ,CAAW;IAE5B,YACE,OAAe,EACf,WAAqB,QAAQ,CAAC,cAAc,EAC5C,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,OAAO,WAAY,SAAQ,WAAW;IAC1C,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ExitCode, ViewevError } from './errors.js';
|
|
2
|
+
const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
3
|
+
const IHDR = [0x49, 0x48, 0x44, 0x52];
|
|
4
|
+
/** Reads the pixel dimensions from a PNG header without decoding the image. */
|
|
5
|
+
export function readPngSize(png) {
|
|
6
|
+
const hasSignature = PNG_SIGNATURE.every((byte, index) => png[index] === byte);
|
|
7
|
+
const hasHeader = IHDR.every((byte, index) => png[12 + index] === byte);
|
|
8
|
+
if (png.byteLength < 24 || !hasSignature || !hasHeader) {
|
|
9
|
+
throw new ViewevError('Not a valid PNG image.', ExitCode.ExecutionError);
|
|
10
|
+
}
|
|
11
|
+
const view = new DataView(png.buffer, png.byteOffset, png.byteLength);
|
|
12
|
+
return { width: view.getUint32(16), height: view.getUint32(20) };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=png.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"png.js","sourceRoot":"","sources":["../../src/shared/png.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGpD,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACvE,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAEtC,+EAA+E;AAC/E,MAAM,UAAU,WAAW,CAAC,GAAe;IACzC,MAAM,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;IAC/E,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;IACxE,IAAI,GAAG,CAAC,UAAU,GAAG,EAAE,IAAI,CAAC,YAAY,IAAI,CAAC,SAAS,EAAE,CAAC;QACvD,MAAM,IAAI,WAAW,CAAC,wBAAwB,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC3E,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;IACtE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.js","sourceRoot":"","sources":["../../src/shared/size.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Viewev architecture
|
|
2
|
+
|
|
3
|
+
Viewev is a modular monolith: one npm package with clear internal boundaries. This document is
|
|
4
|
+
the source of truth for those boundaries and for the decisions behind them.
|
|
5
|
+
|
|
6
|
+
## Principles
|
|
7
|
+
|
|
8
|
+
- Product-agnostic, framework-agnostic: no design-system logic in the core.
|
|
9
|
+
- Provider-independent: scenario discovery is separate from execution.
|
|
10
|
+
- Automation-independent: the core never sees Playwright types.
|
|
11
|
+
- Local-first: no hosted service, database or account.
|
|
12
|
+
- Deterministic: reproducible screenshots matter more than features.
|
|
13
|
+
- Fresh PR references: each pull request compares against a newly built capture of its target
|
|
14
|
+
branch; local image baselines remain an explicit optional workflow.
|
|
15
|
+
- No speculative abstractions: an interface exists only where it protects a real boundary.
|
|
16
|
+
|
|
17
|
+
## Modules and dependency rules
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
src/
|
|
21
|
+
cli/ commander wiring, output, exit codes. The composition root.
|
|
22
|
+
config/ zod schema, loader, defineConfig
|
|
23
|
+
core/ lifecycle orchestration and the result model (interfaces only)
|
|
24
|
+
scenarios/ VisualScenario, ScenarioProvider, validation
|
|
25
|
+
adapters/storybook/ index.json -> scenarios, built-in static server
|
|
26
|
+
impact/ changed-file analysis and Storybook dependency tracing
|
|
27
|
+
reference/ temporary Git worktrees, target-branch builds and cleanup
|
|
28
|
+
browser/ ScreenshotCapturer interface and types
|
|
29
|
+
browser/playwright/ the only code that imports Playwright
|
|
30
|
+
comparison/ pure image comparison with Pixelmatch
|
|
31
|
+
baselines/ filesystem layout, metadata, environment checks
|
|
32
|
+
reporting/ results.json, report artifacts and the static HTML report
|
|
33
|
+
shared/ errors and exit codes, size, environment info
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
ESLint enforces the rules (`eslint.config.js`):
|
|
37
|
+
|
|
38
|
+
- Only `src/browser/playwright` may import Playwright.
|
|
39
|
+
- `core` imports interfaces only: no adapters, no Playwright implementation, no `pixelmatch` or
|
|
40
|
+
`pngjs`, no `cli`.
|
|
41
|
+
- Only `cli` wires concrete adapters and implementations together.
|
|
42
|
+
|
|
43
|
+
## Scenario model
|
|
44
|
+
|
|
45
|
+
A scenario is a UI state Viewev can capture. Providers resolve everything provider-specific
|
|
46
|
+
(for Storybook, a story id becomes an `iframe.html` URL) so the core only sees a URL.
|
|
47
|
+
|
|
48
|
+
- `id` is stable and independent of the URL or port. It is also a file name, so it is limited
|
|
49
|
+
to lowercase letters, digits, `.`, `_`, `@` and `-`, and Windows reserved names are rejected.
|
|
50
|
+
- `variant` holds extra axes such as a theme. It is part of the scenario identity and opaque
|
|
51
|
+
to the core. Variants are modelled now and implemented later.
|
|
52
|
+
- Storybook's `index.json` contains no story parameters, only ids, titles, import paths, types
|
|
53
|
+
and tags. Per-scenario options therefore come from config rules or Storybook tags, never from
|
|
54
|
+
story parameters.
|
|
55
|
+
|
|
56
|
+
## Test lifecycle
|
|
57
|
+
|
|
58
|
+
1. Load and validate configuration.
|
|
59
|
+
2. Discover current-branch scenarios through the configured provider, then validate them.
|
|
60
|
+
3. For a fresh-reference run, check out and build the target branch, then discover its scenarios.
|
|
61
|
+
4. Compare Git changes with provider impact mapping before opening a capture session.
|
|
62
|
+
5. Capture only selected scenarios on both branches, with bounded concurrency and fresh contexts.
|
|
63
|
+
6. Compare corresponding screenshots and record regressions, new and removed scenarios, or errors.
|
|
64
|
+
7. Write `results.json`, the HTML report and the CI job summary.
|
|
65
|
+
8. Map the result to an exit code.
|
|
66
|
+
|
|
67
|
+
Exit codes: `0` passed, `1` visual failures, `2` execution errors (take precedence over `1`
|
|
68
|
+
because the run is incomplete), `3` configuration or usage error.
|
|
69
|
+
|
|
70
|
+
## Capture
|
|
71
|
+
|
|
72
|
+
Screenshots are always of the viewport, never the full page. Content larger than the viewport is
|
|
73
|
+
clipped, and the capture result reports this so it can be surfaced as a warning.
|
|
74
|
+
|
|
75
|
+
Determinism strategy (implemented in Phase 2): pinned Playwright and Chromium, fixed viewport and
|
|
76
|
+
device scale factor, fixed locale, timezone, colour scheme and reduced motion, waiting for
|
|
77
|
+
`document.fonts.ready` and the scenario's readiness selector, disabled animations and transitions,
|
|
78
|
+
and repeated capture until two consecutive screenshots are identical. Dynamic content is handled
|
|
79
|
+
by explicit configuration, never by hiding large areas.
|
|
80
|
+
|
|
81
|
+
## Comparison
|
|
82
|
+
|
|
83
|
+
- Pixelmatch with explicit semantics: `colorThreshold` (0 to 1) is the per-pixel perceptual
|
|
84
|
+
distance. The tolerance for a scenario is the larger of `maxDiffPixels` and `maxDiffRatio`
|
|
85
|
+
times the pixel count; more differing pixels than that fail the scenario. Anti-aliased pixels
|
|
86
|
+
are counted.
|
|
87
|
+
- A dimension mismatch is a failure, never a silent resize.
|
|
88
|
+
- Defaults (`colorThreshold: 0.1`, `maxDiffPixels: 0`) are validated in Phase 2 by a
|
|
89
|
+
repeated-capture determinism test.
|
|
90
|
+
|
|
91
|
+
## Baselines and target references
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
.viewev/baselines/<environment-key>/<scenario-id>.png
|
|
95
|
+
.viewev/baselines/<environment-key>/<scenario-id>.json # sidecar metadata
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
- The environment key is `<platform>-<browser>`, for example `linux-chromium`. Optional local
|
|
99
|
+
baselines remain environment-specific. PR references and actual captures are taken in the same
|
|
100
|
+
run and environment, so CI does not need committed image files.
|
|
101
|
+
- One sidecar per image avoids merge conflicts. It records the scenario id, environment (browser
|
|
102
|
+
and automation versions, OS), viewport, device scale factor, screenshot size, a SHA-256 of the
|
|
103
|
+
PNG and any variant. `schemaVersion` is the metadata format version; history is Git's job.
|
|
104
|
+
- `viewev test` never writes stored baselines. In PR mode, target-branch screenshots are held in
|
|
105
|
+
memory for the current run. Local `baseline create`, `baseline update` and `baseline prune`
|
|
106
|
+
remain available for projects that use image baselines.
|
|
107
|
+
- When `reference` is configured, the CLI makes a disposable worktree at the target Git ref,
|
|
108
|
+
runs project-defined install/build commands there, and captures the target UI into a memory
|
|
109
|
+
store. The store is discarded after comparison. No baseline approval commit is part of PR flow.
|
|
110
|
+
- Build commands are project configuration. Viewev does not choose a package manager or build
|
|
111
|
+
tool. The Storybook output is located using `provider.staticDir` inside the reference worktree.
|
|
112
|
+
- Baselines are stored in plain Git. Git LFS is not used for now.
|
|
113
|
+
|
|
114
|
+
## Pull requests
|
|
115
|
+
|
|
116
|
+
When `reference` is configured, CI compares screenshots from the PR against fresh captures from
|
|
117
|
+
the target branch. GitHub Actions provides `GITHUB_BASE_REF`; other CI systems can pass
|
|
118
|
+
`--compare-ref` or configure `reference.baseRef`. The target ref must be fetched before Viewev runs.
|
|
119
|
+
|
|
120
|
+
Before taking screenshots, the Storybook impact analyzer traces JavaScript, TypeScript and style
|
|
121
|
+
imports from each story. It selects stories whose dependency graph contains a changed file. If the
|
|
122
|
+
story entry or a dependency cannot be resolved, or a changed file cannot be mapped, Viewev selects
|
|
123
|
+
all scenarios. Other providers can supply `impact.module` to map their own source changes.
|
|
124
|
+
|
|
125
|
+
Scenarios on both refs are captured and compared. New stories are shown as new because the target
|
|
126
|
+
branch has no corresponding scenario. Removed stories are listed from the target branch inventory.
|
|
127
|
+
Pixel and dimension differences fail the run and include expected, actual and diff images in the
|
|
128
|
+
report.
|
|
129
|
+
|
|
130
|
+
CI security: tests run on `pull_request` with read-only permissions and no secrets. The target
|
|
131
|
+
branch build runs in that same untrusted job, so it must not require secrets. `pull_request_target`
|
|
132
|
+
is never combined with a checkout of PR code.
|
|
133
|
+
|
|
134
|
+
## Variants
|
|
135
|
+
|
|
136
|
+
A variant is another way of rendering every story, such as a theme or a narrow viewport. The
|
|
137
|
+
config lists them; the Storybook adapter expands each story into one scenario per variant with
|
|
138
|
+
ids like `button--primary@g100`, passing Storybook globals through the story URL. The core
|
|
139
|
+
never knows what a variant means. Local baseline sidecars record the variant.
|
|
140
|
+
|
|
141
|
+
## Dependencies
|
|
142
|
+
|
|
143
|
+
| Dependency | Why |
|
|
144
|
+
| ------------------------------------------ | -------------------------------------------------- |
|
|
145
|
+
| `commander` | CLI parsing |
|
|
146
|
+
| `zod` | Validation of config, provider output and metadata |
|
|
147
|
+
| `playwright-core` (Phase 2, exact version) | Browser automation, behind `ScreenshotCapturer` |
|
|
148
|
+
| `pixelmatch`, `pngjs` (Phase 3) | Pixel comparison and PNG encode and decode |
|
|
149
|
+
|
|
150
|
+
Sharp is not used in v1: nothing in the MVP needs resizing.
|
|
151
|
+
|
|
152
|
+
## Phases
|
|
153
|
+
|
|
154
|
+
1. Foundation: tooling, domain types, configuration, CLI skeleton (done).
|
|
155
|
+
2. Scenario discovery and capture: Storybook provider, capturer interface, Playwright adapter
|
|
156
|
+
(done).
|
|
157
|
+
3. Comparison and baselines: Pixelmatch, baseline store, `test` and `baseline` commands (done).
|
|
158
|
+
4. Reporting and CLI polish: static HTML report, `report` and `doctor` commands (done).
|
|
159
|
+
5. CI and branch-aware image baselines: GitHub Actions summary, optional legacy image-baseline
|
|
160
|
+
mode and impact-analysis extension were implemented.
|
|
161
|
+
6. Fresh target-branch comparison: disposable Git worktrees, project-defined reference builds,
|
|
162
|
+
in-memory reference captures and Storybook source-impact analysis are implemented. Consumer CI
|
|
163
|
+
validation remains. Carbon-specific config stays outside Viewev.
|
|
164
|
+
|
|
165
|
+
## Decision log
|
|
166
|
+
|
|
167
|
+
| Decision | Outcome |
|
|
168
|
+
| ------------------ | --------------------------------------------------------------------------------- |
|
|
169
|
+
| PR comparison | Capture the target branch and PR branch in the same run; store no approved images |
|
|
170
|
+
| Platforms | macOS, Linux and Windows; baselines keyed by environment |
|
|
171
|
+
| Capture area | Viewport only |
|
|
172
|
+
| Sharp | Dropped from v1; `pngjs` instead |
|
|
173
|
+
| Variants | Implemented in the Storybook adapter and baseline metadata |
|
|
174
|
+
| Obsolete baselines | Fail by default |
|
|
175
|
+
| Git LFS | Not for now |
|
|
176
|
+
| Package manager | Viewev publishes as an npm package; consumer build commands are project-defined |
|
package/docs/ci.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Running Viewev in GitHub Actions
|
|
2
|
+
|
|
3
|
+
Pull request runs compare the UI from the PR with a fresh build and capture from the target
|
|
4
|
+
branch. They do not download or update approved image baselines. Viewev creates a temporary Git
|
|
5
|
+
worktree for the target ref, runs the configured reference build commands there, and discards the
|
|
6
|
+
captured reference images after the run.
|
|
7
|
+
|
|
8
|
+
## Configure the reference build
|
|
9
|
+
|
|
10
|
+
`reference.build` contains commands that install and build the target branch's Storybook. They run
|
|
11
|
+
in order from the target checkout root. Use the same Node version, package manager and build
|
|
12
|
+
settings as the PR build.
|
|
13
|
+
|
|
14
|
+
For Yarn 4:
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
// viewev.config.mjs
|
|
18
|
+
export default {
|
|
19
|
+
provider: { type: 'storybook', staticDir: 'packages/react/storybook-static' },
|
|
20
|
+
reference: {
|
|
21
|
+
baseRef: 'origin/main',
|
|
22
|
+
build: [
|
|
23
|
+
{ command: 'corepack', args: ['yarn', 'install', '--immutable'] },
|
|
24
|
+
{ command: 'corepack', args: ['yarn', 'workspace', '@your-scope/react', 'storybook:build'] },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
For npm, use commands such as `{ command: 'npm', args: ['ci'] }` and
|
|
31
|
+
`{ command: 'npm', args: ['run', 'build-storybook'] }`. The command names and arguments are
|
|
32
|
+
project configuration; Viewev does not assume a package manager or workspace layout.
|
|
33
|
+
|
|
34
|
+
## Pull request workflow
|
|
35
|
+
|
|
36
|
+
```yaml
|
|
37
|
+
name: Visual tests
|
|
38
|
+
|
|
39
|
+
on: pull_request
|
|
40
|
+
|
|
41
|
+
permissions:
|
|
42
|
+
contents: read
|
|
43
|
+
|
|
44
|
+
jobs:
|
|
45
|
+
visual:
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
container: mcr.microsoft.com/playwright:v1.60.0-noble
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/checkout@v4
|
|
50
|
+
with:
|
|
51
|
+
fetch-depth: 0 # the target branch ref and merge base must be present
|
|
52
|
+
|
|
53
|
+
- uses: actions/setup-node@v4
|
|
54
|
+
with:
|
|
55
|
+
node-version-file: .nvmrc
|
|
56
|
+
cache: yarn
|
|
57
|
+
|
|
58
|
+
# Install and build the pull request UI using the repository's normal commands.
|
|
59
|
+
- run: corepack yarn install --immutable
|
|
60
|
+
- run: corepack yarn workspace @your-scope/react storybook:build
|
|
61
|
+
|
|
62
|
+
# GITHUB_BASE_REF selects the target branch automatically. Viewev builds that ref using
|
|
63
|
+
# reference.build, then captures only affected stories on both refs when it can map them.
|
|
64
|
+
- run: corepack yarn viewev test
|
|
65
|
+
|
|
66
|
+
- uses: actions/upload-artifact@v4
|
|
67
|
+
if: always()
|
|
68
|
+
with:
|
|
69
|
+
name: viewev-report
|
|
70
|
+
path: .viewev/report
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The PR capture runs with read-only permissions and no secrets. The target branch's build commands
|
|
74
|
+
also run inside this job, so they must not need secrets. Use `pull_request`; do not combine
|
|
75
|
+
`pull_request_target` with a checkout or build of PR code.
|
|
76
|
+
|
|
77
|
+
The built-in Storybook analyzer follows static JavaScript, TypeScript and stylesheet imports from
|
|
78
|
+
each story. Other providers can define `impact.module`; in a fresh-reference run, that module
|
|
79
|
+
receives the changed files, both scenario lists, and both repository roots. Viewev runs all
|
|
80
|
+
scenarios when source mapping is incomplete or a changed file cannot be mapped. The HTML report
|
|
81
|
+
and GitHub job summary show the target ref, selected scenarios, regressions and
|
|
82
|
+
expected/actual/diff images. New and removed stories are listed separately.
|
|
83
|
+
|
|
84
|
+
To select a different target manually, pass `viewev test --compare-ref <ref>`. The ref must be
|
|
85
|
+
available in the checkout. You can run a full capture with `--filter` patterns, but impact
|
|
86
|
+
analysis otherwise selects the affected scenarios before screenshots are taken.
|
package/docs/impact.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Impact analysis
|
|
2
|
+
|
|
3
|
+
When comparing a pull request with a freshly captured target branch, Viewev selects scenarios
|
|
4
|
+
before taking screenshots. The Storybook analyzer traces static JavaScript, TypeScript and
|
|
5
|
+
stylesheet imports starting from each story's `importPath`. Changed component, style, image and
|
|
6
|
+
font dependencies select the stories that use them.
|
|
7
|
+
|
|
8
|
+
The analyzer is conservative. It selects all scenarios when a story source is unavailable, an
|
|
9
|
+
import cannot be resolved, the project uses a dynamic import pattern that cannot be followed, or
|
|
10
|
+
a changed source/configuration file cannot be mapped. This protects coverage when Viewev cannot
|
|
11
|
+
make a confident selection. `--filter` and `include`/`exclude` still apply after impact selection.
|
|
12
|
+
|
|
13
|
+
For provider-specific logic, a project can still supply an analyzer module. `viewev test --changed`
|
|
14
|
+
uses this extension for non-reference runs:
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
// viewev.config.mjs
|
|
18
|
+
export default {
|
|
19
|
+
provider: { type: 'storybook', staticDir: 'storybook-static' },
|
|
20
|
+
impact: {
|
|
21
|
+
module: './viewev-impact.mjs',
|
|
22
|
+
baseRef: 'origin/main',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The module's default export receives `changedFiles`, all discovered current-branch `scenarios`,
|
|
28
|
+
`repoRoot`, and `baseRef`. During a fresh-reference run, it also receives `baseScenarios` and
|
|
29
|
+
`baseRepoRoot` for the target branch. It returns either `{ mode: 'all', reason }` or
|
|
30
|
+
`{ mode: 'subset', scenarios: { [scenarioId]: ['reason'] } }`:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
// viewev-impact.mjs
|
|
34
|
+
export default ({ changedFiles, scenarios }) => {
|
|
35
|
+
const changed = new Set(changedFiles);
|
|
36
|
+
const selected = {};
|
|
37
|
+
|
|
38
|
+
for (const scenario of scenarios) {
|
|
39
|
+
const source = scenario.origin.source?.replace(/^\.\//, '');
|
|
40
|
+
if (source !== undefined && changed.has(source)) {
|
|
41
|
+
selected[scenario.id] = [`source changed: ${source}`];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { mode: 'subset', scenarios: selected };
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Run `viewev test --changed` for legacy image-baseline comparisons; `--base <ref>` overrides
|
|
50
|
+
`impact.baseRef`. For fresh target-branch comparisons, configure `reference` and the same
|
|
51
|
+
`impact.module` is called with both scenario lists and repository roots. Changed files are measured
|
|
52
|
+
from the Git merge base and include committed, staged, working-tree, and non-ignored untracked
|
|
53
|
+
changes. The target ref must be available locally. If Git cannot determine the changes or the
|
|
54
|
+
analysis module fails or returns invalid data, Viewev runs every filtered scenario and records
|
|
55
|
+
why it fell back.
|
|
56
|
+
|
|
57
|
+
For Storybook projects using `reference`, no custom impact module is needed for common static
|
|
58
|
+
imports. The target and current Storybooks are both discovered, and the import graph on each side
|
|
59
|
+
is considered so story additions, removals and moved source files are handled. Other scenario
|
|
60
|
+
providers can supply their own mapping with `impact.module`. Dynamic branch comparison does not
|
|
61
|
+
read approved image baselines.
|