@easy-web/core 1.3.3 → 1.4.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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +9 -9
  3. package/src/components/Header.astro +205 -205
  4. package/src/components/HeaderCentered.astro +230 -230
  5. package/src/components/HeaderFlyout.astro +370 -370
  6. package/src/components/HeaderHideOnScroll.astro +234 -234
  7. package/src/components/LanguageSwitch.astro +82 -82
  8. package/src/components/NotFound.astro +115 -115
  9. package/src/components/PageShell.astro +82 -82
  10. package/src/components/SeoHead.astro +106 -106
  11. package/src/components/StructuredData.astro +1 -1
  12. package/src/components/ThemeToggle.astro +84 -84
  13. package/src/components/UniversalMedia.astro +106 -106
  14. package/src/components/__tests__/StructuredData.test.ts +1 -1
  15. package/src/components/__tests__/UniversalMedia.test.ts +65 -65
  16. package/src/contracts/__tests__/jsonld.test.ts +1 -1
  17. package/src/contracts/index.ts +1 -1
  18. package/src/contracts/jsonld.ts +1 -1
  19. package/src/i18n/__tests__/factory.test.ts +54 -54
  20. package/src/i18n/__tests__/localized-paths.test.ts +258 -258
  21. package/src/i18n/__tests__/routing-multi-locale.test.ts +89 -89
  22. package/src/i18n/__tests__/seo.test.ts +140 -140
  23. package/src/i18n/factory.ts +66 -66
  24. package/src/i18n/index.ts +5 -5
  25. package/src/i18n/localized-paths.ts +181 -181
  26. package/src/i18n/seo.ts +131 -131
  27. package/src/markdown/__tests__/__fixtures__/abs-src-assets.md +1 -1
  28. package/src/markdown/__tests__/__fixtures__/external-url.md +1 -1
  29. package/src/markdown/__tests__/__fixtures__/public-slash.md +1 -1
  30. package/src/markdown/__tests__/__fixtures__/rel-double-dot.md +1 -1
  31. package/src/markdown/__tests__/index.test.ts +60 -60
  32. package/src/markdown/index.ts +1 -1
  33. package/src/markdown/plugin.ts +42 -42
  34. package/src/schemas/__tests__/notFound.test.ts +32 -32
  35. package/src/schemas/notFound.ts +33 -33
  36. package/src/seo/__tests__/crawl-policy.test.ts +50 -50
  37. package/src/seo/__tests__/integration.test.ts +195 -195
  38. package/src/seo/__tests__/no-index-resolution.test.ts +53 -53
  39. package/src/seo/__tests__/robots-txt.test.ts +66 -66
  40. package/src/seo/__tests__/sitemap-options.test.ts +400 -400
  41. package/src/seo/crawl-policy.ts +36 -36
  42. package/src/seo/index.ts +254 -254
  43. package/src/seo/routes/robots-txt.ts +36 -36
