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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 DiffLens Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # DiffLens
2
+
3
+ [![npm version](https://img.shields.io/npm/v/difflens.svg)](https://www.npmjs.com/package/difflens)
4
+ [![CI](https://github.com/hayato06/difflens/actions/workflows/ci.yml/badge.svg)](https://github.com/hayato06/difflens/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Node.js](https://img.shields.io/node/v/difflens.svg)](https://nodejs.org/)
7
+
8
+ **Visual Regression Testing for Everyone + Accessibility as a Service**
9
+
10
+ DiffLens is a lightweight, zero-config visual regression testing and accessibility auditing tool built on top of [Playwright](https://playwright.dev/).
11
+
12
+ ## Features
13
+
14
+ - 📸 **Visual Regression Testing**: Automatically capture screenshots and detect pixel-perfect differences.
15
+ - ♿ **Accessibility Auditing**: Integrated `axe-core` checks to catch a11y violations.
16
+ - ⚙️ **Zero Config**: Works out of the box, or customize with `difflens.config.ts`.
17
+ - 📊 **HTML Reporting**: Generate visual reports to easily inspect diffs.
18
+ - 🤖 **CI Ready**: Proper exit codes for CI/CD integration.
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install -D difflens
24
+ # or
25
+ yarn add -D difflens
26
+ # or
27
+ pnpm add -D difflens
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ### Initialize
33
+
34
+ Generate a configuration file:
35
+
36
+ ```bash
37
+ npx difflens init
38
+ ```
39
+
40
+ ### Run Tests
41
+
42
+ Execute visual regression tests and accessibility audits:
43
+
44
+ ```bash
45
+ npx difflens test
46
+ ```
47
+
48
+ - **First Run**: Captures screenshots and saves them as **Baseline** (`.difflens/baseline`).
49
+ - **Subsequent Runs**: Captures new screenshots (`.difflens/current`) and compares them with the baseline.
50
+ - **Diffs**: If differences are detected, diff images are saved to `.difflens/diff` and the test fails.
51
+
52
+ ### View Report
53
+
54
+ After running tests, open the generated HTML report:
55
+
56
+ ```bash
57
+ open .difflens/index.html
58
+ ```
59
+
60
+ ## Configuration
61
+
62
+ Create `difflens.config.ts` in your project root:
63
+
64
+ ```typescript
65
+ import { DiffLensConfig } from 'difflens';
66
+
67
+ const config: DiffLensConfig = {
68
+ // Base URL for all scenarios (optional)
69
+ baseUrl: 'https://example.com',
70
+
71
+ // Output directory for artifacts (default: .difflens)
72
+ outDir: '.difflens',
73
+
74
+ // Image comparison threshold (0 to 1, default: 0.1)
75
+ threshold: 0.1,
76
+
77
+ // Fail test if an action fails (default: false)
78
+ failOnActionError: false,
79
+
80
+ // Test scenarios
81
+ scenarios: [
82
+ {
83
+ label: 'homepage',
84
+ path: '/',
85
+ // Optional: Define multiple viewports
86
+ viewports: [
87
+ { width: 1280, height: 720, label: 'desktop' },
88
+ { width: 375, height: 667, label: 'mobile' },
89
+ ],
90
+ // Optional: Perform actions before screenshot
91
+ actions: [
92
+ { type: 'wait', timeout: 1000 },
93
+ { type: 'click', selector: '#login-button' },
94
+ { type: 'type', selector: '#username', value: 'user' },
95
+ ],
96
+ },
97
+ {
98
+ label: 'about',
99
+ path: '/about',
100
+ },
101
+ ],
102
+ };
103
+
104
+ export default config;
105
+ ```
106
+
107
+ ## MCP & API Server
108
+
109
+ DiffLens provides an MCP server and a REST API for integration with AI agents.
110
+
111
+ ### Response Schema
112
+
113
+ Both the MCP tool and the API endpoint return a JSON response with the following structure:
114
+
115
+ ```json
116
+ {
117
+ "success": boolean, // Overall success status
118
+ "results": [
119
+ {
120
+ "scenario": string,
121
+ "status": "pass" | "fail" | "new",
122
+ "diffPixels": number,
123
+ "diffPercentage": number,
124
+ "dimensionMismatch": boolean, // True if dimensions differ
125
+ "a11yViolations": [ ... ] // List of accessibility violations
126
+ }
127
+ ]
128
+ }
129
+ ```
130
+
131
+ ## CLI Options
132
+
133
+ ### `test`
134
+
135
+ - `--url <url>`: Run a quick test against a specific URL (overrides config).
136
+ - `--label <label>`: Label for the ad-hoc test (default: 'check').
137
+ - `--format <type>`: Output format.
138
+ - `default`: Standard output with HTML report generation.
139
+ - `json`: Output pure JSON to stdout (logs redirected to stderr).
140
+ - `ai`: Output AI-friendly text summary to stdout (logs redirected to stderr).
141
+
142
+ ### Exit Codes
143
+
144
+ - `0`: Success (No visual regressions or accessibility violations).
145
+ - `1`: Failure (Visual regression detected, dimension mismatch, or accessibility violations).
146
+
147
+ ## License
148
+
149
+ MIT
@@ -0,0 +1,6 @@
1
+ import {
2
+ formatAiReport
3
+ } from "./chunk-4Q2LAHUO.mjs";
4
+ export {
5
+ formatAiReport
6
+ };
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+
25
+ // src/api-server.ts
26
+ var import_node_server = require("@hono/node-server");
27
+ var import_hono = require("hono");
28
+ var import_child_process = require("child_process");
29
+ var import_util = require("util");
30
+ var import_path = __toESM(require("path"));
31
+ var execFileAsync = (0, import_util.promisify)(import_child_process.execFile);
32
+ var app = new import_hono.Hono();
33
+ app.get("/health", (c) => {
34
+ return c.json({ status: "ok", version: "0.0.1" });
35
+ });
36
+ app.post("/check", async (c) => {
37
+ try {
38
+ const body = await c.req.json();
39
+ const { url, label } = body;
40
+ if (!url) {
41
+ return c.json({ error: "URL is required" }, 400);
42
+ }
43
+ const scenarioLabel = label || "check";
44
+ const cliPath = import_path.default.resolve(__dirname, "cli.js");
45
+ const args = [cliPath, "test", "--url", url, "--label", scenarioLabel, "--format", "json"];
46
+ console.log(`Executing: node ${args.join(" ")}`);
47
+ try {
48
+ const { stdout, stderr } = await execFileAsync(process.execPath, args);
49
+ let results;
50
+ try {
51
+ results = JSON.parse(stdout);
52
+ if (!Array.isArray(results)) {
53
+ results = [results];
54
+ }
55
+ } catch (e) {
56
+ results = [];
57
+ }
58
+ return c.json({
59
+ success: true,
60
+ results
61
+ });
62
+ } catch (error) {
63
+ const stdout = error.stdout;
64
+ let results;
65
+ try {
66
+ results = JSON.parse(stdout);
67
+ if (!Array.isArray(results)) {
68
+ results = [results];
69
+ }
70
+ } catch (e) {
71
+ results = [];
72
+ }
73
+ return c.json({
74
+ success: false,
75
+ // Visual regression found or error
76
+ results,
77
+ error: error.message
78
+ });
79
+ }
80
+ } catch (error) {
81
+ return c.json({ error: error.message }, 500);
82
+ }
83
+ });
84
+ var port = 3e3;
85
+ console.log(`Server is running on port ${port}`);
86
+ (0, import_node_server.serve)({
87
+ fetch: app.fetch,
88
+ port
89
+ });
@@ -0,0 +1,65 @@
1
+ // src/api-server.ts
2
+ import { serve } from "@hono/node-server";
3
+ import { Hono } from "hono";
4
+ import { execFile } from "child_process";
5
+ import { promisify } from "util";
6
+ import path from "path";
7
+ var execFileAsync = promisify(execFile);
8
+ var app = new Hono();
9
+ app.get("/health", (c) => {
10
+ return c.json({ status: "ok", version: "0.0.1" });
11
+ });
12
+ app.post("/check", async (c) => {
13
+ try {
14
+ const body = await c.req.json();
15
+ const { url, label } = body;
16
+ if (!url) {
17
+ return c.json({ error: "URL is required" }, 400);
18
+ }
19
+ const scenarioLabel = label || "check";
20
+ const cliPath = path.resolve(__dirname, "cli.js");
21
+ const args = [cliPath, "test", "--url", url, "--label", scenarioLabel, "--format", "json"];
22
+ console.log(`Executing: node ${args.join(" ")}`);
23
+ try {
24
+ const { stdout, stderr } = await execFileAsync(process.execPath, args);
25
+ let results;
26
+ try {
27
+ results = JSON.parse(stdout);
28
+ if (!Array.isArray(results)) {
29
+ results = [results];
30
+ }
31
+ } catch (e) {
32
+ results = [];
33
+ }
34
+ return c.json({
35
+ success: true,
36
+ results
37
+ });
38
+ } catch (error) {
39
+ const stdout = error.stdout;
40
+ let results;
41
+ try {
42
+ results = JSON.parse(stdout);
43
+ if (!Array.isArray(results)) {
44
+ results = [results];
45
+ }
46
+ } catch (e) {
47
+ results = [];
48
+ }
49
+ return c.json({
50
+ success: false,
51
+ // Visual regression found or error
52
+ results,
53
+ error: error.message
54
+ });
55
+ }
56
+ } catch (error) {
57
+ return c.json({ error: error.message }, 500);
58
+ }
59
+ });
60
+ var port = 3e3;
61
+ console.log(`Server is running on port ${port}`);
62
+ serve({
63
+ fetch: app.fetch,
64
+ port
65
+ });
@@ -0,0 +1,51 @@
1
+ // src/core/reporters/ai-reporter.ts
2
+ import path from "path";
3
+ function formatAiReport(results, outDir) {
4
+ let output = "DiffLens Test Report\n====================\n\n";
5
+ const failures = results.filter((r) => r.status === "fail" || r.a11yViolations.length > 0);
6
+ if (failures.length === 0) {
7
+ return output + "All tests passed. No visual regressions or accessibility violations found.\n";
8
+ }
9
+ output += `Found ${failures.length} issues:
10
+
11
+ `;
12
+ failures.forEach((result, index) => {
13
+ output += `Issue #${index + 1}: ${result.scenario}
14
+ `;
15
+ output += `----------------------------------------
16
+ `;
17
+ if (result.status === "fail") {
18
+ if (result.dimensionMismatch) {
19
+ output += `[Dimension Mismatch]
20
+ `;
21
+ output += ` Baseline and current images have different dimensions.
22
+ `;
23
+ } else if (result.diffPixels > 0) {
24
+ output += `[Visual Regression]
25
+ `;
26
+ output += ` Diff Pixels: ${result.diffPixels} (${result.diffPercentage.toFixed(2)}%)
27
+ `;
28
+ if (result.diffPath) {
29
+ output += ` Diff Image: ${path.relative(process.cwd(), result.diffPath)}
30
+ `;
31
+ }
32
+ }
33
+ }
34
+ if (result.a11yViolations.length > 0) {
35
+ output += `[Accessibility Violations]
36
+ `;
37
+ result.a11yViolations.forEach((v) => {
38
+ output += ` - [${v.impact}] ${v.help} (${v.id})
39
+ `;
40
+ output += ` Target: ${v.nodes.map((n) => n.target.join(", ")).join(" | ")}
41
+ `;
42
+ });
43
+ }
44
+ output += "\n";
45
+ });
46
+ return output;
47
+ }
48
+
49
+ export {
50
+ formatAiReport
51
+ };