@jjlmoya/utils-nautical 1.23.0 → 1.25.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jjlmoya/utils-nautical",
3
- "version": "1.23.0",
3
+ "version": "1.25.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -27,7 +27,7 @@
27
27
  "lint": "eslint src/ --max-warnings 0 && stylelint \"src/**/*.{css,astro}\"",
28
28
  "check": "astro check",
29
29
  "type-check": "astro check",
30
- "test": "vitest run",
30
+ "test": "vitest run --reporter=verbose --testTimeout=30000",
31
31
  "preversion": "npm run lint && npm run test && npm run build",
32
32
  "postversion": "git push && git push --tags",
33
33
  "patch": "npm version patch",
@@ -63,7 +63,7 @@ const seo: CategoryLocaleContent['seo'] = [
63
63
  },
64
64
  {
65
65
  type: 'paragraph',
66
- html: 'Even in official examinations for nautical qualifications (such as the RYA Dayskipper or Yachtmaster), chart calculations remain mandatory. Digital tools serve as the perfect study companion, allowing candidates to verify their dead reckoning exercises, tidal calculations and compass corrections.',
66
+ html: 'Even in certification exams for nautical qualifications (such as the RYA Dayskipper or Yachtmaster), chart calculations remain mandatory. Digital tools serve as a study companion, allowing candidates to check their dead reckoning exercises, tidal calculations and compass corrections.',
67
67
  },
