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.
Files changed (197) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -2
  3. package/assets/logo/Logo-horizontal.png +0 -0
  4. package/dist/adapters/storybook/index.d.ts +5 -0
  5. package/dist/adapters/storybook/index.js +4 -0
  6. package/dist/adapters/storybook/index.js.map +1 -0
  7. package/dist/adapters/storybook/provider.d.ts +24 -0
  8. package/dist/adapters/storybook/provider.js +114 -0
  9. package/dist/adapters/storybook/provider.js.map +1 -0
  10. package/dist/adapters/storybook/scenarios.d.ts +30 -0
  11. package/dist/adapters/storybook/scenarios.js +64 -0
  12. package/dist/adapters/storybook/scenarios.js.map +1 -0
  13. package/dist/adapters/storybook/static-server.d.ts +10 -0
  14. package/dist/adapters/storybook/static-server.js +105 -0
  15. package/dist/adapters/storybook/static-server.js.map +1 -0
  16. package/dist/adapters/storybook/storybook-index.d.ts +32 -0
  17. package/dist/adapters/storybook/storybook-index.js +35 -0
  18. package/dist/adapters/storybook/storybook-index.js.map +1 -0
  19. package/dist/baselines/environment-check.d.ts +7 -0
  20. package/dist/baselines/environment-check.js +24 -0
  21. package/dist/baselines/environment-check.js.map +1 -0
  22. package/dist/baselines/environment-key.d.ts +8 -0
  23. package/dist/baselines/environment-key.js +12 -0
  24. package/dist/baselines/environment-key.js.map +1 -0
  25. package/dist/baselines/file-store.d.ts +12 -0
  26. package/dist/baselines/file-store.js +81 -0
  27. package/dist/baselines/file-store.js.map +1 -0
  28. package/dist/baselines/git-store.d.ts +16 -0
  29. package/dist/baselines/git-store.js +150 -0
  30. package/dist/baselines/git-store.js.map +1 -0
  31. package/dist/baselines/memory-store.d.ts +3 -0
  32. package/dist/baselines/memory-store.js +15 -0
  33. package/dist/baselines/memory-store.js.map +1 -0
  34. package/dist/baselines/metadata.d.ts +16 -0
  35. package/dist/baselines/metadata.js +84 -0
  36. package/dist/baselines/metadata.js.map +1 -0
  37. package/dist/baselines/types.d.ts +33 -0
  38. package/dist/baselines/types.js +2 -0
  39. package/dist/baselines/types.js.map +1 -0
  40. package/dist/browser/playwright/capturer.d.ts +2 -0
  41. package/dist/browser/playwright/capturer.js +142 -0
  42. package/dist/browser/playwright/capturer.js.map +1 -0
  43. package/dist/browser/playwright/environment.d.ts +4 -0
  44. package/dist/browser/playwright/environment.js +36 -0
  45. package/dist/browser/playwright/environment.js.map +1 -0
  46. package/dist/browser/playwright/index.d.ts +1 -0
  47. package/dist/browser/playwright/index.js +2 -0
  48. package/dist/browser/playwright/index.js.map +1 -0
  49. package/dist/browser/types.d.ts +43 -0
  50. package/dist/browser/types.js +2 -0
  51. package/dist/browser/types.js.map +1 -0
  52. package/dist/ci/github-summary.d.ts +5 -0
  53. package/dist/ci/github-summary.js +110 -0
  54. package/dist/ci/github-summary.js.map +1 -0
  55. package/dist/cli/baseline-ref.d.ts +6 -0
  56. package/dist/cli/baseline-ref.js +11 -0
  57. package/dist/cli/baseline-ref.js.map +1 -0
  58. package/dist/cli/bin.d.ts +2 -0
  59. package/dist/cli/bin.js +13 -0
  60. package/dist/cli/bin.js.map +1 -0
  61. package/dist/cli/commands/baseline.d.ts +3 -0
  62. package/dist/cli/commands/baseline.js +90 -0
  63. package/dist/cli/commands/baseline.js.map +1 -0
  64. package/dist/cli/commands/capture.d.ts +3 -0
  65. package/dist/cli/commands/capture.js +42 -0
  66. package/dist/cli/commands/capture.js.map +1 -0
  67. package/dist/cli/commands/config.d.ts +3 -0
  68. package/dist/cli/commands/config.js +25 -0
  69. package/dist/cli/commands/config.js.map +1 -0
  70. package/dist/cli/commands/doctor.d.ts +3 -0
  71. package/dist/cli/commands/doctor.js +19 -0
  72. package/dist/cli/commands/doctor.js.map +1 -0
  73. package/dist/cli/commands/report.d.ts +3 -0
  74. package/dist/cli/commands/report.js +16 -0
  75. package/dist/cli/commands/report.js.map +1 -0
  76. package/dist/cli/commands/scenarios.d.ts +3 -0
  77. package/dist/cli/commands/scenarios.js +30 -0
  78. package/dist/cli/commands/scenarios.js.map +1 -0
  79. package/dist/cli/commands/test.d.ts +3 -0
  80. package/dist/cli/commands/test.js +285 -0
  81. package/dist/cli/commands/test.js.map +1 -0
  82. package/dist/cli/context.d.ts +21 -0
  83. package/dist/cli/context.js +22 -0
  84. package/dist/cli/context.js.map +1 -0
  85. package/dist/cli/doctor.d.ts +12 -0
  86. package/dist/cli/doctor.js +113 -0
  87. package/dist/cli/doctor.js.map +1 -0
  88. package/dist/cli/format.d.ts +17 -0
  89. package/dist/cli/format.js +128 -0
  90. package/dist/cli/format.js.map +1 -0
  91. package/dist/cli/impact.d.ts +16 -0
  92. package/dist/cli/impact.js +63 -0
  93. package/dist/cli/impact.js.map +1 -0
  94. package/dist/cli/program.d.ts +11 -0
  95. package/dist/cli/program.js +70 -0
  96. package/dist/cli/program.js.map +1 -0
  97. package/dist/cli/session.d.ts +27 -0
  98. package/dist/cli/session.js +53 -0
  99. package/dist/cli/session.js.map +1 -0
  100. package/dist/comparison/compare.d.ts +11 -0
  101. package/dist/comparison/compare.js +41 -0
  102. package/dist/comparison/compare.js.map +1 -0
  103. package/dist/comparison/types.d.ts +34 -0
  104. package/dist/comparison/types.js +2 -0
  105. package/dist/comparison/types.js.map +1 -0
  106. package/dist/config/load.d.ts +23 -0
  107. package/dist/config/load.js +93 -0
  108. package/dist/config/load.js.map +1 -0
  109. package/dist/config/schema.d.ts +473 -0
  110. package/dist/config/schema.js +157 -0
  111. package/dist/config/schema.js.map +1 -0
  112. package/dist/core/artifacts.d.ts +6 -0
  113. package/dist/core/artifacts.js +2 -0
  114. package/dist/core/artifacts.js.map +1 -0
  115. package/dist/core/baseline-run.d.ts +37 -0
  116. package/dist/core/baseline-run.js +85 -0
  117. package/dist/core/baseline-run.js.map +1 -0
  118. package/dist/core/capture-settings.d.ts +6 -0
  119. package/dist/core/capture-settings.js +21 -0
  120. package/dist/core/capture-settings.js.map +1 -0
  121. package/dist/core/discovery.d.ts +3 -0
  122. package/dist/core/discovery.js +17 -0
  123. package/dist/core/discovery.js.map +1 -0
  124. package/dist/core/impact.d.ts +19 -0
  125. package/dist/core/impact.js +28 -0
  126. package/dist/core/impact.js.map +1 -0
  127. package/dist/core/pool.d.ts +5 -0
  128. package/dist/core/pool.js +21 -0
  129. package/dist/core/pool.js.map +1 -0
  130. package/dist/core/result.d.ts +117 -0
  131. package/dist/core/result.js +53 -0
  132. package/dist/core/result.js.map +1 -0
  133. package/dist/core/selection.d.ts +8 -0
  134. package/dist/core/selection.js +8 -0
  135. package/dist/core/selection.js.map +1 -0
  136. package/dist/core/test-run.d.ts +40 -0
  137. package/dist/core/test-run.js +141 -0
  138. package/dist/core/test-run.js.map +1 -0
  139. package/dist/impact/git.d.ts +17 -0
  140. package/dist/impact/git.js +55 -0
  141. package/dist/impact/git.js.map +1 -0
  142. package/dist/impact/storybook.d.ts +16 -0
  143. package/dist/impact/storybook.js +324 -0
  144. package/dist/impact/storybook.js.map +1 -0
  145. package/dist/impact/types.d.ts +28 -0
  146. package/dist/impact/types.js +23 -0
  147. package/dist/impact/types.js.map +1 -0
  148. package/dist/index.d.ts +4 -0
  149. package/dist/index.js +4 -0
  150. package/dist/index.js.map +1 -0
  151. package/dist/reference/build.d.ts +10 -0
  152. package/dist/reference/build.js +36 -0
  153. package/dist/reference/build.js.map +1 -0
  154. package/dist/reference/git-worktree.d.ts +8 -0
  155. package/dist/reference/git-worktree.js +77 -0
  156. package/dist/reference/git-worktree.js.map +1 -0
  157. package/dist/reference/open.d.ts +13 -0
  158. package/dist/reference/open.js +66 -0
  159. package/dist/reference/open.js.map +1 -0
  160. package/dist/reporting/artifacts.d.ts +8 -0
  161. package/dist/reporting/artifacts.js +23 -0
  162. package/dist/reporting/artifacts.js.map +1 -0
  163. package/dist/reporting/html.d.ts +4 -0
  164. package/dist/reporting/html.js +251 -0
  165. package/dist/reporting/html.js.map +1 -0
  166. package/dist/reporting/report.d.ts +12 -0
  167. package/dist/reporting/report.js +55 -0
  168. package/dist/reporting/report.js.map +1 -0
  169. package/dist/reporting/results-json.d.ts +36 -0
  170. package/dist/reporting/results-json.js +38 -0
  171. package/dist/reporting/results-json.js.map +1 -0
  172. package/dist/scenarios/glob.d.ts +7 -0
  173. package/dist/scenarios/glob.js +21 -0
  174. package/dist/scenarios/glob.js.map +1 -0
  175. package/dist/scenarios/model.d.ts +61 -0
  176. package/dist/scenarios/model.js +31 -0
  177. package/dist/scenarios/model.js.map +1 -0
  178. package/dist/scenarios/schema.d.ts +8 -0
  179. package/dist/scenarios/schema.js +70 -0
  180. package/dist/scenarios/schema.js.map +1 -0
  181. package/dist/shared/environment.d.ts +23 -0
  182. package/dist/shared/environment.js +2 -0
  183. package/dist/shared/environment.js.map +1 -0
  184. package/dist/shared/errors.d.ts +23 -0
  185. package/dist/shared/errors.js +29 -0
  186. package/dist/shared/errors.js.map +1 -0
  187. package/dist/shared/png.d.ts +3 -0
  188. package/dist/shared/png.js +14 -0
  189. package/dist/shared/png.js.map +1 -0
  190. package/dist/shared/size.d.ts +4 -0
  191. package/dist/shared/size.js +2 -0
  192. package/dist/shared/size.js.map +1 -0
  193. package/docs/architecture.md +176 -0
  194. package/docs/ci.md +86 -0
  195. package/docs/impact.md +61 -0
  196. package/docs/publishing.md +35 -0
  197. package/package.json +58 -4
