@rankcli/agent-runtime 0.0.15 → 0.0.16

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 (202) hide show
  1. package/dist/index.d.mts +43 -393
  2. package/dist/index.d.ts +43 -393
  3. package/dist/index.js +306 -6526
  4. package/dist/index.mjs +202 -6412
  5. package/package.json +6 -1
  6. package/scripts/build-deno.ts +0 -134
  7. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  8. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  9. package/src/analyzers/geo-analyzer.test.ts +0 -310
  10. package/src/analyzers/geo-analyzer.ts +0 -814
  11. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  12. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  13. package/src/analyzers/index.ts +0 -233
  14. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  15. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  16. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  17. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  18. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  19. package/src/analyzers/security-headers-analyzer.ts +0 -318
  20. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  21. package/src/analyzers/structured-data-analyzer.ts +0 -590
  22. package/src/audit/ai/analyzer.ts +0 -347
  23. package/src/audit/ai/index.ts +0 -29
  24. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  25. package/src/audit/ai/types.ts +0 -179
  26. package/src/audit/checks/additional-checks.ts +0 -439
  27. package/src/audit/checks/agent-experience.ts +0 -108
  28. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  29. package/src/audit/checks/ai-content-structure.ts +0 -325
  30. package/src/audit/checks/ai-readiness.ts +0 -406
  31. package/src/audit/checks/anchor-text.ts +0 -179
  32. package/src/audit/checks/answer-conciseness.ts +0 -322
  33. package/src/audit/checks/asset-minification.ts +0 -270
  34. package/src/audit/checks/bing-optimization.ts +0 -206
  35. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  36. package/src/audit/checks/caching-headers.ts +0 -305
  37. package/src/audit/checks/canonical-advanced.ts +0 -150
  38. package/src/audit/checks/canonical-domain.ts +0 -196
  39. package/src/audit/checks/citation-quality.ts +0 -358
  40. package/src/audit/checks/client-rendering.ts +0 -542
  41. package/src/audit/checks/color-contrast.ts +0 -342
  42. package/src/audit/checks/content-freshness.ts +0 -170
  43. package/src/audit/checks/content-science.ts +0 -589
  44. package/src/audit/checks/conversion-elements.ts +0 -526
  45. package/src/audit/checks/crawlability.ts +0 -220
  46. package/src/audit/checks/directory-listing.ts +0 -172
  47. package/src/audit/checks/dom-analysis.ts +0 -191
  48. package/src/audit/checks/dom-size.ts +0 -246
  49. package/src/audit/checks/duplicate-content.ts +0 -194
  50. package/src/audit/checks/eeat-signals.ts +0 -990
  51. package/src/audit/checks/entity-seo.ts +0 -396
  52. package/src/audit/checks/featured-snippet.ts +0 -473
  53. package/src/audit/checks/freshness-signals.ts +0 -443
  54. package/src/audit/checks/funnel-intent.ts +0 -463
  55. package/src/audit/checks/hreflang.ts +0 -174
  56. package/src/audit/checks/html-compliance.ts +0 -302
  57. package/src/audit/checks/image-dimensions.ts +0 -167
  58. package/src/audit/checks/images.ts +0 -160
  59. package/src/audit/checks/indexnow.ts +0 -275
  60. package/src/audit/checks/interactive-tools.ts +0 -475
  61. package/src/audit/checks/internal-link-graph.ts +0 -436
  62. package/src/audit/checks/keyword-analysis.ts +0 -239
  63. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  64. package/src/audit/checks/keyword-placement.ts +0 -471
  65. package/src/audit/checks/links.ts +0 -273
  66. package/src/audit/checks/llms-txt.ts +0 -224
  67. package/src/audit/checks/local-seo.ts +0 -296
  68. package/src/audit/checks/mobile.ts +0 -167
  69. package/src/audit/checks/modern-images.ts +0 -226
  70. package/src/audit/checks/navboost-signals.ts +0 -395
  71. package/src/audit/checks/on-page.ts +0 -209
  72. package/src/audit/checks/page-resources.ts +0 -285
  73. package/src/audit/checks/pagination.ts +0 -180
  74. package/src/audit/checks/performance.ts +0 -153
  75. package/src/audit/checks/platform-presence.ts +0 -580
  76. package/src/audit/checks/rag-chunk-readiness.test.ts +0 -159
  77. package/src/audit/checks/rag-chunk-readiness.ts +0 -163
  78. package/src/audit/checks/redirect-analysis.ts +0 -153
  79. package/src/audit/checks/redirect-chain.ts +0 -389
  80. package/src/audit/checks/resource-hints.ts +0 -420
  81. package/src/audit/checks/responsive-css.ts +0 -247
  82. package/src/audit/checks/responsive-images.ts +0 -396
  83. package/src/audit/checks/review-ecosystem.ts +0 -415
  84. package/src/audit/checks/robots-validation.ts +0 -373
  85. package/src/audit/checks/security-headers.ts +0 -188
  86. package/src/audit/checks/security.ts +0 -144
  87. package/src/audit/checks/serp-preview.ts +0 -251
  88. package/src/audit/checks/site-maturity.ts +0 -453
  89. package/src/audit/checks/social-meta.test.ts +0 -275
  90. package/src/audit/checks/social-meta.ts +0 -134
  91. package/src/audit/checks/soft-404.ts +0 -151
  92. package/src/audit/checks/structured-data.ts +0 -238
  93. package/src/audit/checks/tech-detection.ts +0 -496
  94. package/src/audit/checks/topical-clusters.ts +0 -435
  95. package/src/audit/checks/tracker-bloat.ts +0 -462
  96. package/src/audit/checks/tracking-verification.test.ts +0 -371
  97. package/src/audit/checks/tracking-verification.ts +0 -636
  98. package/src/audit/checks/url-safety.ts +0 -682
  99. package/src/audit/deno-entry.ts +0 -66
  100. package/src/audit/discovery/index.ts +0 -15
  101. package/src/audit/discovery/link-crawler.ts +0 -233
  102. package/src/audit/discovery/repo-routes.ts +0 -347
  103. package/src/audit/engine.ts +0 -633
  104. package/src/audit/fixes/index.ts +0 -209
  105. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  106. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  107. package/src/audit/index.ts +0 -74
  108. package/src/audit/runner.test.ts +0 -299
  109. package/src/audit/runner.ts +0 -130
  110. package/src/audit/types.ts +0 -1987
  111. package/src/content/featured-snippet.ts +0 -367
  112. package/src/content/generator.test.ts +0 -534
  113. package/src/content/generator.ts +0 -501
  114. package/src/content/headline.ts +0 -317
  115. package/src/content/index.ts +0 -62
  116. package/src/content/intent.ts +0 -258
  117. package/src/content/keyword-density.ts +0 -349
  118. package/src/content/readability.ts +0 -262
  119. package/src/executor.ts +0 -336
  120. package/src/fixer/framework-fixes.test.ts +0 -489
  121. package/src/fixer/framework-fixes.ts +0 -5287
  122. package/src/fixer/index.ts +0 -6
  123. package/src/fixer/schemas.ts +0 -971
  124. package/src/fixer.ts +0 -642
  125. package/src/frameworks/detector.test.ts +0 -248
  126. package/src/frameworks/detector.ts +0 -899
  127. package/src/frameworks/index.ts +0 -68
  128. package/src/frameworks/recipes/angular.yaml +0 -171
  129. package/src/frameworks/recipes/astro.yaml +0 -206
  130. package/src/frameworks/recipes/django.yaml +0 -180
  131. package/src/frameworks/recipes/laravel.yaml +0 -137
  132. package/src/frameworks/recipes/nextjs.yaml +0 -268
  133. package/src/frameworks/recipes/nuxt.yaml +0 -175
  134. package/src/frameworks/recipes/rails.yaml +0 -188
  135. package/src/frameworks/recipes/react.yaml +0 -202
  136. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  137. package/src/frameworks/recipes/vue.yaml +0 -137
  138. package/src/frameworks/recipes/wordpress.yaml +0 -209
  139. package/src/frameworks/suggestion-engine.ts +0 -357
  140. package/src/geo/geo-content.test.ts +0 -305
  141. package/src/geo/geo-content.ts +0 -266
  142. package/src/geo/geo-history.test.ts +0 -473
  143. package/src/geo/geo-history.ts +0 -433
  144. package/src/geo/geo-tracker.test.ts +0 -359
  145. package/src/geo/geo-tracker.ts +0 -411
  146. package/src/geo/index.ts +0 -11
  147. package/src/geo/llm-citation-checker.ts +0 -188
  148. package/src/git/commit-helper.test.ts +0 -261
  149. package/src/git/commit-helper.ts +0 -329
  150. package/src/git/index.ts +0 -12
  151. package/src/git/pr-helper.test.ts +0 -284
  152. package/src/git/pr-helper.ts +0 -307
  153. package/src/index.ts +0 -76
  154. package/src/keywords/ai-keyword-engine.ts +0 -1062
  155. package/src/keywords/ai-summarizer.ts +0 -387
  156. package/src/keywords/ci-mode.ts +0 -555
  157. package/src/keywords/engine.ts +0 -359
  158. package/src/keywords/index.ts +0 -151
  159. package/src/keywords/llm-judge.ts +0 -357
  160. package/src/keywords/nlp-analysis.ts +0 -706
  161. package/src/keywords/prioritizer.ts +0 -295
  162. package/src/keywords/site-crawler.ts +0 -342
  163. package/src/keywords/sources/autocomplete.ts +0 -139
  164. package/src/keywords/sources/competitive-search.ts +0 -450
  165. package/src/keywords/sources/competitor-analysis.ts +0 -374
  166. package/src/keywords/sources/dataforseo.ts +0 -206
  167. package/src/keywords/sources/free-sources.ts +0 -294
  168. package/src/keywords/sources/gsc.ts +0 -123
  169. package/src/keywords/topic-grouping.ts +0 -327
  170. package/src/keywords/types.ts +0 -144
  171. package/src/keywords/wizard.ts +0 -457
  172. package/src/loader.ts +0 -40
  173. package/src/ranking/index.ts +0 -5
  174. package/src/ranking/serp-client.ts +0 -348
  175. package/src/ranking/tracker.ts +0 -380
  176. package/src/ranking/types.ts +0 -123
  177. package/src/reports/index.ts +0 -7
  178. package/src/reports/report-generator.test.ts +0 -293
  179. package/src/reports/report-generator.ts +0 -713
  180. package/src/scheduler/alerts.test.ts +0 -458
  181. package/src/scheduler/alerts.ts +0 -328
  182. package/src/scheduler/index.ts +0 -8
  183. package/src/scheduler/scheduled-audit.test.ts +0 -377
  184. package/src/scheduler/scheduled-audit.ts +0 -149
  185. package/src/test/integration-test.ts +0 -325
  186. package/src/tools/analyzer.ts +0 -373
  187. package/src/tools/crawl.ts +0 -293
  188. package/src/tools/files.ts +0 -301
  189. package/src/tools/h1-fixer.ts +0 -249
  190. package/src/tools/index.ts +0 -67
  191. package/src/tracking/github-action.ts +0 -326
  192. package/src/tracking/google-analytics.ts +0 -265
  193. package/src/tracking/index.ts +0 -45
  194. package/src/tracking/report-generator.ts +0 -386
  195. package/src/tracking/search-console.ts +0 -335
  196. package/src/types.ts +0 -148
  197. package/src/utils/http.ts +0 -302
  198. package/src/wasm-adapter.ts +0 -297
  199. package/src/wasm-entry.ts +0 -14
  200. package/tsconfig.json +0 -17
  201. package/tsup.wasm.config.ts +0 -26
  202. package/vitest.config.ts +0 -15