@@ -1,195 +1,195 @@
1
- import { describe, it, expect, vi, afterEach } from 'vitest';
2
- import easyWebSeo from '../index.js';
3
-
4
- type ConfigSetupHook = (params: {
5
- config: unknown;
6
- updateConfig: (patch: unknown) => void;
7
- injectRoute: (route: unknown) => void;
8
- logger: { error: (msg: string) => void; warn: (msg: string) => void; info: (msg: string) => void };
9
- }) => void;
10
-
11
- const getConfigSetupHook = (integration: ReturnType<typeof easyWebSeo>): ConfigSetupHook => {
12
- const hook = integration.hooks['astro:config:setup'];
13
- if (typeof hook !== 'function') {
14
- throw new Error('astro:config:setup hook missing on integration');
15
- }
16
- return hook as unknown as ConfigSetupHook;
17
- };
18
-
19
- describe('easyWebSeo integration factory', () => {
20
- afterEach(() => {
21
- delete process.env.EASY_WEB_SEO_NO_INDEX;
22
- vi.restoreAllMocks();
23
- });
24
-
25
- it('returns an AstroIntegration shape with name and astro:config:setup hook', () => {
26
- const integration = easyWebSeo();
27
- expect(integration.name).toBe('@easy-web/seo');
28
- expect(typeof integration.hooks['astro:config:setup']).toBe('function');
29
- });
30
-
31
- it('sets EASY_WEB_SEO_NO_INDEX=false by default and injects /robots.txt route', () => {
32
- const integration = easyWebSeo();
33
- const mockConfig = {
34
- site: new URL('https://example.com'),
35
- base: '/',
36
- trailingSlash: 'ignore',
37
- build: { format: 'directory' },
38
- i18n: undefined,
39
- integrations: [],
40
- };
41
- const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
42
- const mockInjectRoute = vi.fn();
43
- const mockUpdateConfig = vi.fn();
44
-
45
- getConfigSetupHook(integration)({
46
- config: mockConfig,
47
- updateConfig: mockUpdateConfig,
48
- injectRoute: mockInjectRoute,
49
- logger: mockLogger,
50
- });
51
-
52
- expect(process.env.EASY_WEB_SEO_NO_INDEX).toBe('false');
53
- expect(mockInjectRoute).toHaveBeenCalledOnce();
54
- expect(mockInjectRoute).toHaveBeenCalledWith(
55
- expect.objectContaining({
56
- pattern: '/robots.txt',
57
- prerender: true,
58
- }),
59
- );
60
- expect(mockUpdateConfig).toHaveBeenCalledOnce();
61
- });
62
-
63
- it('sets EASY_WEB_SEO_NO_INDEX=true when noIndex option is true', () => {
64
- const integration = easyWebSeo({ noIndex: true });
65
- const mockConfig = {
66
- site: new URL('https://example.com'),
67
- base: '/',
68
- trailingSlash: 'ignore',
69
- build: { format: 'directory' },
70
- i18n: undefined,
71
- integrations: [],
72
- };
73
- const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
74
-
75
- getConfigSetupHook(integration)({
76
- config: mockConfig,
77
- updateConfig: vi.fn(),
78
- injectRoute: vi.fn(),
79
- logger: mockLogger,
80
- });
81
-
82
- expect(process.env.EASY_WEB_SEO_NO_INDEX).toBe('true');
83
- });
84
-
85
- it('throws and logs an error when site is not configured', () => {
86
- const integration = easyWebSeo();
87
- const mockConfig = { site: undefined, i18n: undefined, integrations: [] };
88
- const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
89
- const hook = getConfigSetupHook(integration);
90
-
91
- expect(() =>
92
- hook({
93
- config: mockConfig,
94
- updateConfig: vi.fn(),
95
- injectRoute: vi.fn(),
96
- logger: mockLogger,
97
- }),
98
- ).toThrow('@easy-web/seo');
99
- expect(mockLogger.error).toHaveBeenCalledOnce();
100
- });
101
-
102
- it('falls back to language-only hreflang tags when i18n is set but sitemapLocales is not', () => {
103
- const integration = easyWebSeo();
104
- const mockConfig = {
105
- site: new URL('https://example.com'),
106
- base: '/',
107
- trailingSlash: 'ignore',
108
- build: { format: 'directory' },
109
- i18n: { locales: ['de', 'en'], defaultLocale: 'de', routing: {} },
110
- integrations: [],
111
- };
112
- const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
113
- const mockUpdateConfig = vi.fn();
114
-
115
- getConfigSetupHook(integration)({
116
- config: mockConfig,
117
- updateConfig: mockUpdateConfig,
118
- injectRoute: vi.fn(),
119
- logger: mockLogger,
120
- });
121
-
122
- expect(mockUpdateConfig).toHaveBeenCalledWith(
123
- expect.objectContaining({
124
- integrations: expect.arrayContaining([
125
- expect.objectContaining({ name: '@astrojs/sitemap' }),
126
- ]),
127
- }),
128
- );
129
- expect(mockLogger.warn).toHaveBeenCalledOnce();
130
- const warning = mockLogger.warn.mock.calls[0][0] as string;
131
- expect(warning).toContain('language-only');
132
- expect(warning).not.toContain('en-EN');
133
- });
134
-
135
- it('passes sitemapLocales verbatim (no warning) when caller provides an explicit locale map', () => {
136
- const customLocales = { de: 'de-DE', en: 'en-US' };
137
- const integration = easyWebSeo({ sitemapLocales: customLocales });
138
- const mockConfig = {
139
- site: new URL('https://example.com'),
140
- base: '/',
141
- trailingSlash: 'ignore',
142
- build: { format: 'directory' },
143
- i18n: { locales: ['de', 'en'], defaultLocale: 'de', routing: {} },
144
- integrations: [],
145
- };
146
- const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
147
- const mockUpdateConfig = vi.fn();
148
-
149
- getConfigSetupHook(integration)({
150
- config: mockConfig,
151
- updateConfig: mockUpdateConfig,
152
- injectRoute: vi.fn(),
153
- logger: mockLogger,
154
- });
155
-
156
- expect(mockLogger.warn).not.toHaveBeenCalled();
157
- expect(mockUpdateConfig).toHaveBeenCalledWith(
158
- expect.objectContaining({
159
- integrations: expect.arrayContaining([
160
- expect.objectContaining({ name: '@astrojs/sitemap' }),
161
- ]),
162
- }),
163
- );
164
- });
165
-
166
- it('handles Astro path-style locales (objects with .path) when falling back to language-only tags', () => {
167
- const integration = easyWebSeo();
168
- const mockConfig = {
169
- site: new URL('https://example.com'),
170
- base: '/',
171
- trailingSlash: 'ignore',
172
- build: { format: 'directory' },
173
- i18n: {
174
- locales: [{ path: 'de', codes: ['de'] }, { path: 'en', codes: ['en'] }],
175
- defaultLocale: 'de',
176
- routing: {},
177
- },
178
- integrations: [],
179
- };
180
- const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
181
-
182
- getConfigSetupHook(integration)({
183
- config: mockConfig,
184
- updateConfig: vi.fn(),
185
- injectRoute: vi.fn(),
186
- logger: mockLogger,
187
- });
188
-
189
- expect(mockLogger.warn).toHaveBeenCalledOnce();
190
- const warning = mockLogger.warn.mock.calls[0][0] as string;
191
- expect(warning).toContain('de');
192
- expect(warning).toContain('en');
193
- expect(warning).not.toContain('en-EN');
194
- });
195
- });
1
+ import { describe, it, expect, vi, afterEach } from 'vitest';
2
+ import easyWebSeo from '../index.js';
3
+
4
+ type ConfigSetupHook = (params: {
5
+ config: unknown;
6
+ updateConfig: (patch: unknown) => void;
7
+ injectRoute: (route: unknown) => void;
8
+ logger: { error: (msg: string) => void; warn: (msg: string) => void; info: (msg: string) => void };
9
+ }) => void;
10
+
11
+ const getConfigSetupHook = (integration: ReturnType<typeof easyWebSeo>): ConfigSetupHook => {
12
+ const hook = integration.hooks['astro:config:setup'];
13
+ if (typeof hook !== 'function') {
14
+ throw new Error('astro:config:setup hook missing on integration');
15
+ }
16
+ return hook as unknown as ConfigSetupHook;
17
+ };
18
+
19
+ describe('easyWebSeo integration factory', () => {
20
+ afterEach(() => {
21
+ delete process.env.EASY_WEB_SEO_NO_INDEX;
22
+ vi.restoreAllMocks();
23
+ });
24
+
25
+ it('returns an AstroIntegration shape with name and astro:config:setup hook', () => {
26
+ const integration = easyWebSeo();
27
+ expect(integration.name).toBe('@easy-web/seo');
28
+ expect(typeof integration.hooks['astro:config:setup']).toBe('function');
29
+ });
30
+
31
+ it('sets EASY_WEB_SEO_NO_INDEX=false by default and injects /robots.txt route', () => {
32
+ const integration = easyWebSeo();
33
+ const mockConfig = {
34
+ site: new URL('https://example.com'),
35
+ base: '/',
36
+ trailingSlash: 'ignore',
37
+ build: { format: 'directory' },
38
+ i18n: undefined,
39
+ integrations: [],
40
+ };
41
+ const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
42
+ const mockInjectRoute = vi.fn();
43
+ const mockUpdateConfig = vi.fn();
44
+
45
+ getConfigSetupHook(integration)({
46
+ config: mockConfig,
47
+ updateConfig: mockUpdateConfig,
48
+ injectRoute: mockInjectRoute,
49
+ logger: mockLogger,
50
+ });
51
+
52
+ expect(process.env.EASY_WEB_SEO_NO_INDEX).toBe('false');
53
+ expect(mockInjectRoute).toHaveBeenCalledOnce();
54
+ expect(mockInjectRoute).toHaveBeenCalledWith(
55
+ expect.objectContaining({
56
+ pattern: '/robots.txt',
57
+ prerender: true,
58
+ }),
59
+ );
60
+ expect(mockUpdateConfig).toHaveBeenCalledOnce();
61
+ });
62
+
63
+ it('sets EASY_WEB_SEO_NO_INDEX=true when noIndex option is true', () => {
64
+ const integration = easyWebSeo({ noIndex: true });
65
+ const mockConfig = {
66
+ site: new URL('https://example.com'),
67
+ base: '/',
68
+ trailingSlash: 'ignore',
69
+ build: { format: 'directory' },
70
+ i18n: undefined,
71
+ integrations: [],
72
+ };
73
+ const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
74
+
75
+ getConfigSetupHook(integration)({
76
+ config: mockConfig,
77
+ updateConfig: vi.fn(),
78
+ injectRoute: vi.fn(),
79
+ logger: mockLogger,
80
+ });
81
+
82
+ expect(process.env.EASY_WEB_SEO_NO_INDEX).toBe('true');
83
+ });
84
+
85
+ it('throws and logs an error when site is not configured', () => {
86
+ const integration = easyWebSeo();
87
+ const mockConfig = { site: undefined, i18n: undefined, integrations: [] };
88
+ const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
89
+ const hook = getConfigSetupHook(integration);
90
+
91
+ expect(() =>
92
+ hook({
93
+ config: mockConfig,
94
+ updateConfig: vi.fn(),
95
+ injectRoute: vi.fn(),
96
+ logger: mockLogger,
97
+ }),
98
+ ).toThrow('@easy-web/seo');
99
+ expect(mockLogger.error).toHaveBeenCalledOnce();
100
+ });
101
+
102
+ it('falls back to language-only hreflang tags when i18n is set but sitemapLocales is not', () => {
103
+ const integration = easyWebSeo();
104
+ const mockConfig = {
105
+ site: new URL('https://example.com'),
106
+ base: '/',
107
+ trailingSlash: 'ignore',
108
+ build: { format: 'directory' },
109
+ i18n: { locales: ['de', 'en'], defaultLocale: 'de', routing: {} },
110
+ integrations: [],
111
+ };
112
+ const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
113
+ const mockUpdateConfig = vi.fn();
114
+
115
+ getConfigSetupHook(integration)({
116
+ config: mockConfig,
117
+ updateConfig: mockUpdateConfig,
118
+ injectRoute: vi.fn(),
119
+ logger: mockLogger,
120
+ });
121
+
122
+ expect(mockUpdateConfig).toHaveBeenCalledWith(
123
+ expect.objectContaining({
124
+ integrations: expect.arrayContaining([
125
+ expect.objectContaining({ name: '@astrojs/sitemap' }),
126
+ ]),
127
+ }),
128
+ );
129
+ expect(mockLogger.warn).toHaveBeenCalledOnce();
130
+ const warning = mockLogger.warn.mock.calls[0][0] as string;
131
+ expect(warning).toContain('language-only');
132
+ expect(warning).not.toContain('en-EN');
133
+ });
134
+
135
+ it('passes sitemapLocales verbatim (no warning) when caller provides an explicit locale map', () => {
136
+ const customLocales = { de: 'de-DE', en: 'en-US' };
137
+ const integration = easyWebSeo({ sitemapLocales: customLocales });
138
+ const mockConfig = {
139
+ site: new URL('https://example.com'),
140
+ base: '/',
141
+ trailingSlash: 'ignore',
142
+ build: { format: 'directory' },
143
+ i18n: { locales: ['de', 'en'], defaultLocale: 'de', routing: {} },
144
+ integrations: [],
145
+ };
146
+ const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
147
+ const mockUpdateConfig = vi.fn();
148
+
149
+ getConfigSetupHook(integration)({
150
+ config: mockConfig,
151
+ updateConfig: mockUpdateConfig,
152
+ injectRoute: vi.fn(),
153
+ logger: mockLogger,
154
+ });
155
+
156
+ expect(mockLogger.warn).not.toHaveBeenCalled();
157
+ expect(mockUpdateConfig).toHaveBeenCalledWith(
158
+ expect.objectContaining({
159
+ integrations: expect.arrayContaining([
160
+ expect.objectContaining({ name: '@astrojs/sitemap' }),
161
+ ]),
162
+ }),
163
+ );
164
+ });
165
+
166
+ it('handles Astro path-style locales (objects with .path) when falling back to language-only tags', () => {
167
+ const integration = easyWebSeo();
168
+ const mockConfig = {
169
+ site: new URL('https://example.com'),
170
+ base: '/',
171
+ trailingSlash: 'ignore',
172
+ build: { format: 'directory' },
173
+ i18n: {
174
+ locales: [{ path: 'de', codes: ['de'] }, { path: 'en', codes: ['en'] }],
175
+ defaultLocale: 'de',
176
+ routing: {},
177
+ },
178
+ integrations: [],
179
+ };
180
+ const mockLogger = { error: vi.fn(), warn: vi.fn(), info: vi.fn() };
181
+
182
+ getConfigSetupHook(integration)({
183
+ config: mockConfig,
184
+ updateConfig: vi.fn(),
185
+ injectRoute: vi.fn(),
186
+ logger: mockLogger,
187
+ });
188
+
189
+ expect(mockLogger.warn).toHaveBeenCalledOnce();
190
+ const warning = mockLogger.warn.mock.calls[0][0] as string;
191
+ expect(warning).toContain('de');
192
+ expect(warning).toContain('en');
193
+ expect(warning).not.toContain('en-EN');
194
+ });
195
+ });
@@ -1,53 +1,53 @@
1
- import { describe, it, expect, afterEach } from 'vitest';
2
-
3
- /**
4
- * Mirrors the crawl-policy resolution inside SeoHead.astro. Tests the precedence
5
- * rules, not the Astro rendering (which requires a full Astro setup) — same
6
- * approach as content-blocks' UniversalMedia dispatch test.
7
- *
8
- * This pins the contract that was broken before: `easyWebSeo()` resolves the
9
- * crawl policy once and publishes it to the environment, and `<SeoHead>` must
10
- * consume that value. Defaulting the prop to `false` instead made the
11
- * integration and the rendered document disagree — sitemap suppressed and
12
- * robots.txt disallowing everything, while every page still shipped without a
13
- * robots meta tag.
14
- */
15
- function resolveShouldNoIndex(noIndex: boolean | undefined, isNotFoundRoute: boolean): boolean {
16
- const policyNoIndex = process.env.EASY_WEB_SEO_NO_INDEX === 'true';
17
- return (noIndex ?? policyNoIndex) || isNotFoundRoute;
18
- }
19
-
20
- describe('<SeoHead> crawl-policy resolution', () => {
21
- afterEach(() => {
22
- delete process.env.EASY_WEB_SEO_NO_INDEX;
23
- });
24
-
25
- it('inherits noindex from the integration when the prop is omitted', () => {
26
- process.env.EASY_WEB_SEO_NO_INDEX = 'true';
27
- expect(resolveShouldNoIndex(undefined, false)).toBe(true);
28
- });
29
-
30
- it('stays indexable when neither the prop nor the policy asks for noindex', () => {
31
- expect(resolveShouldNoIndex(undefined, false)).toBe(false);
32
- });
33
-
34
- it('lets an explicit prop override a site-wide noindex policy', () => {
35
- process.env.EASY_WEB_SEO_NO_INDEX = 'true';
36
- expect(resolveShouldNoIndex(false, false)).toBe(false);
37
- });
38
-
39
- it('honours an explicit prop when no policy is published', () => {
40
- expect(resolveShouldNoIndex(true, false)).toBe(true);
41
- });
42
-
43
- it('always noindexes a 404 route, whatever the prop and policy say', () => {
44
- expect(resolveShouldNoIndex(false, true)).toBe(true);
45
- process.env.EASY_WEB_SEO_NO_INDEX = 'true';
46
- expect(resolveShouldNoIndex(false, true)).toBe(true);
47
- });
48
-
49
- it('treats any non-"true" env value as indexable rather than truthy-string', () => {
50
- process.env.EASY_WEB_SEO_NO_INDEX = 'false';
51
- expect(resolveShouldNoIndex(undefined, false)).toBe(false);
52
- });
53
- });
1
+ import { describe, it, expect, afterEach } from 'vitest';
2
+
3
+ /**
4
+ * Mirrors the crawl-policy resolution inside SeoHead.astro. Tests the precedence
5
+ * rules, not the Astro rendering (which requires a full Astro setup) — same
6
+ * approach as content-blocks' UniversalMedia dispatch test.
7
+ *
8
+ * This pins the contract that was broken before: `easyWebSeo()` resolves the
9
+ * crawl policy once and publishes it to the environment, and `<SeoHead>` must
10
+ * consume that value. Defaulting the prop to `false` instead made the
11
+ * integration and the rendered document disagree — sitemap suppressed and
12
+ * robots.txt disallowing everything, while every page still shipped without a
13
+ * robots meta tag.
14
+ */
15
+ function resolveShouldNoIndex(noIndex: boolean | undefined, isNotFoundRoute: boolean): boolean {
16
+ const policyNoIndex = process.env.EASY_WEB_SEO_NO_INDEX === 'true';
17
+ return (noIndex ?? policyNoIndex) || isNotFoundRoute;
18
+ }
19
+
20
+ describe('<SeoHead> crawl-policy resolution', () => {
21
+ afterEach(() => {
22
+ delete process.env.EASY_WEB_SEO_NO_INDEX;
23
+ });
24
+
25
+ it('inherits noindex from the integration when the prop is omitted', () => {
26
+ process.env.EASY_WEB_SEO_NO_INDEX = 'true';
27
+ expect(resolveShouldNoIndex(undefined, false)).toBe(true);
28
+ });
29
+
30
+ it('stays indexable when neither the prop nor the policy asks for noindex', () => {
31
+ expect(resolveShouldNoIndex(undefined, false)).toBe(false);
32
+ });
33
+
34
+ it('lets an explicit prop override a site-wide noindex policy', () => {
35
+ process.env.EASY_WEB_SEO_NO_INDEX = 'true';
36
+ expect(resolveShouldNoIndex(false, false)).toBe(false);
37
+ });
38
+
39
+ it('honours an explicit prop when no policy is published', () => {
40
+ expect(resolveShouldNoIndex(true, false)).toBe(true);
41
+ });
42
+
43
+ it('always noindexes a 404 route, whatever the prop and policy say', () => {
44
+ expect(resolveShouldNoIndex(false, true)).toBe(true);
45
+ process.env.EASY_WEB_SEO_NO_INDEX = 'true';
46
+ expect(resolveShouldNoIndex(false, true)).toBe(true);
47
+ });
48
+
49
+ it('treats any non-"true" env value as indexable rather than truthy-string', () => {
50
+ process.env.EASY_WEB_SEO_NO_INDEX = 'false';
51
+ expect(resolveShouldNoIndex(undefined, false)).toBe(false);
52
+ });
53
+ });
@@ -1,66 +1,66 @@
1
- import { describe, it, expect, afterEach } from 'vitest';
2
- import type { APIContext } from 'astro';
3
- import { GET } from '../routes/robots-txt.js';
4
-
5
- const runGET = (ctx: Partial<APIContext>): Response => {
6
- const result = GET(ctx as APIContext);
7
- if (!(result instanceof Response)) {
8
- throw new Error('GET returned a non-Response value; robots-txt handler must be synchronous Response');
9
- }
10
- return result;
11
- };
12
-
13
- describe('robots-txt GET handler', () => {
14
- afterEach(() => {
15
- delete process.env.EASY_WEB_SEO_NO_INDEX;
16
- });
17
-
18
- it('returns public robots.txt with Sitemap when EASY_WEB_SEO_NO_INDEX is "false"', async () => {
19
- process.env.EASY_WEB_SEO_NO_INDEX = 'false';
20
- const response = runGET({ site: new URL('https://harleyrentflorida.de') });
21
- const text = await response.text();
22
-
23
- expect(response.status).toBe(200);
24
- expect(response.headers.get('Content-Type')).toBe('text/plain; charset=utf-8');
25
- expect(text).toContain('User-agent: *');
26
- expect(text).toContain('Disallow: /admin/');
27
- expect(text).toContain('Allow: /');
28
- expect(text).toContain('Sitemap: https://harleyrentflorida.de/sitemap-index.xml');
29
- expect(text).not.toMatch(/Disallow: \/\n/);
30
- });
31
-
32
- it('returns noIndex robots.txt (Disallow: /) without Sitemap when EASY_WEB_SEO_NO_INDEX is "true"', async () => {
33
- process.env.EASY_WEB_SEO_NO_INDEX = 'true';
34
- const response = runGET({ site: new URL('https://dev.ismaili.de') });
35
- const text = await response.text();
36
-
37
- expect(response.status).toBe(200);
38
- expect(response.headers.get('Content-Type')).toBe('text/plain; charset=utf-8');
39
- expect(text).toContain('User-agent: *');
40
- expect(text).toMatch(/Disallow: \/\n/);
41
- expect(text).not.toContain('Sitemap:');
42
- expect(text).not.toContain('/admin/');
43
- expect(text).not.toContain('Allow: /');
44
- });
45
-
46
- it('returns 500 fail-safe (Disallow: /, no Sitemap) when site is undefined', async () => {
47
- const response = runGET({ site: undefined });
48
- const text = await response.text();
49
-
50
- expect(response.status).toBe(500);
51
- expect(response.headers.get('Content-Type')).toBe('text/plain; charset=utf-8');
52
- expect(text).toContain('User-agent: *');
53
- expect(text).toContain('Disallow: /');
54
- expect(text).not.toContain('Sitemap:');
55
- });
56
-
57
- it('treats missing EASY_WEB_SEO_NO_INDEX env var as public mode (Sitemap present)', async () => {
58
- delete process.env.EASY_WEB_SEO_NO_INDEX;
59
- const response = runGET({ site: new URL('https://example.com') });
60
- const text = await response.text();
61
-
62
- expect(response.status).toBe(200);
63
- expect(text).toContain('Sitemap: https://example.com/sitemap-index.xml');
64
- expect(text).toContain('Disallow: /admin/');
65
- });
66
- });
1
+ import { describe, it, expect, afterEach } from 'vitest';
2
+ import type { APIContext } from 'astro';
3
+ import { GET } from '../routes/robots-txt.js';
4
+
5
+ const runGET = (ctx: Partial<APIContext>): Response => {
6
+ const result = GET(ctx as APIContext);
7
+ if (!(result instanceof Response)) {
8
+ throw new Error('GET returned a non-Response value; robots-txt handler must be synchronous Response');
9
+ }
10
+ return result;
11
+ };
12
+
13
+ describe('robots-txt GET handler', () => {
14
+ afterEach(() => {
15
+ delete process.env.EASY_WEB_SEO_NO_INDEX;
16
+ });
17
+
18
+ it('returns public robots.txt with Sitemap when EASY_WEB_SEO_NO_INDEX is "false"', async () => {
19
+ process.env.EASY_WEB_SEO_NO_INDEX = 'false';
20
+ const response = runGET({ site: new URL('https://harleyrentflorida.de') });
21
+ const text = await response.text();
22
+
23
+ expect(response.status).toBe(200);
24
+ expect(response.headers.get('Content-Type')).toBe('text/plain; charset=utf-8');
25
+ expect(text).toContain('User-agent: *');
26
+ expect(text).toContain('Disallow: /admin/');
27
+ expect(text).toContain('Allow: /');
28
+ expect(text).toContain('Sitemap: https://harleyrentflorida.de/sitemap-index.xml');
29
+ expect(text).not.toMatch(/Disallow: \/\n/);
30
+ });
31
+
32
+ it('returns noIndex robots.txt (Disallow: /) without Sitemap when EASY_WEB_SEO_NO_INDEX is "true"', async () => {
33
+ process.env.EASY_WEB_SEO_NO_INDEX = 'true';
34
+ const response = runGET({ site: new URL('https://dev.ismaili.de') });
35
+ const text = await response.text();
36
+
37
+ expect(response.status).toBe(200);
38
+ expect(response.headers.get('Content-Type')).toBe('text/plain; charset=utf-8');
39
+ expect(text).toContain('User-agent: *');
40
+ expect(text).toMatch(/Disallow: \/\n/);
41
+ expect(text).not.toContain('Sitemap:');
42
+ expect(text).not.toContain('/admin/');
43
+ expect(text).not.toContain('Allow: /');
44
+ });
45
+
46
+ it('returns 500 fail-safe (Disallow: /, no Sitemap) when site is undefined', async () => {
47
+ const response = runGET({ site: undefined });
48
+ const text = await response.text();
49
+
50
+ expect(response.status).toBe(500);
51
+ expect(response.headers.get('Content-Type')).toBe('text/plain; charset=utf-8');
52
+ expect(text).toContain('User-agent: *');
53
+ expect(text).toContain('Disallow: /');
54
+ expect(text).not.toContain('Sitemap:');
55
+ });
56
+
57
+ it('treats missing EASY_WEB_SEO_NO_INDEX env var as public mode (Sitemap present)', async () => {
58
+ delete process.env.EASY_WEB_SEO_NO_INDEX;
59
+ const response = runGET({ site: new URL('https://example.com') });
60
+ const text = await response.text();
61
+
62
+ expect(response.status).toBe(200);
63
+ expect(text).toContain('Sitemap: https://example.com/sitemap-index.xml');
64
+ expect(text).toContain('Disallow: /admin/');
65
+ });
66
+ });