@@ -0,0 +1,128 @@
1
+ function plural(count, singular, pluralForm = `${singular}s`) {
2
+ return `${count} ${count === 1 ? singular : pluralForm}`;
3
+ }
4
+ export function formatEnvironment(environment) {
5
+ const { browser, automation, os } = environment;
6
+ return `Chromium ${browser.version} on ${os.platform}/${os.arch} (${automation.name} ${automation.version})`;
7
+ }
8
+ /** One line per scenario result. Returns undefined for passes unless `verbose` is set. */
9
+ export function formatScenarioResult(result, verbose, reference) {
10
+ const { id } = result.scenario;
11
+ const note = result.clipped === true ? ' (clipped by the viewport)' : '';
12
+ const { outcome } = result;
13
+ switch (outcome.status) {
14
+ case 'passed':
15
+ return verbose ? ` pass ${id}${note}` : undefined;
16
+ case 'regression':
17
+ if (outcome.cause === 'dimensions') {
18
+ const { expected, actual } = outcome;
19
+ return ` FAIL ${id} size changed ${expected.width}x${expected.height} -> ${actual.width}x${actual.height}${note}`;
20
+ }
21
+ return ` FAIL ${id} ${(outcome.stats.diffRatio * 100).toFixed(2)}% (${outcome.stats.diffPixels} of ${outcome.stats.totalPixels} px differ)${note}`;
22
+ case 'changed':
23
+ return ` CHG ${id} ${outcome.change === 'added' ? 'new baseline' : 'baseline update'} proposed by this change${note}`;
24
+ case 'missing-baseline':
25
+ return reference === undefined
26
+ ? ` NEW ${id} no baseline${note}`
27
+ : ` NEW ${id} no matching scenario on ${reference}${note}`;
28
+ case 'error':
29
+ return ` ERR ${id} [${outcome.error.phase}] ${outcome.error.message}`;
30
+ }
31
+ }
32
+ export function formatTestSummary(result, summary, options) {
33
+ const lines = [''];
34
+ lines.push(`${plural(summary.total, 'scenario')}: ${summary.passed} passed, ` +
35
+ `${plural(summary.regressions, 'regression')}, ` +
36
+ (summary.changed > 0 ? `${summary.changed} changed by this change, ` : '') +
37
+ (result.reference !== undefined
38
+ ? `${plural(summary.missingBaselines, 'new scenario')} absent from reference, `
39
+ : `${summary.missingBaselines} missing ${summary.missingBaselines === 1 ? 'baseline' : 'baselines'}, `) +
40
+ `${plural(summary.errors, 'error')}`);
41
+ if (summary.changed > 0) {
42
+ lines.push('', `${summary.changed} visual ${summary.changed === 1 ? 'change is' : 'changes are'} proposed by this change`, 'and do not fail the run. Review the baseline images in the pull request to approve them.');
43
+ }
44
+ if ((result.removed ?? []).length > 0) {
45
+ lines.push('', `${plural((result.removed ?? []).length, 'baseline')} removed by this change:`, ...(result.removed ?? []).map((id) => ` ${id}`));
46
+ }
47
+ if (result.obsolete.length > 0) {
48
+ const verdict = options.failOnObsolete ? 'fails the run' : 'warning only';
49
+ lines.push('', result.reference !== undefined
50
+ ? `${plural(result.obsolete.length, 'scenario')} removed since ${result.reference.ref} (${verdict}):`
51
+ : `${plural(result.obsolete.length, 'obsolete baseline')} with no matching scenario (${verdict}):`, ...result.obsolete.map((id) => ` ${id}`), ...(result.reference === undefined
52
+ ? ['Remove them with "viewev baseline prune --yes".']
53
+ : []));
54
+ }
55
+ if (result.selection !== undefined) {
56
+ lines.push('', ...formatSelectionNote(result.selection));
57
+ }
58
+ for (const warning of result.warnings ?? [])
59
+ lines.push('', `Warning: ${warning}`);
60
+ if (summary.missingBaselines > 0) {
61
+ lines.push('', result.reference !== undefined
62
+ ? 'These scenarios have no matching story in the target branch; review their screenshots in the report.'
63
+ : 'Create missing baselines with "viewev baseline create".');
64
+ }
65
+ if (summary.regressions > 0) {
66
+ if (result.reference !== undefined) {
67
+ lines.push('', `Review the visual differences from the freshly captured ${result.reference.ref} UI in the report.`);
68
+ }
69
+ else {
70
+ lines.push('', 'If the changes are intended, approve them with "viewev baseline update --filter <id>"', 'and review the changed images in Git before committing.');
71
+ }
72
+ }
73
+ lines.push('');
74
+ if (result.reference !== undefined) {
75
+ lines.push(`Reference: ${result.reference.ref} (${result.reference.commit.slice(0, 12)})`);
76
+ }
77
+ else {
78
+ lines.push(`Baselines: ${options.baselineDir}`);
79
+ }
80
+ lines.push(`Report: ${options.reportPath}`, `Results: ${options.resultsPath}`, '');
81
+ return lines.join('\n');
82
+ }
83
+ /** Explains how the scenarios were chosen when impact analysis (--changed) took part. */
84
+ export function formatSelectionNote(selection) {
85
+ if (selection.mode === 'all') {
86
+ return [
87
+ `Impact analysis: every scenario runs (${selection.total}). ${selection.reason ?? ''}`.trim(),
88
+ ];
89
+ }
90
+ const since = selection.baseRef !== undefined
91
+ ? ` since the merge base with ${selection.baseRef} (${selection.changedFileCount ?? 0} changed files)`
92
+ : '';
93
+ return [
94
+ `Impact analysis: ${selection.selected} of ${selection.total} scenarios selected${since}.`,
95
+ 'Scenarios that were not selected were not tested, so this run is not full visual coverage.',
96
+ ];
97
+ }
98
+ export function formatBaselineResult(result, verbose) {
99
+ const { id } = result.scenario;
100
+ const note = result.clipped === true ? ' (clipped by the viewport)' : '';
101
+ const extra = result.message !== undefined ? ` ${result.message}` : '';
102
+ switch (result.action) {
103
+ case 'created':
104
+ return ` created ${id}${note}${extra}`;
105
+ case 'updated':
106
+ return ` updated ${id}${note}${extra}`;
107
+ case 'error':
108
+ return ` ERR ${id} ${result.message ?? ''}`;
109
+ case 'unchanged':
110
+ return verbose ? ` unchanged ${id}` : undefined;
111
+ case 'kept':
112
+ return verbose ? ` kept ${id} baseline already exists` : undefined;
113
+ }
114
+ }
115
+ export function formatBaselineSummary(results, baselineDir) {
116
+ const count = (action) => results.filter((result) => result.action === action).length;
117
+ const lines = [
118
+ '',
119
+ `Created ${count('created')}, updated ${count('updated')}, unchanged ${count('unchanged')}, ` +
120
+ `kept ${count('kept')}, errors ${count('error')}.`,
121
+ ];
122
+ if (count('created') + count('updated') > 0) {
123
+ lines.push(`Baselines are in ${baselineDir}. Review the changed images in Git before committing them.`);
124
+ }
125
+ lines.push('');
126
+ return lines.join('\n');
127
+ }
128
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/cli/format.ts"],"names":[],"mappings":"AAIA,SAAS,MAAM,CAAC,KAAa,EAAE,QAAgB,EAAE,UAAU,GAAG,GAAG,QAAQ,GAAG;IAC1E,OAAO,GAAG,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,WAA4B;IAC5D,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,GAAG,WAAW,CAAC;IAChD,OAAO,YAAY,OAAO,CAAC,OAAO,OAAO,EAAE,CAAC,QAAQ,IAAI,EAAE,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,GAAG,CAAC;AAC/G,CAAC;AAED,0FAA0F;AAC1F,MA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YACd,OAAO,OAAO,CAAC,CAAC,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACpD,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,CAAC,CAAC,gBAAgB,EAAE,2BAA2B,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,CAAC;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,OAAkC,EAClC,WAAmB;IAEnB,MAAM,KAAK,GAAG,CAAC,MAAgC,EAAU,EAAE,CACzD,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,MAAM,CAAC;IAC9D,MAAM,KAAK,GAAG;QACZ,EAAE;QACF,WAAW,KAAK,CAAC,SAAS,CAAC,aAAa,KAAK,CAAC,SAAS,CAAC,eAAe,KAAK,CAAC,WAAW,CAAC,IAAI;YAC3F,QAAQ,KAAK,CAAC,MAAM,CAAC,YAAY,KAAK,CAAC,OAAO,CAAC,GAAG;KACrD,CAAC;IACF,IAAI,KAAK,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5C,KAAK,CAAC,IAAI,CACR,oBAAoB,WAAW,4DAA4D,CAC5F,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { LoadedConfig } from '../config/load.js';
2
+ import type { ImpactPlan } from '../core/impact.js';
3
+ import type { ImpactInput, ImpactSelection } from '../impact/types.js';
4
+ import type { VisualScenario } from '../scenarios/model.js';
5
+ export interface ImpactRequest {
6
+ /** Overrides impact.baseRef from the config. */
7
+ readonly baseRef?: string;
8
+ }
9
+ /** Runs a project's impact extension, falling back to every scenario if it cannot be trusted. */
10
+ export declare function analyzeWithConfiguredImpact(loaded: LoadedConfig, input: ImpactInput): Promise<ImpactSelection>;
11
+ /**
12
+ * Picks the scenarios a change affects. Whenever the analysis cannot be trusted (Git cannot
13
+ * tell what changed, the module is broken or returns nonsense) every scenario runs: running
14
+ * too much is safe, running too little is not. The reason is recorded and shown in the report.
15
+ */
16
+ export declare function selectByImpact(loaded: LoadedConfig, discovered: readonly VisualScenario[], filtered: readonly VisualScenario[], request: ImpactRequest): Promise<ImpactPlan>;
@@ -0,0 +1,63 @@
1
+ import { pathToFileURL } from 'node:url';
2
+ import { applyImpact, fallbackToAll } from '../core/impact.js';
3
+ import { parseImpactSelection } from '../impact/types.js';
4
+ import { changedFiles } from '../impact/git.js';
5
+ import { ConfigError } from '../shared/errors.js';
6
+ function describe(error) {
7
+ return (error instanceof Error ? error.message : String(error)).split('\n')[0] ?? 'unknown error';
8
+ }
9
+ async function loadAnalyzer(file) {
10
+ let loaded;
11
+ try {
12
+ loaded = (await import(/* @vite-ignore */ pathToFileURL(file).href));
13
+ }
14
+ catch (error) {
15
+ throw new Error(`could not load ${file}: ${describe(error)}`, { cause: error });
16
+ }
17
+ if (typeof loaded.default !== 'function') {
18
+ throw new Error(`${file} must export a function as its default export`);
19
+ }
20
+ return loaded.default;
21
+ }
22
+ /** Runs a project's impact extension, falling back to every scenario if it cannot be trusted. */
23
+ export async function analyzeWithConfiguredImpact(loaded, input) {
24
+ const modulePath = loaded.paths.impactModule;
25
+ if (modulePath === undefined) {
26
+ return fallbackToAll('No provider impact analyzer is configured; every scenario runs.');
27
+ }
28
+ try {
29
+ const analyzer = await loadAnalyzer(modulePath);
30
+ return parseImpactSelection(await analyzer(input));
31
+ }
32
+ catch (error) {
33
+ return fallbackToAll(`The impact analysis failed (${describe(error)}), so every scenario runs.`);
34
+ }
35
+ }
36
+ /**
37
+ * Picks the scenarios a change affects. Whenever the analysis cannot be trusted (Git cannot
38
+ * tell what changed, the module is broken or returns nonsense) every scenario runs: running
39
+ * too much is safe, running too little is not. The reason is recorded and shown in the report.
40
+ */
41
+ export async function selectByImpact(loaded, discovered, filtered, request) {
42
+ const { impact } = loaded.config;
43
+ if (impact === undefined || loaded.paths.impactModule === undefined) {
44
+ throw new ConfigError('Impact analysis is not configured. Add impact: { module: "./impact.mjs" } to the config ' +
45
+ 'to use --changed. See docs/impact.md.');
46
+ }
47
+ const baseRef = request.baseRef ?? impact.baseRef;
48
+ let changes;
49
+ try {
50
+ changes = await changedFiles(loaded.rootDir, baseRef);
51
+ }
52
+ catch (error) {
53
+ return applyImpact(filtered, fallbackToAll(`Changed files could not be determined (${describe(error)}), so every scenario runs.`), { baseRef, changedFileCount: 0 });
54
+ }
55
+ const selection = await analyzeWithConfiguredImpact(loaded, {
56
+ changedFiles: changes.files,
57
+ scenarios: discovered,
58
+ repoRoot: changes.repoRoot,
59
+ baseRef,
60
+ });
61
+ return applyImpact(filtered, selection, { baseRef, changedFileCount: changes.files.length });
62
+ }
63
+ //# sourceMappingURL=impact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"impact.js","sourceRoot":"","sources":["../../src/cli/impact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAOlD,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC;AACpG,CAAC;AAED,KAAK,UAAU,YAAY,CAAC,IAAY;IACtC,IAAI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AS,IAAI,MAAM,CAAC,KAAK,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACpE,MAAM,IAAI,WAAW,CACnB,0FAA0F;YACxF,uCAAuC,CAC1C,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC;IAElD,IAAI,OAAiD,CAAC;IACtD,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,WAAW,CAChB,QAAQ,EACR,aAAa,CACX,0CAA0C,QAAQ,CAAC,KAAK,CAAC,4BAA4B,CACtF,EACD,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,EAAE,CACjC,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,2BAA2B,CAAC,MAAM,EAAE;QAC1D,YAAY,EAAE,OAAO,CAAC,KAAK;QAC3B,SAAS,EAAE,UAAU;QACrB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,OAAO;KACR,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;AAC/F,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Command } from 'commander';
2
+ import { ExitCode } from '../shared/errors.js';
3
+ import type { CliIO } from './context.js';
4
+ export type { CliIO } from './context.js';
5
+ interface BuiltProgram {
6
+ readonly program: Command;
7
+ exitCode(): ExitCode;
8
+ }
9
+ export declare function createProgram(io: CliIO): BuiltProgram;
10
+ /** Runs the CLI and returns the process exit code. Never calls process.exit. */
11
+ export declare function run(argv: readonly string[], io: CliIO): Promise<ExitCode>;
@@ -0,0 +1,70 @@
1
+ import { createRequire } from 'node:module';
2
+ import { Command, CommanderError } from 'commander';
3
+ import { ExitCode, ViewevError } from '../shared/errors.js';
4
+ import { registerBaselineCommand } from './commands/baseline.js';
5
+ import { registerCaptureCommand } from './commands/capture.js';
6
+ import { registerConfigCommand } from './commands/config.js';
7
+ import { registerDoctorCommand } from './commands/doctor.js';
8
+ import { registerReportCommand } from './commands/report.js';
9
+ import { registerScenariosCommand } from './commands/scenarios.js';
10
+ import { registerTestCommand } from './commands/test.js';
11
+ const nodeRequire = createRequire(import.meta.url);
12
+ // Resolves to the package root from both src/cli and dist/cli.
13
+ const { version } = nodeRequire('../../package.json');
14
+ const INFORMATIONAL_COMMANDER_CODES = new Set([
15
+ 'commander.help',
16
+ 'commander.helpDisplayed',
17
+ 'commander.version',
18
+ ]);
19
+ export function createProgram(io) {
20
+ const program = new Command();
21
+ let exitCode = ExitCode.Ok;
22
+ const context = {
23
+ io,
24
+ configPath: () => program.opts().config,
25
+ setExitCode: (code) => {
26
+ if (exitCode === ExitCode.Ok)
27
+ exitCode = code;
28
+ },
29
+ };
30
+ program
31
+ .name('viewev')
32
+ .description('Visual evaluation for the web. Open-source visual regression testing.')
33
+ .version(version)
34
+ .option('-c, --config <path>', 'path to the config file')
35
+ .configureOutput({
36
+ writeOut: (text) => io.stdout(text),
37
+ writeErr: (text) => io.stderr(text),
38
+ })
39
+ .exitOverride();
40
+ registerConfigCommand(program, context);
41
+ registerScenariosCommand(program, context);
42
+ registerTestCommand(program, context);
43
+ registerBaselineCommand(program, context);
44
+ registerReportCommand(program, context);
45
+ registerDoctorCommand(program, context);
46
+ registerCaptureCommand(program, context);
47
+ return { program, exitCode: () => exitCode };
48
+ }
49
+ /** Runs the CLI and returns the process exit code. Never calls process.exit. */
50
+ export async function run(argv, io) {
51
+ const built = createProgram(io);
52
+ try {
53
+ await built.program.parseAsync([...argv], { from: 'user' });
54
+ return built.exitCode();
55
+ }
56
+ catch (error) {
57
+ if (error instanceof CommanderError) {
58
+ // Commander has already printed its message through configureOutput.
59
+ return INFORMATIONAL_COMMANDER_CODES.has(error.code) ? ExitCode.Ok : ExitCode.ConfigError;
60
+ }
61
+ if (error instanceof ViewevError) {
62
+ io.stderr(`error: ${error.message}\n`);
63
+ return error.exitCode;
64
+ }
65
+ const detail = error instanceof Error ? (error.stack ?? error.message) : String(error);
66
+ io.stderr(`unexpected error: ${detail}\n`);
67
+ return ExitCode.ExecutionError;
68
+ }
69
+ }
70
+ //# sourceMappingURL=program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.js","sourceRoot":"","sources":["../../src/cli/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAKzD,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnD,+DAA+D;AAC/D,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAC,oBAAoB,CAAwB,CAAC;AAE7E,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC;IAC5C,gBAAgB;IAChB,yBAAyB;IACzB,mBAAmB;CACpB,CAAC,CAAC;AAOH,MAAM,UAAU,aAAa,CAAC,EAAS;IACrC,MAAM,OAAO,GAAG,IAA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,MAAM,KAAK,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IAChC,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5D,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,cAAc,EAAE,CAAC;YACpC,qEAAqE;YACrE,OAAO,6BAA6B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC;QAC5F,CAAC;QACD,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,EAAE,CAAC,MAAM,CAAC,UAAU,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;YACvC,OAAO,KAAK,CAAC,QAAQ,CAAC;QACxB,CAAC;QACD,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvF,EAAE,CAAC,MAAM,CAAC,qBAAqB,MAAM,IAAI,CAAC,CAAC;QAC3C,OAAO,QAAQ,CAAC,cAAc,CAAC;IACjC,CAAC;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { CaptureSession } from '../browser/types.js';
2
+ import type { LoadedConfig } from '../config/load.js';
3
+ import type { SelectionInfo } from '../core/result.js';
4
+ import type { VisualScenario } from '../scenarios/model.js';
5
+ import type { CommandContext } from './context.js';
6
+ import type { ImpactRequest } from './impact.js';
7
+ export interface Discovery {
8
+ readonly loaded: LoadedConfig;
9
+ /** Every scenario the provider found, before filtering. */
10
+ readonly discovered: readonly VisualScenario[];
11
+ /**
12
+ * The scenarios to run: those that pass the include and exclude filters (or --filter) and,
13
+ * with --changed, that the change affects.
14
+ */
15
+ readonly selected: readonly VisualScenario[];
16
+ /** Present when impact analysis took part in choosing `selected`. */
17
+ readonly impact?: SelectionInfo;
18
+ }
19
+ /** Loads the config, opens the Storybook, discovers and filters scenarios, then cleans up. */
20
+ export declare function withDiscovery<T>(context: CommandContext, filter: readonly string[] | undefined, action: (discovery: Discovery) => Promise<T>, impact?: ImpactRequest): Promise<T>;
21
+ /**
22
+ * Stops runs that would do nothing by mistake. With impact analysis an empty selection is a
23
+ * legitimate result ("this change affects no scenario"), unless the filters already left nothing.
24
+ */
25
+ export declare function requireSelection(discovery: Discovery): void;
26
+ /** Opens a browser session, prints which environment it is, and always closes it. */
27
+ export declare function withSession<T>(context: CommandContext, discovery: Discovery, action: (session: CaptureSession) => Promise<T>): Promise<T>;
@@ -0,0 +1,53 @@
1
+ import { createPlaywrightCapturer } from '../browser/playwright/index.js';
2
+ import { captureEnvironmentFrom } from '../core/capture-settings.js';
3
+ import { discoverScenarios } from '../core/discovery.js';
4
+ import { selectScenarios } from '../core/selection.js';
5
+ import { ConfigError } from '../shared/errors.js';
6
+ import { loadConfigFor, openConfiguredStorybook } from './context.js';
7
+ import { formatEnvironment } from './format.js';
8
+ import { selectByImpact } from './impact.js';
9
+ /** Loads the config, opens the Storybook, discovers and filters scenarios, then cleans up. */
10
+ export async function withDiscovery(context, filter, action, impact) {
11
+ const loaded = await loadConfigFor(context);
12
+ const source = await openConfiguredStorybook(loaded);
13
+ try {
14
+ const discovered = await discoverScenarios(source.provider, {
15
+ signal: new AbortController().signal,
16
+ });
17
+ const filtered = selectScenarios(discovered, {
18
+ include: filter ?? loaded.config.include,
19
+ exclude: loaded.config.exclude,
20
+ });
21
+ if (impact === undefined) {
22
+ return await action({ loaded, discovered, selected: filtered });
23
+ }
24
+ const plan = await selectByImpact(loaded, discovered, filtered, impact);
25
+ return await action({ loaded, discovered, selected: plan.selected, impact: plan.info });
26
+ }
27
+ finally {
28
+ await source.close();
29
+ }
30
+ }
31
+ /**
32
+ * Stops runs that would do nothing by mistake. With impact analysis an empty selection is a
33
+ * legitimate result ("this change affects no scenario"), unless the filters already left nothing.
34
+ */
35
+ export function requireSelection(discovery) {
36
+ const affectedNothing = discovery.impact !== undefined && discovery.impact.total > 0;
37
+ if (discovery.selected.length === 0 && !affectedNothing) {
38
+ throw new ConfigError(`No scenarios selected (${discovery.discovered.length} discovered). ` +
39
+ 'Check --filter, include and exclude.');
40
+ }
41
+ }
42
+ /** Opens a browser session, prints which environment it is, and always closes it. */
43
+ export async function withSession(context, discovery, action) {
44
+ const session = await createPlaywrightCapturer().open(captureEnvironmentFrom(discovery.loaded.config));
45
+ try {
46
+ context.io.stdout(`${formatEnvironment(session.environment)}\n`);
47
+ return await action(session);
48
+ }
49
+ finally {
50
+ await session.close();
51
+ }
52
+ }
53
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/cli/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAG1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAgB7C,8FAA8F;AAC9F,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAuB,EACvB,MAAqC,EACrC,MAA4C,EAC5C,MAAsB;IAEtB,MAAM,MAAM,GAAG,MAAM,aAAa,C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CAAsC,CACzC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,qFAAqF;AACrF,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAuB,EACvB,SAAoB,EACpB,MAA+C;IAE/C,MAAM,OAAO,GAAG,MAAM,wBAAwB,EAAE,CAAC,IAAI,CACnD,sBAAsB,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAChD,CAAC;IACF,IAAI,CAAC;QACH,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACjE,OAAO,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { ImageComparator } from './types.js';
2
+ /**
3
+ * Pixel-level comparison with Pixelmatch.
4
+ *
5
+ * - Images of different dimensions are a failure; nothing is resized or padded.
6
+ * - Anti-aliased pixels are counted, because screenshots come from one deterministic
7
+ * environment and every pixel is expected to match.
8
+ * - The comparison passes when the number of differing pixels is within the tolerance, which
9
+ * is the larger of `maxDiffPixels` and `maxDiffRatio` times the total pixel count.
10
+ */
11
+ export declare const compareImages: ImageComparator;
@@ -0,0 +1,41 @@
1
+ import pixelmatch from 'pixelmatch';
2
+ import { PNG } from 'pngjs';
3
+ import { readPngSize } from '../shared/png.js';
4
+ function toBuffer(bytes) {
5
+ return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
6
+ }
7
+ /**
8
+ * Pixel-level comparison with Pixelmatch.
9
+ *
10
+ * - Images of different dimensions are a failure; nothing is resized or padded.
11
+ * - Anti-aliased pixels are counted, because screenshots come from one deterministic
12
+ * environment and every pixel is expected to match.
13
+ * - The comparison passes when the number of differing pixels is within the tolerance, which
14
+ * is the larger of `maxDiffPixels` and `maxDiffRatio` times the total pixel count.
15
+ */
16
+ export const compareImages = (baseline, actual, options) => {
17
+ const expectedSize = readPngSize(baseline);
18
+ const actualSize = readPngSize(actual);
19
+ if (expectedSize.width !== actualSize.width || expectedSize.height !== actualSize.height) {
20
+ return { kind: 'mismatch', cause: 'dimensions', expected: expectedSize, actual: actualSize };
21
+ }
22
+ const expectedImage = PNG.sync.read(toBuffer(baseline));
23
+ const actualImage = PNG.sync.read(toBuffer(actual));
24
+ const { width, height } = expectedImage;
25
+ const diffImage = new PNG({ width, height });
26
+ const diffPixels = pixelmatch(expectedImage.data, actualImage.data, diffImage.data, width, height, {
27
+ threshold: options.colorThreshold,
28
+ includeAA: true,
29
+ });
30
+ const totalPixels = width * height;
31
+ const stats = {
32
+ diffPixels,
33
+ totalPixels,
34
+ diffRatio: totalPixels === 0 ? 0 : diffPixels / totalPixels,
35
+ };
36
+ const tolerance = Math.max(options.maxDiffPixels, options.maxDiffRatio === undefined ? 0 : Math.floor(options.maxDiffRatio * totalPixels));
37
+ if (diffPixels <= tolerance)
38
+ return { kind: 'match', stats };
39
+ return { kind: 'mismatch', cause: 'pixels', stats, diffPng: PNG.sync.write(diffImage) };
40
+ };
41
+ //# sourceMappingURL=compare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare.js","sourceRoot":"","sources":["../../src/comparison/compare.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,SAAS,QAAQ,CAAC,KAAiB;IACjC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AACvE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAoB,CAC5C,QAAoB,EACpB,MAAkB,EAClB,OAA0B,EACR,EAAE;IACpB,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AC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,GAAG,WAAW,CAAC,CACxF,CAAC;IACF,IAAI,UAAU,IAAI,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAE7D,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;AAC1F,CAAC,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { Size } from '../shared/size.js';
2
+ export interface ComparisonOptions {
3
+ /** Pixelmatch per-pixel perceptual (YIQ) distance, 0 (exact) to 1. */
4
+ readonly colorThreshold: number;
5
+ /** Number of differing pixels that is tolerated. */
6
+ readonly maxDiffPixels: number;
7
+ /**
8
+ * Ratio of differing pixels that is tolerated (0 to 1). The tolerance applied is the larger
9
+ * of `maxDiffPixels` and `maxDiffRatio` times the number of pixels.
10
+ */
11
+ readonly maxDiffRatio?: number;
12
+ }
13
+ export interface DiffStats {
14
+ readonly diffPixels: number;
15
+ readonly totalPixels: number;
16
+ /** diffPixels / totalPixels, between 0 and 1. */
17
+ readonly diffRatio: number;
18
+ }
19
+ export type ComparisonResult = {
20
+ readonly kind: 'match';
21
+ readonly stats: DiffStats;
22
+ } | {
23
+ readonly kind: 'mismatch';
24
+ readonly cause: 'pixels';
25
+ readonly stats: DiffStats;
26
+ readonly diffPng: Uint8Array;
27
+ } | {
28
+ readonly kind: 'mismatch';
29
+ readonly cause: 'dimensions';
30
+ readonly expected: Size;
31
+ readonly actual: Size;
32
+ };
33
+ /** Compares an approved baseline with a new screenshot. Pure: no I/O. */
34
+ export type ImageComparator = (baseline: Uint8Array, actual: Uint8Array, options: ComparisonOptions) => ComparisonResult;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/comparison/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ import type { ViewevConfig } from './schema.js';
2
+ export declare const CONFIG_FILE_NAMES: readonly ["viewev.config.mjs", "viewev.config.js", "viewev.config.json"];
3
+ export interface ResolvedPaths {
4
+ readonly baselines: string;
5
+ readonly report: string;
6
+ readonly storybookStaticDir?: string;
7
+ /** Absolute path of the impact analysis module, when impact analysis is configured. */
8
+ readonly impactModule?: string;
9
+ }
10
+ export interface LoadedConfig {
11
+ /** Directory of the config file; all relative paths in the config resolve against it. */
12
+ readonly rootDir: string;
13
+ readonly configFile: string;
14
+ readonly config: ViewevConfig;
15
+ readonly paths: ResolvedPaths;
16
+ }
17
+ export interface LoadConfigOptions {
18
+ readonly cwd: string;
19
+ /** Explicit config file (absolute, or relative to cwd). Skips discovery. */
20
+ readonly configPath?: string;
21
+ }
22
+ export declare function parseConfig(raw: unknown, source?: string): ViewevConfig;
23
+ export declare function loadConfig(options: LoadConfigOptions): Promise<LoadedConfig>;
@@ -0,0 +1,93 @@
1
+ import { access, readFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { ConfigError } from '../shared/errors.js';
5
+ import { configSchema } from './schema.js';
6
+ export const CONFIG_FILE_NAMES = [
7
+ 'viewev.config.mjs',
8
+ 'viewev.config.js',
9
+ 'viewev.config.json',
10
+ ];
11
+ async function exists(file) {
12
+ try {
13
+ await access(file);
14
+ return true;
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }
20
+ async function findConfigFile(options) {
21
+ if (options.configPath !== undefined) {
22
+ const explicit = path.resolve(options.cwd, options.configPath);
23
+ if (!(await exists(explicit))) {
24
+ throw new ConfigError(`Config file not found: ${explicit}`);
25
+ }
26
+ return explicit;
27
+ }
28
+ const found = [];
29
+ for (const name of CONFIG_FILE_NAMES) {
30
+ const candidate = path.join(options.cwd, name);
31
+ if (await exists(candidate))
32
+ found.push(candidate);
33
+ }
34
+ if (found.length === 0) {
35
+ throw new ConfigError(`No config file found in ${options.cwd}. Create one of: ${CONFIG_FILE_NAMES.join(', ')}.`);
36
+ }
37
+ if (found.length > 1) {
38
+ const names = found.map((file) => path.basename(file)).join(', ');
39
+ throw new ConfigError(`Multiple config files found (${names}). Keep only one.`);
40
+ }
41
+ return found[0];
42
+ }
43
+ async function readRawConfig(file) {
44
+ if (path.extname(file) === '.json') {
45
+ const text = await readFile(file, 'utf8');
46
+ try {
47
+ return JSON.parse(text);
48
+ }
49
+ catch (error) {
50
+ throw new ConfigError(`Config file is not valid JSON: ${file}`, { cause: error });
51
+ }
52
+ }
53
+ let module;
54
+ try {
55
+ module = (await import(/* @vite-ignore */ pathToFileURL(file).href));
56
+ }
57
+ catch (error) {
58
+ const reason = error instanceof Error ? error.message : String(error);
59
+ throw new ConfigError(`Could not load config file ${file}: ${reason}`, { cause: error });
60
+ }
61
+ if (module.default === undefined) {
62
+ throw new ConfigError(`Config file must have a default export: ${file}`);
63
+ }
64
+ return module.default;
65
+ }
66
+ function formatIssues(error) {
67
+ return error.issues
68
+ .map((issue) => ` - ${issue.path.length > 0 ? issue.path.join('.') : '(root)'}: ${issue.message}`)
69
+ .join('\n');
70
+ }
71
+ export function parseConfig(raw, source = 'config') {
72
+ const parsed = configSchema.safeParse(raw);
73
+ if (!parsed.success) {
74
+ throw new ConfigError(`Invalid ${source}:\n${formatIssues(parsed.error)}`);
75
+ }
76
+ return parsed.data;
77
+ }
78
+ export async function loadConfig(options) {
79
+ const configFile = await findConfigFile(options);
80
+ const rootDir = path.dirname(configFile);
81
+ const raw = await readRawConfig(configFile);
82
+ const config = parseConfig(raw, `config (${path.basename(configFile)})`);
83
+ const staticDir = config.provider.staticDir;
84
+ const impactModule = config.impact?.module;
85
+ const paths = {
86
+ baselines: path.resolve(rootDir, config.baselines.dir),
87
+ report: path.resolve(rootDir, config.report.dir),
88
+ ...(staticDir !== undefined ? { storybookStaticDir: path.resolve(rootDir, staticDir) } : {}),
89
+ ...(impactModule !== undefined ? { impactModule: path.resolve(rootDir, impactModule) } : {}),
90
+ };
91
+ return { rootDir, configFile, config, paths };
92
+ }
93
+ //# sourceMappingURL=load.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.js","sourceRoot":"","sources":["../../src/config/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,mBAAmB;IACnB,kBAAkB;IAClB,oBAAoB;CACZ,CAAC;AAwBX,KAAK,UAAU,MAAM,CAAC,IAAY;IAChC,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,OAA0B;IACtD,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAC/D,IAAI,CAAC,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,WAAW,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE,CAAC;QACrC,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