@@ -1,318 +0,0 @@
1
- /**
2
- * Security Headers Analyzer
3
- *
4
- * Analyzes HTTP security headers that impact SEO and trust signals.
5
- * Many security headers are now considered ranking factors.
6
- */
7
-
8
- import type { AuditIssue } from '../audit/types.js';
9
-
10
- export interface SecurityHeadersResult {
11
- score: number;
12
- https: {
13
- enabled: boolean;
14
- hasHSTS: boolean;
15
- hstsMaxAge?: number;
16
- includesSubdomains: boolean;
17
- preload: boolean;
18
- };
19
- contentSecurity: {
20
- hasCSP: boolean;
21
- policy?: string;
22
- issues: string[];
23
- };
24
- frameOptions: {
25
- hasXFrameOptions: boolean;
26
- value?: string;
27
- };
28
- contentTypeOptions: {
29
- hasXContentTypeOptions: boolean;
30
- };
31
- xssProtection: {
32
- hasXXSSProtection: boolean;
33
- value?: string;
34
- };
35
- referrerPolicy: {
36
- hasReferrerPolicy: boolean;
37
- value?: string;
38
- };
39
- permissionsPolicy: {
40
- hasPermissionsPolicy: boolean;
41
- policy?: string;
42
- };
43
- issues: AuditIssue[];
44
- grade: 'A+' | 'A' | 'B' | 'C' | 'D' | 'F';
45
- }
46
-
47
- const SECURITY_HEADERS = {
48
- 'strict-transport-security': {
49
- name: 'HSTS',
50
- importance: 'critical',
51
- description: 'Enforces HTTPS connections',
52
- },
53
- 'content-security-policy': {
54
- name: 'CSP',
55
- importance: 'high',
56
- description: 'Prevents XSS and injection attacks',
57
- },
58
- 'x-frame-options': {
59
- name: 'X-Frame-Options',
60
- importance: 'medium',
61
- description: 'Prevents clickjacking',
62
- },
63
- 'x-content-type-options': {
64
- name: 'X-Content-Type-Options',
65
- importance: 'medium',
66
- description: 'Prevents MIME sniffing',
67
- },
68
- 'x-xss-protection': {
69
- name: 'X-XSS-Protection',
70
- importance: 'low',
71
- description: 'Legacy XSS filter (deprecated but still useful)',
72
- },
73
- 'referrer-policy': {
74
- name: 'Referrer-Policy',
75
- importance: 'medium',
76
- description: 'Controls referrer information',
77
- },
78
- 'permissions-policy': {
79
- name: 'Permissions-Policy',
80
- importance: 'medium',
81
- description: 'Controls browser features',
82
- },
83
- };
84
-
85
- /**
86
- * Analyze security headers
87
- */
88
- export function analyzeSecurityHeaders(
89
- headers: Record<string, string>,
90
- url: string
91
- ): SecurityHeadersResult {
92
- const issues: AuditIssue[] = [];
93
- let score = 100;
94
-
95
- // Normalize headers to lowercase
96
- const normalizedHeaders: Record<string, string> = {};
97
- for (const [key, value] of Object.entries(headers)) {
98
- normalizedHeaders[key.toLowerCase()] = value;
99
- }
100
-
101
- // Check HTTPS
102
- const isHTTPS = url.startsWith('https://');
103
- if (!isHTTPS) {
104
- score -= 30;
105
- issues.push({
106
- code: 'SEC_NO_HTTPS',
107
- severity: 'critical',
108
- category: 'technical',
109
- title: 'Site not using HTTPS',
110
- description: 'HTTPS is required for security and is a confirmed Google ranking factor.',
111
- impact: 'Major negative ranking impact and browser security warnings',
112
- howToFix: 'Install SSL certificate and redirect all HTTP traffic to HTTPS',
113
- affectedUrls: [url],
114
- });
115
- }
116
-
117
- // Check HSTS
118
- const hsts = normalizedHeaders['strict-transport-security'];
119
- let hasHSTS = false;
120
- let hstsMaxAge: number | undefined;
121
- let includesSubdomains = false;
122
- let preload = false;
123
-
124
- if (hsts) {
125
- hasHSTS = true;
126
- const maxAgeMatch = hsts.match(/max-age=(\d+)/);
127
- if (maxAgeMatch) {
128
- hstsMaxAge = parseInt(maxAgeMatch[1]);
129
- if (hstsMaxAge < 31536000) { // Less than 1 year
130
- score -= 5;
131
- issues.push({
132
- code: 'SEC_HSTS_SHORT',
133
- severity: 'info',
134
- category: 'technical',
135
- title: 'HSTS max-age is less than 1 year',
136
- description: `Current max-age is ${hstsMaxAge} seconds. Recommended: 31536000 (1 year) or more.`,
137
- impact: 'Reduced protection window',
138
- howToFix: 'Set Strict-Transport-Security: max-age=31536000; includeSubDomains; preload',
139
- affectedUrls: [url],
140
- });
141
- }
142
- }
143
- includesSubdomains = hsts.toLowerCase().includes('includesubdomains');
144
- preload = hsts.toLowerCase().includes('preload');
145
- } else if (isHTTPS) {
146
- score -= 15;
147
- issues.push({
148
- code: 'SEC_NO_HSTS',
149
- severity: 'warning',
150
- category: 'technical',
151
- title: 'Missing HSTS header',
152
- description: 'HTTP Strict Transport Security (HSTS) header is not set.',
153
- impact: 'Users may access site over insecure HTTP',
154
- howToFix: 'Add header: Strict-Transport-Security: max-age=31536000; includeSubDomains; preload',
155
- affectedUrls: [url],
156
- });
157
- }
158
-
159
- // Check CSP
160
- const csp = normalizedHeaders['content-security-policy'];
161
- const cspIssues: string[] = [];
162
-
163
- if (csp) {
164
- // Check for unsafe directives
165
- if (csp.includes("'unsafe-inline'")) {
166
- cspIssues.push("Contains 'unsafe-inline' - reduces XSS protection");
167
- score -= 5;
168
- }
169
- if (csp.includes("'unsafe-eval'")) {
170
- cspIssues.push("Contains 'unsafe-eval' - allows eval()");
171
- score -= 5;
172
- }
173
- if (csp.includes('*') && !csp.includes('*.')) {
174
- cspIssues.push("Contains wildcard (*) - too permissive");
175
- score -= 3;
176
- }
177
- } else {
178
- score -= 10;
179
- issues.push({
180
- code: 'SEC_NO_CSP',
181
- severity: 'warning',
182
- category: 'technical',
183
- title: 'Missing Content-Security-Policy header',
184
- description: 'CSP helps prevent XSS attacks and is a security best practice.',
185
- impact: 'Vulnerable to cross-site scripting attacks',
186
- howToFix: "Add Content-Security-Policy header with appropriate directives. Start with: default-src 'self'",
187
- affectedUrls: [url],
188
- });
189
- }
190
-
191
- // Check X-Frame-Options
192
- const xFrameOptions = normalizedHeaders['x-frame-options'];
193
- if (!xFrameOptions) {
194
- score -= 5;
195
- issues.push({
196
- code: 'SEC_NO_XFRAME',
197
- severity: 'info',
198
- category: 'technical',
199
- title: 'Missing X-Frame-Options header',
200
- description: 'X-Frame-Options prevents clickjacking attacks.',
201
- impact: 'Site can be embedded in malicious iframes',
202
- howToFix: 'Add header: X-Frame-Options: SAMEORIGIN (or DENY)',
203
- affectedUrls: [url],
204
- });
205
- }
206
-
207
- // Check X-Content-Type-Options
208
- const xContentTypeOptions = normalizedHeaders['x-content-type-options'];
209
- if (!xContentTypeOptions) {
210
- score -= 5;
211
- issues.push({
212
- code: 'SEC_NO_XCONTENT_TYPE',
213
- severity: 'info',
214
- category: 'technical',
215
- title: 'Missing X-Content-Type-Options header',
216
- description: 'Prevents browsers from MIME-sniffing responses.',
217
- impact: 'Potential for MIME confusion attacks',
218
- howToFix: 'Add header: X-Content-Type-Options: nosniff',
219
- affectedUrls: [url],
220
- });
221
- }
222
-
223
- // Check Referrer-Policy
224
- const referrerPolicy = normalizedHeaders['referrer-policy'];
225
- if (!referrerPolicy) {
226
- score -= 3;
227
- issues.push({
228
- code: 'SEC_NO_REFERRER_POLICY',
229
- severity: 'info',
230
- category: 'technical',
231
- title: 'Missing Referrer-Policy header',
232
- description: 'Controls how much referrer information is sent with requests.',
233
- impact: 'May leak sensitive URL information',
234
- howToFix: 'Add header: Referrer-Policy: strict-origin-when-cross-origin',
235
- affectedUrls: [url],
236
- });
237
- }
238
-
239
- // Check Permissions-Policy
240
- const permissionsPolicy = normalizedHeaders['permissions-policy'] ||
241
- normalizedHeaders['feature-policy']; // Legacy name
242
- if (!permissionsPolicy) {
243
- score -= 3;
244
- issues.push({
245
- code: 'SEC_NO_PERMISSIONS_POLICY',
246
- severity: 'info',
247
- category: 'technical',
248
- title: 'Missing Permissions-Policy header',
249
- description: 'Controls which browser features can be used.',
250
- impact: 'All browser features enabled by default',
251
- howToFix: 'Add header: Permissions-Policy: geolocation=(), microphone=(), camera=()',
252
- affectedUrls: [url],
253
- });
254
- }
255
-
256
- // Calculate grade
257
- let grade: 'A+' | 'A' | 'B' | 'C' | 'D' | 'F';
258
- if (score >= 95) grade = 'A+';
259
- else if (score >= 85) grade = 'A';
260
- else if (score >= 70) grade = 'B';
261
- else if (score >= 55) grade = 'C';
262
- else if (score >= 40) grade = 'D';
263
- else grade = 'F';
264
-
265
- return {
266
- score: Math.max(0, score),
267
- https: {
268
- enabled: isHTTPS,
269
- hasHSTS,
270
- hstsMaxAge,
271
- includesSubdomains,
272
- preload,
273
- },
274
- contentSecurity: {
275
- hasCSP: !!csp,
276
- policy: csp,
277
- issues: cspIssues,
278
- },
279
- frameOptions: {
280
- hasXFrameOptions: !!xFrameOptions,
281
- value: xFrameOptions,
282
- },
283
- contentTypeOptions: {
284
- hasXContentTypeOptions: !!xContentTypeOptions,
285
- },
286
- xssProtection: {
287
- hasXXSSProtection: !!normalizedHeaders['x-xss-protection'],
288
- value: normalizedHeaders['x-xss-protection'],
289
- },
290
- referrerPolicy: {
291
- hasReferrerPolicy: !!referrerPolicy,
292
- value: referrerPolicy,
293
- },
294
- permissionsPolicy: {
295
- hasPermissionsPolicy: !!permissionsPolicy,
296
- policy: permissionsPolicy,
297
- },
298
- issues,
299
- grade,
300
- };
301
- }
302
-
303
- /**
304
- * Generate recommended security headers
305
- */
306
- export function generateSecurityHeaders(siteUrl: string): Record<string, string> {
307
- const domain = new URL(siteUrl).hostname;
308
-
309
- return {
310
- 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload',
311
- 'Content-Security-Policy': `default-src 'self'; script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https:; connect-src 'self' https://api.${domain}`,
312
- 'X-Frame-Options': 'SAMEORIGIN',
313
- 'X-Content-Type-Options': 'nosniff',
314
- 'Referrer-Policy': 'strict-origin-when-cross-origin',
315
- 'Permissions-Policy': 'geolocation=(), microphone=(), camera=(), payment=()',
316
- 'X-XSS-Protection': '1; mode=block',
317
- };
318
- }
@@ -1,210 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { analyzeStructuredData, generateSchemaTemplate } from './structured-data-analyzer.js';
3
-
4
- describe('Structured Data Analyzer', () => {
5
- describe('analyzeStructuredData', () => {
6
- it('detects valid Article schema', () => {
7
- const html = `
8
- <!DOCTYPE html>
9
- <html>
10
- <head>
11
- <script type="application/ld+json">
12
- {
13
- "@context": "https://schema.org",
14
- "@type": "Article",
15
- "headline": "Test Article",
16
- "author": {"@type": "Person", "name": "John Doe"},
17
- "datePublished": "2024-01-15"
18
- }
19
- </script>
20
- </head>
21
- <body><h1>Test</h1></body>
22
- </html>
23
- `;
24
- const result = analyzeStructuredData(html, 'https://example.com/article');
25
- expect(result.hasArticle).toBe(true);
26
- expect(result.schemas.some(s => s.type === 'Article')).toBe(true);
27
- });
28
-
29
- it('validates required properties', () => {
30
- const html = `
31
- <!DOCTYPE html>
32
- <html>
33
- <head>
34
- <script type="application/ld+json">
35
- {
36
- "@context": "https://schema.org",
37
- "@type": "Article",
38
- "headline": "Test Article"
39
- }
40
- </script>
41
- </head>
42
- <body><h1>Test</h1></body>
43
- </html>
44
- `;
45
- const result = analyzeStructuredData(html, 'https://example.com/article');
46
- const articleSchema = result.schemas.find(s => s.type === 'Article');
47
- expect(articleSchema?.isValid).toBe(false);
48
- expect(articleSchema?.errors.some(e => e.includes('author'))).toBe(true);
49
- });
50
-
51
- it('detects FAQPage schema', () => {
52
- const html = `
53
- <!DOCTYPE html>
54
- <html>
55
- <head>
56
- <script type="application/ld+json">
57
- {
58
- "@context": "https://schema.org",
59
- "@type": "FAQPage",
60
- "mainEntity": [
61
- {
62
- "@type": "Question",
63
- "name": "What is SEO?",
64
- "acceptedAnswer": {
65
- "@type": "Answer",
66
- "text": "SEO stands for Search Engine Optimization."
67
- }
68
- }
69
- ]
70
- }
71
- </script>
72
- </head>
73
- <body><h1>FAQ</h1></body>
74
- </html>
75
- `;
76
- const result = analyzeStructuredData(html, 'https://example.com/faq');
77
- expect(result.hasFAQ).toBe(true);
78
- });
79
-
80
- it('detects Product schema', () => {
81
- const html = `
82
- <!DOCTYPE html>
83
- <html>
84
- <head>
85
- <script type="application/ld+json">
86
- {
87
- "@context": "https://schema.org",
88
- "@type": "Product",
89
- "name": "Test Product",
90
- "offers": {
91
- "@type": "Offer",
92
- "price": "29.99",
93
- "priceCurrency": "USD"
94
- }
95
- }
96
- </script>
97
- </head>
98
- <body><h1>Product</h1></body>
99
- </html>
100
- `;
101
- const result = analyzeStructuredData(html, 'https://example.com/product');
102
- expect(result.hasProduct).toBe(true);
103
- });
104
-
105
- it('detects BreadcrumbList schema', () => {
106
- const html = `
107
- <!DOCTYPE html>
108
- <html>
109
- <head>
110
- <script type="application/ld+json">
111
- {
112
- "@context": "https://schema.org",
113
- "@type": "BreadcrumbList",
114
- "itemListElement": [
115
- {"@type": "ListItem", "position": 1, "name": "Home", "item": "/"},
116
- {"@type": "ListItem", "position": 2, "name": "Products", "item": "/products"}
117
- ]
118
- }
119
- </script>
120
- </head>
121
- <body><h1>Product</h1></body>
122
- </html>
123
- `;
124
- const result = analyzeStructuredData(html, 'https://example.com/product');
125
- expect(result.hasBreadcrumb).toBe(true);
126
- });
127
-
128
- it('handles @graph format', () => {
129
- const html = `
130
- <!DOCTYPE html>
131
- <html>
132
- <head>
133
- <script type="application/ld+json">
134
- {
135
- "@context": "https://schema.org",
136
- "@graph": [
137
- {"@type": "Organization", "name": "Test Org", "url": "https://example.com"},
138
- {"@type": "WebSite", "name": "Test Site", "url": "https://example.com"}
139
- ]
140
- }
141
- </script>
142
- </head>
143
- <body><h1>Home</h1></body>
144
- </html>
145
- `;
146
- const result = analyzeStructuredData(html, 'https://example.com');
147
- expect(result.hasOrganization).toBe(true);
148
- expect(result.hasWebSite).toBe(true);
149
- });
150
-
151
- it('reports invalid JSON', () => {
152
- const html = `
153
- <!DOCTYPE html>
154
- <html>
155
- <head>
156
- <script type="application/ld+json">
157
- {invalid json here}
158
- </script>
159
- </head>
160
- <body><h1>Test</h1></body>
161
- </html>
162
- `;
163
- const result = analyzeStructuredData(html, 'https://example.com');
164
- expect(result.issues.some(i => i.code === 'SCHEMA_INVALID_JSON')).toBe(true);
165
- });
166
-
167
- it('reports when no schema is found', () => {
168
- const html = `
169
- <!DOCTYPE html>
170
- <html>
171
- <head><title>Test</title></head>
172
- <body><h1>No Schema</h1></body>
173
- </html>
174
- `;
175
- const result = analyzeStructuredData(html, 'https://example.com');
176
- expect(result.issues.some(i => i.code === 'SCHEMA_NONE_FOUND')).toBe(true);
177
- });
178
- });
179
-
180
- describe('generateSchemaTemplate', () => {
181
- it('generates article schema template', () => {
182
- const schema = generateSchemaTemplate('article', {
183
- siteName: 'Test Site',
184
- siteUrl: 'https://example.com',
185
- authorName: 'John Doe',
186
- });
187
- expect(schema).toContain('Article');
188
- expect(schema).toContain('John Doe');
189
- expect(schema).toContain('https://example.com');
190
- });
191
-
192
- it('generates product schema template', () => {
193
- const schema = generateSchemaTemplate('product', {
194
- siteName: 'Test Store',
195
- siteUrl: 'https://store.example.com',
196
- });
197
- expect(schema).toContain('Product');
198
- expect(schema).toContain('Offer');
199
- });
200
-
201
- it('generates FAQ schema template', () => {
202
- const schema = generateSchemaTemplate('faq', {
203
- siteName: 'Help Center',
204
- siteUrl: 'https://help.example.com',
205
- });
206
- expect(schema).toContain('FAQPage');
207
- expect(schema).toContain('Question');
208
- });
209
- });
210
- });