Tests for server-side logic: sitemap generation helpers, RSS feed sanitizer, and the page renderer. Most of these functions are currently not exported and need to be made testable first.

Part of Add tests and CI integration (sub-task 3 of 4). Requires testing environment setup first. Can be done in parallel with utility tests.

Prerequisite: export helper functions

Before writing tests, these currently-private functions need to be exported (or extracted into separate testable modules):

  • sitemap-appendix.xml/+server.js:getRouteFromPath , calculatePriority,extractSections
  • feed.xml/+server.js: sanitizeContentForRSS
  • page-renderer.svelte.js: getCoverUrl, createSvelteKitStateMocks, createRenderContext

Sitemap helpers

From src/routes/sitemap-appendix.xml/+server.js:

getRouteFromPath(filePath)

  • Strips +page.svelte and .. prefix
  • Prepends base path

calculatePriority(path)

  • / (root) returns "0.9"
  • Each nesting level reduces by 0.1
  • Minimum priority is "0.1" (deeply nested paths don't go below)
  • Returns string with one decimal place

extractSections(pagePaths)

  • Extracts parent sections from page paths
  • Returns sorted, deduplicated array
  • Each section has trailing slash
  • Handles deeply nested paths (creates all intermediate sections)

Feed sanitizer

From src/routes/feed.xml/+server.js:

sanitizeContentForRSS(html)

  • Removes onload, onerror and other event handler attributes
  • Removes single-quoted event handlers
  • Removes style attributes (both quote types)
  • Removes javascript: URLs
  • Removes data-* attributes
  • Removes class attributes
  • Removes id attributes
  • Preserves actual content text and tag structure
  • Test with HTML containing all pattern types combined

Page renderer

From src/lib/page-renderer.svelte.js:

getCoverUrl(cover)

  • Returns empty string for null/undefined/falsy
  • Returns the string directly if cover is a string
  • Extracts img.src from object form
  • Returns empty string if object has no img.src

createSvelteKitStateMocks(filePath, pageData)

  • Returns object with url, params, route, data, form, error, status
  • url is a valid URL object based on filePath
  • data.info merges defaults with provided pageData
  • Default date is '01-01-2024'

createRenderContext

  • Returns a Map
  • Has 'meta' key with a Store instance
  • Has '__request__' key with page mock

Date formatting in renderBlogPage

  • DD-MM-YYYY converts to YYYY-MM-DDT00:00:00-00:00
  • Fallback to 01-01-2024 when no date provided

EXCLUDE_PATHS filtering

  • Pages matching excluded paths return null
  • Pages not in the set are rendered normally

Endpoint tests

Server logic correctness

A static site template built with SvelteKit.

Sveleton, 2025