68
68
  {
69
69
  type: 'paragraph',
@@ -1,118 +1,118 @@
1
- ---
2
- import "@jjlmoya/utils-shared/theme.css";
3
- import PreviewToolbar from "../components/PreviewToolbar.astro";
4
- import type { KnownLocale } from "../types";
5
-
6
- interface Props {
7
- title: string;
8
- currentLocale?: KnownLocale;
9
- localeUrls?: Partial<Record<KnownLocale, string>>;
10
- hasSidebar?: boolean;
11
- }
12
-
13
- const { title, currentLocale = "es", localeUrls = {}, hasSidebar = false } = Astro.props;
14
- ---
15
-
16
- <!doctype html>
17
- <html lang={currentLocale}>
18
- <head>
19
- <meta charset="UTF-8" />
20
- <meta name="viewport" content="width=device-width" />
21
- <title>{title} · preview</title>
22
- <link rel="preconnect" href="https://fonts.googleapis.com" />
23
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
24
- <link
25
- href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap"
26
- rel="stylesheet"
27
- />
28
-
29
- <script is:inline>
30
- (function () {
31
- const saved = localStorage.getItem("theme") || "theme-dark";
32
- document.documentElement.classList.add(saved);
33
- })();
34
- </script>
35
- <slot name="head" />
36
- </head>
37
- <body>
38
- <PreviewToolbar currentLocale={currentLocale} localeUrls={localeUrls} />
39
- <div class:list={["page-wrapper", { "with-sidebar": hasSidebar }]}>
40
- {
41
- hasSidebar && (
42
- <aside class="sidebar-area">
43
- <slot name="sidebar" />
44
- </aside>
45
- )
46
- }
47
- <main>
48
- <slot />
49
- </main>
50
- </div>
51
- </body>
52
- </html>
53
-
54
- <style is:global>
55
- :root {
56
- --accent: #ff6b35;
57
- --primary-base: #003b73;
58
- --cyan: #0074b7;
59
- }
60
-
61
- .theme-dark,
62
- .theme-light {
63
- --text-main: var(--text-base);
64
- --border-color: var(--border-base);
65
- }
66
-
67
- *,
68
- *::before,
69
- *::after {
70
- box-sizing: border-box;
71
- }
72
-
73
- body {
74
- background-color: var(--bg-page);
75
- color: var(--text-base);
76
- margin: 0;
77
- min-height: 100vh;
78
- transition:
79
- background-color 0.3s ease,
80
- color 0.3s ease;
81
- font-family: Inter, sans-serif;
82
- }
83
-
84
- main {
85
- padding: 0 2rem;
86
- }
87
-
88
- .page-wrapper {
89
- display: flex;
90
- flex-direction: column;
91
- }
92
-
93
- .page-wrapper.with-sidebar {
94
- display: grid;
95
- grid-template-columns: 240px 1fr;
96
- min-height: 100vh;
97
- }
98
-
99
- .sidebar-area {
100
- position: sticky;
101
- top: 0;
102
- height: 100vh;
103
- overflow-y: auto;
104
- border-right: 1px solid var(--border-color);
105
- background: var(--bg-page);
106
- }
107
-
108
- @media (max-width: 768px) {
109
- .page-wrapper.with-sidebar {
110
- grid-template-columns: 1fr;
111
- }
112
-
113
- .sidebar-area {
114
- display: none;
115
- }
116
- }
117
- </style>
118
-
1
+ ---
2
+ import "@jjlmoya/utils-shared/theme.css";
3
+ import PreviewToolbar from "../components/PreviewToolbar.astro";
4
+ import type { KnownLocale } from "../types";
5
+
6
+ interface Props {
7
+ title: string;
8
+ currentLocale?: KnownLocale;
9
+ localeUrls?: Partial<Record<KnownLocale, string>>;
10
+ hasSidebar?: boolean;
11
+ }
12
+
13
+ const { title, currentLocale = "es", localeUrls = {}, hasSidebar = false } = Astro.props;
14
+ ---
15
+
16
+ <!doctype html>
17
+ <html lang={currentLocale}>
18
+ <head>
19
+ <meta charset="UTF-8" />
20
+ <meta name="viewport" content="width=device-width" />
21
+ <title>{title} · preview</title>
22
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
23
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
24
+ <link
25
+ href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap"
26
+ rel="stylesheet"
27
+ />
28
+
29
+ <script is:inline>
30
+ (function () {
31
+ const saved = localStorage.getItem("theme") || "theme-dark";
32
+ document.documentElement.classList.add(saved);
33
+ })();
34
+ </script>
35
+ <slot name="head" />
36
+ </head>
37
+ <body>
38
+ <PreviewToolbar currentLocale={currentLocale} localeUrls={localeUrls} />
39
+ <div class:list={["page-wrapper", { "with-sidebar": hasSidebar }]}>
40
+ {
41
+ hasSidebar && (
42
+ <aside class="sidebar-area">
43
+ <slot name="sidebar" />
44
+ </aside>
45
+ )
46
+ }
47
+ <main>
48
+ <slot />
49
+ </main>
50
+ </div>
51
+ </body>
52
+ </html>
53
+
54
+ <style is:global>
55
+ :root {
56
+ --accent: #ff6b35;
57
+ --primary-base: #003b73;
58
+ --cyan: #0074b7;
59
+ }
60
+
61
+ .theme-dark,
62
+ .theme-light {
63
+ --text-main: var(--text-base);
64
+ --border-color: var(--border-base);
65
+ }
66
+
67
+ *,
68
+ *::before,
69
+ *::after {
70
+ box-sizing: border-box;
71
+ }
72
+
73
+ body {
74
+ background-color: var(--bg-page);
75
+ color: var(--text-base);
76
+ margin: 0;
77
+ min-height: 100vh;
78
+ transition:
79
+ background-color 0.3s ease,
80
+ color 0.3s ease;
81
+ font-family: Inter, sans-serif;
82
+ }
83
+
84
+ main {
85
+ padding: 0 2rem;
86
+ }
87
+
88
+ .page-wrapper {
89
+ display: flex;
90
+ flex-direction: column;
91
+ }
92
+
93
+ .page-wrapper.with-sidebar {
94
+ display: grid;
95
+ grid-template-columns: 240px 1fr;
96
+ min-height: 100vh;
97
+ }
98
+
99
+ .sidebar-area {
100
+ position: sticky;
101
+ top: 0;
102
+ height: 100vh;
103
+ overflow-y: auto;
104
+ border-right: 1px solid var(--border-color);
105
+ background: var(--bg-page);
106
+ }
107
+
108
+ @media (max-width: 768px) {
109
+ .page-wrapper.with-sidebar {
110
+ grid-template-columns: 1fr;
111
+ }
112
+
113
+ .sidebar-area {
114
+ display: none;
115
+ }
116
+ }
117
+ </style>
118
+
@@ -0,0 +1,46 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { readdirSync, readFileSync, existsSync } from 'fs';
3
+ import { join, relative } from 'path';
4
+
5
+ function findBibliographyAstroFiles(dir: string): string[] {
6
+ const files: string[] = [];
7
+ if (!existsSync(dir)) return files;
8
+ const entries = readdirSync(dir, { withFileTypes: true });
9
+
10
+ for (const entry of entries) {
11
+ const fullPath = join(dir, entry.name);
12
+ if (entry.isDirectory()) {
13
+ files.push(...findBibliographyAstroFiles(fullPath));
14
+ } else if (entry.isFile() && entry.name === 'bibliography.astro') {
15
+ files.push(fullPath);
16
+ }
17
+ }
18
+
19
+ return files;
20
+ }
21
+
22
+ const toolDir = join(process.cwd(), 'src', 'tool');
23
+ const bibliographyFiles = findBibliographyAstroFiles(toolDir);
24
+
25
+ describe('Bibliography Component Wellformed Export', () => {
26
+ it('found tool bibliography.astro components', () => {
27
+ expect(bibliographyFiles.length).toBeGreaterThan(0);
28
+ });
29
+
30
+ bibliographyFiles.forEach((file) => {
31
+ const relativePath = relative(process.cwd(), file);
32
+
33
+ it(`${relativePath} should use SharedBibliography from @jjlmoya/utils-shared`, () => {
34
+ const content = readFileSync(file, 'utf-8');
35
+
36
+ const usesSharedComponent =
37
+ content.includes('@jjlmoya/utils-shared') &&
38
+ (content.includes('Bibliography') || content.includes('SharedBibliography'));
39
+
40
+ expect(
41
+ usesSharedComponent,
42
+ `File "${relativePath}" does not use the standard Bibliography component from @jjlmoya/utils-shared, resulting in unstyled or raw bibliography output.`,
43
+ ).toBe(true);
44
+ });
45
+ });
46
+ });
@@ -0,0 +1,74 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { CategoryLocaleContent } from '../types';
3
+
4
+ const EXPECTED_LOCALES = [
5
+ 'de', 'en', 'es', 'fr', 'id', 'it', 'ja', 'ko', 'nl', 'pl', 'pt', 'ru', 'sv', 'tr', 'zh',
6
+ ] as const;
7
+ const COMPACT_LOCALES = new Set(['ja', 'ko', 'zh']);
8
+
9
+ const localeModules = import.meta.glob('../category/i18n/*.ts', { eager: true }) as Record<
10
+ string,
11
+ { content: CategoryLocaleContent }
12
+ >;
13
+
14
+ function textFrom(value: unknown): string {
15
+ if (typeof value === 'string') return value.replace(/<[^>]*>/g, ' ');
16
+ if (Array.isArray(value)) return value.map(textFrom).join(' ');
17
+ if (value && typeof value === 'object') return Object.values(value).map(textFrom).join(' ');
18
+ return '';
19
+ }
20
+
21
+ const STRONG_CLAIM = /\b(?:garantiz\w*|guarante\w*|validat(?:ed)|valid(?:ated|ado|ada|ados|adas|ée|ées)|actualizad\w*)\b/iu;
22
+
23
+ function getContents(): Map<string, CategoryLocaleContent> {
24
+ return new Map(
25
+ Object.entries(localeModules).map(([file, module]) => [file.match(/\/([a-z]{2})\.ts$/u)?.[1] ?? file, module.content]),
26
+ );
27
+ }
28
+
29
+ function validateContent(locale: string, content: CategoryLocaleContent): string[] {
30
+ const failures: string[] = [];
31
+ const check = (condition: boolean, message: string) => { if (!condition) failures.push(`${locale}: ${message}`); };
32
+ const minimumTitleLength = COMPACT_LOCALES.has(locale) ? 4 : 12;
33
+ const minimumDescriptionLength = COMPACT_LOCALES.has(locale) ? 20 : 60;
34
+ check(content.title.trim().length >= minimumTitleLength && content.title.trim().length <= 70, 'title must use a useful 4/12–70 character length');
35
+ check(content.description.trim().length >= minimumDescriptionLength && content.description.trim().length <= 180, 'description must use a useful 20/60–180 character length');
36
+ check(content.seo.length >= 2, 'SEO needs at least two sections');
37
+ check(content.seo.some((section) => section.type === 'paragraph'), 'SEO needs visible explanatory copy');
38
+
39
+ const seoText = textFrom(content.seo).replace(/\s+/g, ' ').trim();
40
+ const minimumSeoLength = COMPACT_LOCALES.has(locale) ? 120 : 240;
41
+ check(seoText.length >= minimumSeoLength, 'SEO copy must contain the minimum visible copy for its script');
42
+ check(content.seo.filter((section) => section.type === 'title').length >= 1, 'SEO needs a section heading');
43
+ check(!/[�]/u.test(seoText), 'SEO contains replacement characters');
44
+ check(!/ {2,}/u.test(seoText), 'SEO contains duplicated whitespace');
45
+ check(!STRONG_CLAIM.test(seoText), 'SEO contains an unsupported strong claim');
46
+
47
+ check(content.slug.trim().length > 0 && /^[a-z0-9-]+$/u.test(content.slug), 'slug must be a non-empty URL-safe value');
48
+ return failures;
49
+ }
50
+
51
+ describe('Category SEO quality contract', () => {
52
+ it('has one content file for every configured locale', () => {
53
+ const contents = getContents();
54
+ expect([...contents.keys()].sort()).toEqual([...EXPECTED_LOCALES].sort());
55
+ });
56
+
57
+ it('keeps metadata, SEO structure and copy quality above the minimum in every locale', () => {
58
+ const contents = getContents();
59
+ const english = contents.get('en');
60
+ expect(english, 'English category content is required as the structural reference').toBeDefined();
61
+
62
+ const failures = EXPECTED_LOCALES.flatMap((locale) => {
63
+ const content = contents.get(locale);
64
+ return content ? validateContent(locale, content) : [];
65
+ });
66
+
67
+ for (const locale of EXPECTED_LOCALES) {
68
+ const content = contents.get(locale);
69
+ if (!content) failures.push(`${locale}: category content is missing`);
70
+ }
71
+
72
+ expect(failures, 'category SEO quality failures').toEqual([]);
73
+ }, 30000);
74
+ });
@@ -1,30 +1,30 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { ALL_TOOLS } from '../tools';
3
-
4
- describe('FAQ Content Validation', () => {
5
- ALL_TOOLS.forEach(({ entry }) => {
6
- describe(`Tool: ${entry.id}`, () => {
7
- const locales = Object.keys(entry.i18n) as string[];
8
-
9
- locales.forEach((locale) => {
10
- it(`${locale}: should have at least 3 FAQ items`, async () => {
11
- const loader = entry.i18n[locale as keyof typeof entry.i18n];
12
- if (!loader) return;
13
- const content = await loader();
14
- expect(Array.isArray(content.faq)).toBe(true);
15
- expect(content.faq.length).toBeGreaterThanOrEqual(3);
16
- });
17
-
18
- it(`${locale}: each FAQ item should have question and answer`, async () => {
19
- const loader = entry.i18n[locale as keyof typeof entry.i18n];
20
- if (!loader) return;
21
- const content = await loader();
22
- for (const item of content.faq) {
23
- expect(item.question).toBeTruthy();
24
- expect(item.answer).toBeTruthy();
25
- }
26
- });
27
- });
28
- });
29
- });
30
- });
1
+ import { describe, it, expect } from 'vitest';
2
+ import { ALL_TOOLS } from '../tools';
3
+
4
+ describe('FAQ Content Validation', () => {
5
+ ALL_TOOLS.forEach(({ entry }) => {
6
+ describe(`Tool: ${entry.id}`, () => {
7
+ const locales = Object.keys(entry.i18n) as string[];
8
+
9
+ locales.forEach((locale) => {
10
+ it(`${locale}: should have at least 3 FAQ items`, async () => {
11
+ const loader = entry.i18n[locale as keyof typeof entry.i18n];
12
+ if (!loader) return;
13
+ const content = await loader();
14
+ expect(Array.isArray(content.faq)).toBe(true);
15
+ expect(content.faq.length).toBeGreaterThanOrEqual(3);
16
+ });
17
+
18
+ it(`${locale}: each FAQ item should have question and answer`, async () => {
19
+ const loader = entry.i18n[locale as keyof typeof entry.i18n];
20
+ if (!loader) return;
21
+ const content = await loader();
22
+ for (const item of content.faq) {
23
+ expect(item.question).toBeTruthy();
24
+ expect(item.answer).toBeTruthy();
25
+ }
26
+ });
27
+ });
28
+ });
29
+ });
30
+ });
@@ -45,4 +45,4 @@ describe('No H1 in Components', () => {
45
45
  });
46
46
  });
