webguardx 0.1.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (Unreleased)
4
+
5
+ ### Features
6
+
7
+ - HTTP status check for all configured pages
8
+ - Content visibility verification (body rendered, elements visible)
9
+ - WCAG accessibility audit via axe-core (2.0/2.1 Level A & AA)
10
+ - Lighthouse performance, accessibility, best practices, and SEO audit (opt-in)
11
+ - Broken links detection (crawl page links, check for 4xx/5xx)
12
+ - Console error capture (browser console.error and console.warn)
13
+ - Generic auth system: API login, form login, cookie injection, bearer token
14
+ - Retry logic with configurable attempts and delay
15
+ - Per-page screenshot capture (pass and fail)
16
+ - Reporters: terminal (colored), HTML (self-contained), JSON
17
+ - CLI: `webguard init`, `webguard run`, `webguard report`
18
+ - TypeScript config with `defineConfig()` and full autocomplete
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ritik Pal
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,289 @@
1
+ # webguard
2
+
3
+ Full-page web audit framework built on Playwright. Run HTTP status, accessibility, performance, broken links, and console error checks across your entire UI with a single command.
4
+
5
+ ## Why webguard?
6
+
7
+ Web applications break in ways users notice first — slow loads, missing content, broken links, accessibility barriers, and silent JavaScript errors. Manual QA catches some of these, but not consistently across every page, every deploy.
8
+
9
+ **webguard** automates the entire surface-level health check of your UI:
10
+
11
+ - **Catch UI regressions before users do** — Run after every deploy to verify all pages load correctly, render visible content, and have zero console errors
12
+ - **Shift-left on accessibility** — WCAG 2.0/2.1 audits (axe-core) run on every page automatically, so a11y issues are caught in CI, not by compliance audits months later
13
+ - **One config, full coverage** — Define your pages once and webguard runs 6 different audit types on each, instead of maintaining separate scripts for status checks, a11y, broken links, etc.
14
+ - **Works behind auth walls** — 5 built-in auth strategies (API login, form login, cookies, bearer token, none) so you can audit protected pages without custom auth scripts
15
+ - **Built for CI/CD** — Non-zero exit on failures, JSON output for pipeline integration, HTML reports for human review
16
+ - **No test files to maintain** — Unlike Playwright Test or Cypress, there are no `.spec.ts` files. Your config defines pages and webguard handles the rest
17
+ - **Real browser, real results** — Powered by Playwright's Chromium, not synthetic HTTP calls. Every audit sees exactly what your users see
18
+ - **Detailed evidence** — Full-page screenshots, axe violation JSON, Lighthouse reports, and broken link lists — all timestamped per run
19
+
20
+ ### Who is this for?
21
+
22
+ | Team | Use Case |
23
+ |------|----------|
24
+ | **Frontend / UI teams** | Verify every page renders correctly after deploys |
25
+ | **QA engineers** | Automated smoke tests across the entire app surface |
26
+ | **Accessibility teams** | Continuous WCAG compliance monitoring |
27
+ | **DevOps / SRE** | Post-deploy health checks in CI pipelines |
28
+ | **Open source maintainers** | Ensure docs/marketing sites stay healthy |
29
+
30
+ ## Features
31
+
32
+ - **HTTP Status** — Verify every page returns the expected status code
33
+ - **Content Visibility** — Ensure pages render visible, meaningful content
34
+ - **Accessibility** — WCAG 2.0/2.1 audit via axe-core
35
+ - **Lighthouse** — Performance, SEO, best practices scores (optional)
36
+ - **Broken Links** — Crawl `<a>` hrefs and detect 404s
37
+ - **Console Errors** — Capture `console.error` and `console.warn`
38
+ - **Screenshots** — Full-page screenshots per page (pass/fail)
39
+ - **Multiple Auth Strategies** — API login, form login, cookie injection, bearer token
40
+ - **Reports** — Terminal, HTML, and JSON output
41
+
42
+ ## Quick Start
43
+
44
+ ```bash
45
+ # Install
46
+ npm install webguardx
47
+
48
+ # Scaffold a config
49
+ npx webguardx init
50
+
51
+ # Edit webguard.config.ts with your pages
52
+
53
+ # Run audits
54
+ npx webguardx run
55
+ ```
56
+
57
+ ## Configuration
58
+
59
+ Create `webguard.config.ts` in your project root:
60
+
61
+ ```ts
62
+ import { defineConfig } from "webguardx";
63
+
64
+ export default defineConfig({
65
+ baseURL: "https://myapp.com",
66
+
67
+ pages: [
68
+ { name: "Dashboard", path: "/dashboard" },
69
+ { name: "Settings", path: "/settings" },
70
+ { name: "Profile", path: "/profile" },
71
+ ],
72
+
73
+ auth: {
74
+ method: "api-login",
75
+ loginUrl: "https://auth.myapp.com/api/login",
76
+ payload: {
77
+ email: process.env.EMAIL!,
78
+ password: process.env.PASSWORD!,
79
+ },
80
+ },
81
+
82
+ audits: {
83
+ httpStatus: true,
84
+ contentVisibility: true,
85
+ accessibility: true,
86
+ lighthouse: false,
87
+ brokenLinks: false,
88
+ consoleErrors: true,
89
+ },
90
+
91
+ retry: { maxRetries: 3, delayMs: 5000 },
92
+
93
+ output: {
94
+ dir: "./webguard-results",
95
+ formats: ["terminal", "html", "json"],
96
+ screenshots: true,
97
+ },
98
+ });
99
+ ```
100
+
101
+ ## CLI
102
+
103
+ | Command | Description |
104
+ |---------|-------------|
105
+ | `webguard init` | Scaffold config file, `.env.example`, update `.gitignore` |
106
+ | `webguard run` | Run all audits |
107
+ | `webguard run --headed` | Run with visible browser |
108
+ | `webguard run --pages "Home,Settings"` | Run specific pages only |
109
+ | `webguard run --audits "httpStatus,accessibility"` | Run specific audits only |
110
+ | `webguard run --config ./custom.config.ts` | Use custom config path |
111
+ | `webguard report` | Show path to latest HTML report |
112
+ | `webguard report --open` | Open HTML report in browser |
113
+
114
+ ## Auth Strategies
115
+
116
+ ### API Login (POST)
117
+
118
+ ```ts
119
+ auth: {
120
+ method: "api-login",
121
+ loginUrl: "https://auth.example.com/api/login",
122
+ payload: { email: "user@example.com", password: "secret" },
123
+ headers: { "Content-Type": "application/json" }, // optional
124
+ }
125
+ ```
126
+
127
+ ### Form Login
128
+
129
+ ```ts
130
+ auth: {
131
+ method: "form-login",
132
+ loginUrl: "https://example.com/login",
133
+ fields: [
134
+ { selector: "#email", value: "user@example.com" },
135
+ { selector: "#password", value: "secret" },
136
+ ],
137
+ submitSelector: "button[type=submit]",
138
+ waitAfterLogin: "https://example.com/dashboard", // optional URL to wait for
139
+ }
140
+ ```
141
+
142
+ ### Cookie Injection
143
+
144
+ ```ts
145
+ auth: {
146
+ method: "cookie",
147
+ cookies: [
148
+ { name: "session", value: "abc123", domain: "example.com", path: "/" },
149
+ ],
150
+ }
151
+ ```
152
+
153
+ ### Bearer Token
154
+
155
+ ```ts
156
+ auth: {
157
+ method: "bearer-token",
158
+ token: process.env.AUTH_TOKEN!,
159
+ }
160
+ ```
161
+
162
+ ### No Auth
163
+
164
+ ```ts
165
+ auth: {
166
+ method: "none",
167
+ }
168
+ ```
169
+
170
+ ## Audits
171
+
172
+ ### Built-in Audits
173
+
174
+ | Audit | Key | Default | Description |
175
+ |-------|-----|---------|-------------|
176
+ | HTTP Status | `httpStatus` | `true` | Checks response status matches `expectedStatus` (default 200) |
177
+ | Content Visibility | `contentVisibility` | `true` | Verifies body is visible with meaningful content |
178
+ | Accessibility | `accessibility` | `true` | Runs axe-core WCAG audit |
179
+ | Lighthouse | `lighthouse` | `false` | Performance, a11y, best practices, SEO scores |
180
+ | Broken Links | `brokenLinks` | `false` | HEAD requests all `<a>` hrefs for 404s |
181
+ | Console Errors | `consoleErrors` | `true` | Captures `console.error` and `console.warn` |
182
+
183
+ ### Per-Page Configuration
184
+
185
+ Skip specific audits on individual pages:
186
+
187
+ ```ts
188
+ pages: [
189
+ { name: "Home", path: "/" },
190
+ { name: "Login", path: "/login", skipAudits: ["accessibility"] },
191
+ { name: "API Docs", path: "/docs", expectedStatus: 301 },
192
+ ]
193
+ ```
194
+
195
+ ### Accessibility Options
196
+
197
+ ```ts
198
+ // WCAG tags to check (default: all Level A and AA)
199
+ wcagTags: ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"],
200
+ ```
201
+
202
+ ### Lighthouse Thresholds
203
+
204
+ ```ts
205
+ // Install optional deps: npm install lighthouse chrome-launcher
206
+ lighthouseThresholds: {
207
+ performance: 50,
208
+ accessibility: 90,
209
+ bestPractices: 80,
210
+ seo: 80,
211
+ },
212
+ ```
213
+
214
+ ## Output
215
+
216
+ Each run creates a timestamped directory:
217
+
218
+ ```
219
+ webguard-results/
220
+ run-2026-01-30T10-30-00/
221
+ results.json # Machine-readable results
222
+ report.html # Self-contained HTML report
223
+ screenshots/
224
+ Dashboard/
225
+ page-pass.png
226
+ Settings/
227
+ page-fail.png
228
+ ```
229
+
230
+ ## Programmatic API
231
+
232
+ ```ts
233
+ import { defineConfig, run, loadConfig } from "webguardx";
234
+
235
+ // Option 1: Define config inline
236
+ const config = defineConfig({
237
+ baseURL: "https://example.com",
238
+ pages: [{ name: "Home", path: "/" }],
239
+ });
240
+
241
+ const result = await run(config);
242
+ console.log(result.summary);
243
+
244
+ // Option 2: Load from file
245
+ const fileConfig = await loadConfig("./webguard.config.ts");
246
+ const result2 = await run(fileConfig);
247
+ ```
248
+
249
+ ## Terminal Output
250
+
251
+ ```
252
+ webguard v0.1.0
253
+
254
+ i Base URL: https://myapp.com
255
+ i Pages: 3
256
+ i Audits: httpStatus, contentVisibility, accessibility, consoleErrors
257
+
258
+ [1/3] Dashboard (/dashboard)
259
+ ✓ httpStatus 200 OK 12ms
260
+ ✓ contentVisibility 47 elements 8ms
261
+ ✓ accessibility 0 violations 892ms
262
+ ✓ consoleErrors 0 errors 2ms
263
+
264
+ [2/3] Settings (/settings)
265
+ ✓ httpStatus 200 OK 15ms
266
+ ✓ contentVisibility 23 elements 6ms
267
+ ✗ accessibility 3 violations 743ms
268
+ ✓ consoleErrors 0 errors 1ms
269
+
270
+ ────────────────────────────────────────────────────────────
271
+ Summary
272
+ ────────────────────────────────────────────────────────────
273
+
274
+ Total audits: 8
275
+ ✓ Passed: 7
276
+ ✗ Failed: 1
277
+ Duration: 3.2s
278
+
279
+ Result: FAIL (1 failure(s))
280
+ ```
281
+
282
+ ## Requirements
283
+
284
+ - Node.js >= 18
285
+ - Playwright browsers: `npx playwright install chromium`
286
+
287
+ ## License
288
+
289
+ MIT