difflens 0.0.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/dist/cli.mjs ADDED
@@ -0,0 +1,661 @@
1
+ import {
2
+ loadConfig,
3
+ runTests
4
+ } from "./chunk-LVDSHTE4.mjs";
5
+
6
+ // node_modules/cac/dist/index.mjs
7
+ import { EventEmitter } from "events";
8
+ function toArr(any) {
9
+ return any == null ? [] : Array.isArray(any) ? any : [any];
10
+ }
11
+ function toVal(out, key, val, opts) {
12
+ var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
13
+ out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
14
+ }
15
+ function mri2(args, opts) {
16
+ args = args || [];
17
+ opts = opts || {};
18
+ var k, arr, arg, name, val, out = { _: [] };
19
+ var i = 0, j = 0, idx = 0, len = args.length;
20
+ const alibi = opts.alias !== void 0;
21
+ const strict = opts.unknown !== void 0;
22
+ const defaults = opts.default !== void 0;
23
+ opts.alias = opts.alias || {};
24
+ opts.string = toArr(opts.string);
25
+ opts.boolean = toArr(opts.boolean);
26
+ if (alibi) {
27
+ for (k in opts.alias) {
28
+ arr = opts.alias[k] = toArr(opts.alias[k]);
29
+ for (i = 0; i < arr.length; i++) {
30
+ (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
31
+ }
32
+ }
33
+ }
34
+ for (i = opts.boolean.length; i-- > 0; ) {
35
+ arr = opts.alias[opts.boolean[i]] || [];
36
+ for (j = arr.length; j-- > 0; ) opts.boolean.push(arr[j]);
37
+ }
38
+ for (i = opts.string.length; i-- > 0; ) {
39
+ arr = opts.alias[opts.string[i]] || [];
40
+ for (j = arr.length; j-- > 0; ) opts.string.push(arr[j]);
41
+ }
42
+ if (defaults) {
43
+ for (k in opts.default) {
44
+ name = typeof opts.default[k];
45
+ arr = opts.alias[k] = opts.alias[k] || [];
46
+ if (opts[name] !== void 0) {
47
+ opts[name].push(k);
48
+ for (i = 0; i < arr.length; i++) {
49
+ opts[name].push(arr[i]);
50
+ }
51
+ }
52
+ }
53
+ }
54
+ const keys = strict ? Object.keys(opts.alias) : [];
55
+ for (i = 0; i < len; i++) {
56
+ arg = args[i];
57
+ if (arg === "--") {
58
+ out._ = out._.concat(args.slice(++i));
59
+ break;
60
+ }
61
+ for (j = 0; j < arg.length; j++) {
62
+ if (arg.charCodeAt(j) !== 45) break;
63
+ }
64
+ if (j === 0) {
65
+ out._.push(arg);
66
+ } else if (arg.substring(j, j + 3) === "no-") {
67
+ name = arg.substring(j + 3);
68
+ if (strict && !~keys.indexOf(name)) {
69
+ return opts.unknown(arg);
70
+ }
71
+ out[name] = false;
72
+ } else {
73
+ for (idx = j + 1; idx < arg.length; idx++) {
74
+ if (arg.charCodeAt(idx) === 61) break;
75
+ }
76
+ name = arg.substring(j, idx);
77
+ val = arg.substring(++idx) || (i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i]);
78
+ arr = j === 2 ? [name] : name;
79
+ for (idx = 0; idx < arr.length; idx++) {
80
+ name = arr[idx];
81
+ if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
82
+ toVal(out, name, idx + 1 < arr.length || val, opts);
83
+ }
84
+ }
85
+ }
86
+ if (defaults) {
87
+ for (k in opts.default) {
88
+ if (out[k] === void 0) {
89
+ out[k] = opts.default[k];
90
+ }
91
+ }
92
+ }
93
+ if (alibi) {
94
+ for (k in out) {
95
+ arr = opts.alias[k] || [];
96
+ while (arr.length > 0) {
97
+ out[arr.shift()] = out[k];
98
+ }
99
+ }
100
+ }
101
+ return out;
102
+ }
103
+ var removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
104
+ var findAllBrackets = (v) => {
105
+ const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
106
+ const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
107
+ const res = [];
108
+ const parse = (match) => {
109
+ let variadic = false;
110
+ let value = match[1];
111
+ if (value.startsWith("...")) {
112
+ value = value.slice(3);
113
+ variadic = true;
114
+ }
115
+ return {
116
+ required: match[0].startsWith("<"),
117
+ value,
118
+ variadic
119
+ };
120
+ };
121
+ let angledMatch;
122
+ while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
123
+ res.push(parse(angledMatch));
124
+ }
125
+ let squareMatch;
126
+ while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
127
+ res.push(parse(squareMatch));
128
+ }
129
+ return res;
130
+ };
131
+ var getMriOptions = (options) => {
132
+ const result = { alias: {}, boolean: [] };
133
+ for (const [index, option] of options.entries()) {
134
+ if (option.names.length > 1) {
135
+ result.alias[option.names[0]] = option.names.slice(1);
136
+ }
137
+ if (option.isBoolean) {
138
+ if (option.negated) {
139
+ const hasStringTypeOption = options.some((o, i) => {
140
+ return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
141
+ });
142
+ if (!hasStringTypeOption) {
143
+ result.boolean.push(option.names[0]);
144
+ }
145
+ } else {
146
+ result.boolean.push(option.names[0]);
147
+ }
148
+ }
149
+ }
150
+ return result;
151
+ };
152
+ var findLongest = (arr) => {
153
+ return arr.sort((a, b) => {
154
+ return a.length > b.length ? -1 : 1;
155
+ })[0];
156
+ };
157
+ var padRight = (str, length) => {
158
+ return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
159
+ };
160
+ var camelcase = (input) => {
161
+ return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
162
+ return p1 + p2.toUpperCase();
163
+ });
164
+ };
165
+ var setDotProp = (obj, keys, val) => {
166
+ let i = 0;
167
+ let length = keys.length;
168
+ let t = obj;
169
+ let x;
170
+ for (; i < length; ++i) {
171
+ x = t[keys[i]];
172
+ t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
173
+ }
174
+ };
175
+ var setByType = (obj, transforms) => {
176
+ for (const key of Object.keys(transforms)) {
177
+ const transform = transforms[key];
178
+ if (transform.shouldTransform) {
179
+ obj[key] = Array.prototype.concat.call([], obj[key]);
180
+ if (typeof transform.transformFunction === "function") {
181
+ obj[key] = obj[key].map(transform.transformFunction);
182
+ }
183
+ }
184
+ }
185
+ };
186
+ var getFileName = (input) => {
187
+ const m = /([^\\\/]+)$/.exec(input);
188
+ return m ? m[1] : "";
189
+ };
190
+ var camelcaseOptionName = (name) => {
191
+ return name.split(".").map((v, i) => {
192
+ return i === 0 ? camelcase(v) : v;
193
+ }).join(".");
194
+ };
195
+ var CACError = class extends Error {
196
+ constructor(message) {
197
+ super(message);
198
+ this.name = this.constructor.name;
199
+ if (typeof Error.captureStackTrace === "function") {
200
+ Error.captureStackTrace(this, this.constructor);
201
+ } else {
202
+ this.stack = new Error(message).stack;
203
+ }
204
+ }
205
+ };
206
+ var Option = class {
207
+ constructor(rawName, description, config) {
208
+ this.rawName = rawName;
209
+ this.description = description;
210
+ this.config = Object.assign({}, config);
211
+ rawName = rawName.replace(/\.\*/g, "");
212
+ this.negated = false;
213
+ this.names = removeBrackets(rawName).split(",").map((v) => {
214
+ let name = v.trim().replace(/^-{1,2}/, "");
215
+ if (name.startsWith("no-")) {
216
+ this.negated = true;
217
+ name = name.replace(/^no-/, "");
218
+ }
219
+ return camelcaseOptionName(name);
220
+ }).sort((a, b) => a.length > b.length ? 1 : -1);
221
+ this.name = this.names[this.names.length - 1];
222
+ if (this.negated && this.config.default == null) {
223
+ this.config.default = true;
224
+ }
225
+ if (rawName.includes("<")) {
226
+ this.required = true;
227
+ } else if (rawName.includes("[")) {
228
+ this.required = false;
229
+ } else {
230
+ this.isBoolean = true;
231
+ }
232
+ }
233
+ };
234
+ var processArgs = process.argv;
235
+ var platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
236
+ var Command = class {
237
+ constructor(rawName, description, config = {}, cli2) {
238
+ this.rawName = rawName;
239
+ this.description = description;
240
+ this.config = config;
241
+ this.cli = cli2;
242
+ this.options = [];
243
+ this.aliasNames = [];
244
+ this.name = removeBrackets(rawName);
245
+ this.args = findAllBrackets(rawName);
246
+ this.examples = [];
247
+ }
248
+ usage(text) {
249
+ this.usageText = text;
250
+ return this;
251
+ }
252
+ allowUnknownOptions() {
253
+ this.config.allowUnknownOptions = true;
254
+ return this;
255
+ }
256
+ ignoreOptionDefaultValue() {
257
+ this.config.ignoreOptionDefaultValue = true;
258
+ return this;
259
+ }
260
+ version(version2, customFlags = "-v, --version") {
261
+ this.versionNumber = version2;
262
+ this.option(customFlags, "Display version number");
263
+ return this;
264
+ }
265
+ example(example) {
266
+ this.examples.push(example);
267
+ return this;
268
+ }
269
+ option(rawName, description, config) {
270
+ const option = new Option(rawName, description, config);
271
+ this.options.push(option);
272
+ return this;
273
+ }
274
+ alias(name) {
275
+ this.aliasNames.push(name);
276
+ return this;
277
+ }
278
+ action(callback) {
279
+ this.commandAction = callback;
280
+ return this;
281
+ }
282
+ isMatched(name) {
283
+ return this.name === name || this.aliasNames.includes(name);
284
+ }
285
+ get isDefaultCommand() {
286
+ return this.name === "" || this.aliasNames.includes("!");
287
+ }
288
+ get isGlobalCommand() {
289
+ return this instanceof GlobalCommand;
290
+ }
291
+ hasOption(name) {
292
+ name = name.split(".")[0];
293
+ return this.options.find((option) => {
294
+ return option.names.includes(name);
295
+ });
296
+ }
297
+ outputHelp() {
298
+ const { name, commands } = this.cli;
299
+ const {
300
+ versionNumber,
301
+ options: globalOptions,
302
+ helpCallback
303
+ } = this.cli.globalCommand;
304
+ let sections = [
305
+ {
306
+ body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
307
+ }
308
+ ];
309
+ sections.push({
310
+ title: "Usage",
311
+ body: ` $ ${name} ${this.usageText || this.rawName}`
312
+ });
313
+ const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
314
+ if (showCommands) {
315
+ const longestCommandName = findLongest(commands.map((command) => command.rawName));
316
+ sections.push({
317
+ title: "Commands",
318
+ body: commands.map((command) => {
319
+ return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
320
+ }).join("\n")
321
+ });
322
+ sections.push({
323
+ title: `For more info, run any command with the \`--help\` flag`,
324
+ body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
325
+ });
326
+ }
327
+ let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
328
+ if (!this.isGlobalCommand && !this.isDefaultCommand) {
329
+ options = options.filter((option) => option.name !== "version");
330
+ }
331
+ if (options.length > 0) {
332
+ const longestOptionName = findLongest(options.map((option) => option.rawName));
333
+ sections.push({
334
+ title: "Options",
335
+ body: options.map((option) => {
336
+ return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
337
+ }).join("\n")
338
+ });
339
+ }
340
+ if (this.examples.length > 0) {
341
+ sections.push({
342
+ title: "Examples",
343
+ body: this.examples.map((example) => {
344
+ if (typeof example === "function") {
345
+ return example(name);
346
+ }
347
+ return example;
348
+ }).join("\n")
349
+ });
350
+ }
351
+ if (helpCallback) {
352
+ sections = helpCallback(sections) || sections;
353
+ }
354
+ console.log(sections.map((section) => {
355
+ return section.title ? `${section.title}:
356
+ ${section.body}` : section.body;
357
+ }).join("\n\n"));
358
+ }
359
+ outputVersion() {
360
+ const { name } = this.cli;
361
+ const { versionNumber } = this.cli.globalCommand;
362
+ if (versionNumber) {
363
+ console.log(`${name}/${versionNumber} ${platformInfo}`);
364
+ }
365
+ }
366
+ checkRequiredArgs() {
367
+ const minimalArgsCount = this.args.filter((arg) => arg.required).length;
368
+ if (this.cli.args.length < minimalArgsCount) {
369
+ throw new CACError(`missing required args for command \`${this.rawName}\``);
370
+ }
371
+ }
372
+ checkUnknownOptions() {
373
+ const { options, globalCommand } = this.cli;
374
+ if (!this.config.allowUnknownOptions) {
375
+ for (const name of Object.keys(options)) {
376
+ if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
377
+ throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
378
+ }
379
+ }
380
+ }
381
+ }
382
+ checkOptionValue() {
383
+ const { options: parsedOptions, globalCommand } = this.cli;
384
+ const options = [...globalCommand.options, ...this.options];
385
+ for (const option of options) {
386
+ const value = parsedOptions[option.name.split(".")[0]];
387
+ if (option.required) {
388
+ const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
389
+ if (value === true || value === false && !hasNegated) {
390
+ throw new CACError(`option \`${option.rawName}\` value is missing`);
391
+ }
392
+ }
393
+ }
394
+ }
395
+ };
396
+ var GlobalCommand = class extends Command {
397
+ constructor(cli2) {
398
+ super("@@global@@", "", {}, cli2);
399
+ }
400
+ };
401
+ var __assign = Object.assign;
402
+ var CAC = class extends EventEmitter {
403
+ constructor(name = "") {
404
+ super();
405
+ this.name = name;
406
+ this.commands = [];
407
+ this.rawArgs = [];
408
+ this.args = [];
409
+ this.options = {};
410
+ this.globalCommand = new GlobalCommand(this);
411
+ this.globalCommand.usage("<command> [options]");
412
+ }
413
+ usage(text) {
414
+ this.globalCommand.usage(text);
415
+ return this;
416
+ }
417
+ command(rawName, description, config) {
418
+ const command = new Command(rawName, description || "", config, this);
419
+ command.globalCommand = this.globalCommand;
420
+ this.commands.push(command);
421
+ return command;
422
+ }
423
+ option(rawName, description, config) {
424
+ this.globalCommand.option(rawName, description, config);
425
+ return this;
426
+ }
427
+ help(callback) {
428
+ this.globalCommand.option("-h, --help", "Display this message");
429
+ this.globalCommand.helpCallback = callback;
430
+ this.showHelpOnExit = true;
431
+ return this;
432
+ }
433
+ version(version2, customFlags = "-v, --version") {
434
+ this.globalCommand.version(version2, customFlags);
435
+ this.showVersionOnExit = true;
436
+ return this;
437
+ }
438
+ example(example) {
439
+ this.globalCommand.example(example);
440
+ return this;
441
+ }
442
+ outputHelp() {
443
+ if (this.matchedCommand) {
444
+ this.matchedCommand.outputHelp();
445
+ } else {
446
+ this.globalCommand.outputHelp();
447
+ }
448
+ }
449
+ outputVersion() {
450
+ this.globalCommand.outputVersion();
451
+ }
452
+ setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
453
+ this.args = args;
454
+ this.options = options;
455
+ if (matchedCommand) {
456
+ this.matchedCommand = matchedCommand;
457
+ }
458
+ if (matchedCommandName) {
459
+ this.matchedCommandName = matchedCommandName;
460
+ }
461
+ return this;
462
+ }
463
+ unsetMatchedCommand() {
464
+ this.matchedCommand = void 0;
465
+ this.matchedCommandName = void 0;
466
+ }
467
+ parse(argv = processArgs, {
468
+ run = true
469
+ } = {}) {
470
+ this.rawArgs = argv;
471
+ if (!this.name) {
472
+ this.name = argv[1] ? getFileName(argv[1]) : "cli";
473
+ }
474
+ let shouldParse = true;
475
+ for (const command of this.commands) {
476
+ const parsed = this.mri(argv.slice(2), command);
477
+ const commandName = parsed.args[0];
478
+ if (command.isMatched(commandName)) {
479
+ shouldParse = false;
480
+ const parsedInfo = __assign(__assign({}, parsed), {
481
+ args: parsed.args.slice(1)
482
+ });
483
+ this.setParsedInfo(parsedInfo, command, commandName);
484
+ this.emit(`command:${commandName}`, command);
485
+ }
486
+ }
487
+ if (shouldParse) {
488
+ for (const command of this.commands) {
489
+ if (command.name === "") {
490
+ shouldParse = false;
491
+ const parsed = this.mri(argv.slice(2), command);
492
+ this.setParsedInfo(parsed, command);
493
+ this.emit(`command:!`, command);
494
+ }
495
+ }
496
+ }
497
+ if (shouldParse) {
498
+ const parsed = this.mri(argv.slice(2));
499
+ this.setParsedInfo(parsed);
500
+ }
501
+ if (this.options.help && this.showHelpOnExit) {
502
+ this.outputHelp();
503
+ run = false;
504
+ this.unsetMatchedCommand();
505
+ }
506
+ if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
507
+ this.outputVersion();
508
+ run = false;
509
+ this.unsetMatchedCommand();
510
+ }
511
+ const parsedArgv = { args: this.args, options: this.options };
512
+ if (run) {
513
+ this.runMatchedCommand();
514
+ }
515
+ if (!this.matchedCommand && this.args[0]) {
516
+ this.emit("command:*");
517
+ }
518
+ return parsedArgv;
519
+ }
520
+ mri(argv, command) {
521
+ const cliOptions = [
522
+ ...this.globalCommand.options,
523
+ ...command ? command.options : []
524
+ ];
525
+ const mriOptions = getMriOptions(cliOptions);
526
+ let argsAfterDoubleDashes = [];
527
+ const doubleDashesIndex = argv.indexOf("--");
528
+ if (doubleDashesIndex > -1) {
529
+ argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
530
+ argv = argv.slice(0, doubleDashesIndex);
531
+ }
532
+ let parsed = mri2(argv, mriOptions);
533
+ parsed = Object.keys(parsed).reduce((res, name) => {
534
+ return __assign(__assign({}, res), {
535
+ [camelcaseOptionName(name)]: parsed[name]
536
+ });
537
+ }, { _: [] });
538
+ const args = parsed._;
539
+ const options = {
540
+ "--": argsAfterDoubleDashes
541
+ };
542
+ const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
543
+ let transforms = /* @__PURE__ */ Object.create(null);
544
+ for (const cliOption of cliOptions) {
545
+ if (!ignoreDefault && cliOption.config.default !== void 0) {
546
+ for (const name of cliOption.names) {
547
+ options[name] = cliOption.config.default;
548
+ }
549
+ }
550
+ if (Array.isArray(cliOption.config.type)) {
551
+ if (transforms[cliOption.name] === void 0) {
552
+ transforms[cliOption.name] = /* @__PURE__ */ Object.create(null);
553
+ transforms[cliOption.name]["shouldTransform"] = true;
554
+ transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
555
+ }
556
+ }
557
+ }
558
+ for (const key of Object.keys(parsed)) {
559
+ if (key !== "_") {
560
+ const keys = key.split(".");
561
+ setDotProp(options, keys, parsed[key]);
562
+ setByType(options, transforms);
563
+ }
564
+ }
565
+ return {
566
+ args,
567
+ options
568
+ };
569
+ }
570
+ runMatchedCommand() {
571
+ const { args, options, matchedCommand: command } = this;
572
+ if (!command || !command.commandAction)
573
+ return;
574
+ command.checkUnknownOptions();
575
+ command.checkOptionValue();
576
+ command.checkRequiredArgs();
577
+ const actionArgs = [];
578
+ command.args.forEach((arg, index) => {
579
+ if (arg.variadic) {
580
+ actionArgs.push(args.slice(index));
581
+ } else {
582
+ actionArgs.push(args[index]);
583
+ }
584
+ });
585
+ actionArgs.push(options);
586
+ return command.commandAction.apply(this, actionArgs);
587
+ }
588
+ };
589
+ var cac = (name = "") => new CAC(name);
590
+ var dist_default = cac;
591
+
592
+ // src/cli.ts
593
+ import fs from "fs";
594
+ import path from "path";
595
+
596
+ // package.json
597
+ var version = "0.0.1";
598
+
599
+ // src/cli.ts
600
+ var cli = dist_default("difflens");
601
+ cli.command("init", "Initialize DiffLens configuration").action(() => {
602
+ const configPath = path.resolve(process.cwd(), "difflens.config.ts");
603
+ if (fs.existsSync(configPath)) {
604
+ console.log("Configuration file already exists: difflens.config.ts");
605
+ return;
606
+ }
607
+ const template = `import { DiffLensConfig } from 'difflens';
608
+
609
+ const config: DiffLensConfig = {
610
+ scenarios: [
611
+ {
612
+ label: 'example',
613
+ path: 'https://example.com',
614
+ },
615
+ ],
616
+ outDir: '.difflens',
617
+ };
618
+
619
+ export default config;
620
+ `;
621
+ fs.writeFileSync(configPath, template);
622
+ console.log("Created configuration file: difflens.config.ts");
623
+ });
624
+ cli.command("test", "Run visual regression tests").option("--format <type>", "Output format (default, json, ai)").option("--url <url>", "URL to test (overrides config file)").option("--label <label>", "Label for the test scenario", { default: "check" }).action(async (options) => {
625
+ console.error("Running tests...");
626
+ try {
627
+ let config;
628
+ if (options.url) {
629
+ config = {
630
+ scenarios: [{ label: options.label, path: options.url }],
631
+ outDir: ".difflens",
632
+ format: options.format
633
+ };
634
+ } else {
635
+ config = await loadConfig();
636
+ if (options.format) {
637
+ config.format = options.format;
638
+ }
639
+ }
640
+ const success = await runTests(config);
641
+ if (!success) {
642
+ console.error("Tests failed.");
643
+ process.exit(1);
644
+ }
645
+ } catch (error) {
646
+ console.error("Test run failed:", error);
647
+ process.exit(1);
648
+ }
649
+ });
650
+ cli.command("report", "Generate HTML report").action(() => {
651
+ console.error("Generating report...");
652
+ console.error("Report generation is currently integrated into the test command.");
653
+ });
654
+ cli.help();
655
+ cli.version(version);
656
+ try {
657
+ cli.parse();
658
+ } catch (error) {
659
+ console.error(error);
660
+ process.exit(1);
661
+ }
@@ -0,0 +1,61 @@
1
+ import { Result } from 'axe-core';
2
+
3
+ interface DiffLensConfig {
4
+ baseUrl?: string;
5
+ viewports?: {
6
+ [key: string]: {
7
+ width: number;
8
+ height: number;
9
+ };
10
+ };
11
+ scenarios: Scenario[];
12
+ threshold?: number;
13
+ outDir?: string;
14
+ format?: 'default' | 'json' | 'ai';
15
+ failOnActionError?: boolean;
16
+ failOnNavigationError?: boolean;
17
+ }
18
+ interface Viewport {
19
+ width: number;
20
+ height: number;
21
+ label?: string;
22
+ }
23
+ interface Action {
24
+ type: 'click' | 'type' | 'wait';
25
+ selector?: string;
26
+ value?: string;
27
+ timeout?: number;
28
+ }
29
+ interface Scenario {
30
+ label: string;
31
+ path: string;
32
+ viewports?: Viewport[];
33
+ actions?: Action[];
34
+ maskSelectors?: string[];
35
+ hideSelectors?: string[];
36
+ }
37
+ interface TestResult {
38
+ scenario: string;
39
+ timestamp: string;
40
+ status: 'pass' | 'fail' | 'new';
41
+ diffPixels: number;
42
+ diffPercentage: number;
43
+ screenshotPath: string;
44
+ diffPath?: string;
45
+ baselinePath?: string;
46
+ a11yViolations: Result[];
47
+ dimensionMismatch?: boolean;
48
+ }
49
+ interface ReportData {
50
+ timestamp: string;
51
+ results: TestResult[];
52
+ }
53
+
54
+ declare const DEFAULT_CONFIG: DiffLensConfig;
55
+ declare function loadConfig(configPath?: string): Promise<DiffLensConfig>;
56
+
57
+ declare function runTests(config: DiffLensConfig): Promise<boolean>;
58
+
59
+ declare function formatAiReport(results: TestResult[], outDir: string): string;
60
+
61
+ export { type Action, DEFAULT_CONFIG, type DiffLensConfig, type ReportData, type Scenario, type TestResult, type Viewport, formatAiReport, loadConfig, runTests };