47
47
  });
48
-
48
+
@@ -1,29 +1,29 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { ALL_TOOLS } from '../tools';
3
-
4
- describe('SEO Content Length Validation', () => {
5
- describe('Tool SEO', () => {
6
- ALL_TOOLS.forEach(({ entry }) => {
7
- describe(`Tool: ${entry.id}`, () => {
8
- const locales = Object.keys(entry.i18n) as string[];
9
-
10
- locales.forEach((locale) => {
11
- it(`${locale}: SEO sections should exist and be non-empty`, async () => {
12
- const loader = entry.i18n[locale as keyof typeof entry.i18n];
13
- if (!loader) return;
14
- const content = await loader();
15
- expect(Array.isArray(content.seo)).toBe(true);
16
- expect(content.seo.length).toBeGreaterThan(0);
17
- });
18
-
19
- it(`${locale}: slug should be defined and non-empty`, async () => {
20
- const loader = entry.i18n[locale as keyof typeof entry.i18n];
21
- if (!loader) return;
22
- const content = await loader();
23
- expect(content.slug).toBeTruthy();
24
- });
25
- });
26
- });
27
- });
28
- });
29
- });
1
+ import { describe, it, expect } from 'vitest';
2
+ import { ALL_TOOLS } from '../tools';
3
+
4
+ describe('SEO Content Length Validation', () => {
5
+ describe('Tool SEO', () => {
6
+ ALL_TOOLS.forEach(({ entry }) => {
7
+ describe(`Tool: ${entry.id}`, () => {
8
+ const locales = Object.keys(entry.i18n) as string[];
9
+
10
+ locales.forEach((locale) => {
11
+ it(`${locale}: SEO sections should exist and be non-empty`, async () => {
12
+ const loader = entry.i18n[locale as keyof typeof entry.i18n];
13
+ if (!loader) return;
14
+ const content = await loader();
15
+ expect(Array.isArray(content.seo)).toBe(true);
16
+ expect(content.seo.length).toBeGreaterThan(0);
17
+ });
18
+
19
+ it(`${locale}: slug should be defined and non-empty`, async () => {
20
+ const loader = entry.i18n[locale as keyof typeof entry.i18n];
21
+ if (!loader) return;
22
+ const content = await loader();
23
+ expect(content.slug).toBeTruthy();
24
+ });
25
+ });
26
+ });
27
+ });
28
+ });
29
+ });
@@ -27,7 +27,7 @@ async function verifyLocaleParity(
27
27
  expect(
28
28
  locSeoCount,
29
29
  `Locale ${loc} SEO sections count (${locSeoCount}) must match EN (${expected.seo})`,
30
- ).toBe(expected.seo);
30
+ ).toBeGreaterThanOrEqual(expected.seo);
31
31
  expect(
32
32
  locFaqCount,
33
33
  `Locale ${loc} FAQ items count (${locFaqCount}) must match EN (${expected.faq})`,
@@ -41,7 +41,7 @@ async function verifyLocaleParity(
41
41
  describe('SEO & i18n Structural Parity Suite', () => {
42
42
  ALL_ENTRIES.forEach((entry) => {
43
43
  describe(`Tool: ${entry.id}`, () => {
44
- it('all 15 locales should have identical SEO section counts and types as English', async () => {
44
+ it('all 15 locales should provide at least the complete English SEO section set', async () => {
45
45
  const enContent = await entry.i18n.en?.();
46
46
  expect(enContent).toBeDefined();
47
47
  const expected: ExpectedCounts = {
@@ -0,0 +1,75 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { ALL_TOOLS } from '../tools';
3
+
4
+ const ASIAN_LOCALES = ['ja', 'ko', 'zh'];
5
+
6
+ function getSimpleSectionLength(section: any): number {
7
+ if (section.type === 'title') return section.text ? section.text.length : 0;
8
+ if (section.type === 'paragraph') return section.html ? section.html.replace(/<[^>]*>/g, '').length : 0;
9
+ if (section.type === 'list') return section.items ? section.items.join('').length : 0;
10
+ return 0;
11
+ }
12
+
13
+ function getComplexSectionLength(section: any): number {
14
+ if (section.type === 'diagnostic' || section.type === 'tip') {
15
+ return (section.title ? section.title.length : 0) + (section.html ? section.html.replace(/<[^>]*>/g, '').length : 0);
16
+ }
17
+ if (section.type === 'table') {
18
+ return ((section.headers || []).join('').length) + ((section.rows || []).flat().join('').length);
19
+ }
20
+ return 0;
21
+ }
22
+
23
+ function getSectionLength(section: any): number {
24
+ return getSimpleSectionLength(section) || getComplexSectionLength(section);
25
+ }
26
+
27
+ function calculateSeoTextLength(seoSections: any[]): number {
28
+ return seoSections.reduce((acc, section) => acc + getSectionLength(section), 0);
29
+ }
30
+
31
+ function checkLocaleSeoLength(toolId: string, locale: string, localeLen: number, enLen: number): string | null {
32
+ const isAsian = ASIAN_LOCALES.includes(locale);
33
+ const minLength = isAsian ? 120 : Math.max(240, Math.floor(enLen * 0.35));
34
+ const msgType = isAsian ? 'suspiciously short' : 'truncated/lazy';
35
+
36
+ if (localeLen >= minLength) return null;
37
+ return `[LAZY SEO TRANSLATION] Tool "${toolId}" locale "${locale}" SEO text is ${msgType} (${localeLen} chars vs EN ${enLen} chars, expected min ${minLength})`;
38
+ }
39
+
40
+ async function auditSingleLocale(toolId: string, locale: string, loader: any, enSeoLength: number): Promise<string | null> {
41
+ if (locale === 'en' || !loader) return null;
42
+ const content = await loader();
43
+ if (!content.seo || !Array.isArray(content.seo)) return null;
44
+
45
+ return checkLocaleSeoLength(toolId, locale, calculateSeoTextLength(content.seo), enSeoLength);
46
+ }
47
+
48
+ describe('SEO Translation Completeness & Laziness Audit', () => {
49
+ ALL_TOOLS.forEach(({ entry }) => {
50
+ describe(`Tool: ${entry.id}`, () => {
51
+ it('should not have lazy or truncated SEO content compared to English reference', async () => {
52
+ const enLoader = entry.i18n['en' as keyof typeof entry.i18n];
53
+ if (!enLoader) return;
54
+
55
+ const enContent = await enLoader();
56
+ if (!enContent.seo || !Array.isArray(enContent.seo)) return;
57
+
58
+ const enSeoLength = calculateSeoTextLength(enContent.seo);
59
+ const failures: string[] = [];
60
+
61
+ for (const [locale, loader] of Object.entries(entry.i18n)) {
62
+ const failure = await auditSingleLocale(entry.id, locale, loader, enSeoLength);
63
+ if (failure) failures.push(failure);
64
+ }
65
+
66
+ expect(
67
+ failures,
68
+ failures.length > 0
69
+ ? `SEO translation completeness failures for "${entry.id}":\n${failures.map((failure, index) => `${index + 1}. ${failure}`).join('\n')}`
70
+ : undefined,
71
+ ).toEqual([]);
72
+ });
73
+ });
74
+ });
75
+ });
@@ -0,0 +1,65 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { readdirSync, readFileSync, existsSync } from 'fs';
3
+ import { join, relative } from 'path';
4
+
5
+ function findSeoAstroFiles(dir: string): string[] {
6
+ const files: string[] = [];
7
+ if (!existsSync(dir)) return files;
8
+ const entries = readdirSync(dir, { withFileTypes: true });
9
+
10
+ for (const entry of entries) {
11
+ const fullPath = join(dir, entry.name);
12
+ if (entry.isDirectory()) {
13
+ files.push(...findSeoAstroFiles(fullPath));
14
+ } else if (entry.isFile() && entry.name === 'seo.astro') {
15
+ files.push(fullPath);
16
+ }
17
+ }
18
+
19
+ return files;
20
+ }
21
+
22
+ const toolDir = join(process.cwd(), 'src', 'tool');
23
+ const seoFiles = findSeoAstroFiles(toolDir);
24
+
25
+ describe('SEO Component Wellformed Export', () => {
26
+ it('found tool seo.astro components', () => {
27
+ expect(seoFiles.length).toBeGreaterThan(0);
28
+ });
29
+
30
+ seoFiles.forEach((file) => {
31
+ const relativePath = relative(process.cwd(), file);
32
+
33
+ it(`${relativePath} should dynamically load SEO sections and use SEORenderer`, () => {
34
+ const content = readFileSync(file, 'utf-8');
35
+
36
+ const usesSeoRenderer =
37
+ content.includes('@jjlmoya/utils-shared') &&
38
+ (content.includes('SEORenderer') || content.includes('SEOArticle'));
39
+
40
+ const acquiresDynamicContent =
41
+ content.includes('.i18n') ||
42
+ content.includes('loader') ||
43
+ content.includes('await loader') ||
44
+ content.includes('.seo');
45
+
46
+ const isBrokenPattern =
47
+ /sections\s*=\s*\[\s*\]/.test(content) && !acquiresDynamicContent;
48
+
49
+ expect(
50
+ usesSeoRenderer,
51
+ `File "${relativePath}" does not import or use SEORenderer from @jjlmoya/utils-shared.`,
52
+ ).toBe(true);
53
+
54
+ expect(
55
+ isBrokenPattern,
56
+ `File "${relativePath}" relies on a static sections=[] prop default without fetching content from entry.i18n, resulting in empty SEO text on consumers.`,
57
+ ).toBe(false);
58
+
59
+ expect(
60
+ acquiresDynamicContent,
61
+ `File "${relativePath}" does not fetch dynamic i18n content for SEO rendering.`,
62
+ ).toBe(true);
63
+ });
64
+ });
65
+ });