Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
The testing strategy for the CyberPath project is multifaceted, focusing on build-time checks, data integrity, and automated end-to-end visual verification rather than a conventional unit or integration test suite. The approach ensures code quality through static analysis, validates content structure via schema definitions, and uses a custom script to perform visual testing of key pages.
Contribution guidelines suggest that developers should write tests for their changes, although the repository does not include a dedicated testing framework like Jest or Vitest. Quality is further supported by in-browser debugging tools and error monitoring services.
Sources: package.json, CONTRIBUTING.md:12, scripts/screenshot.js, astro.config.ts
Build-Time Validation
The primary automated testing occurs during the project's build process. This is orchestrated by the build script defined in package.json.
Sources: package.json:7
Static Type Checking
The build process begins with astro check, which leverages TypeScript to perform static type checking across the entire codebase. This acts as a first line of defense against type-related errors and ensures code consistency.
"scripts": {
"build": "astro check && astro build && ...",
}
Sources: package.json:6-7
Data Schema Validation
The project uses zod to define a strict schema for the certifications content collection. During the build, Astro validates all Markdown frontmatter against this schema. This ensures that critical data like titles, acronyms, prices, and career paths conform to the expected structure and types, preventing data-related bugs.
The schema is defined in src/content.config.ts.
// src/content.config.ts
const certifications = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: "./src/content/certifications" }),
schema: ({image}) =>
z.object({
title: z.string(),
acronym: z.string(),
last_updated_at: z.date(),
image: image(),
reference: z.string(),
aliases: z.array(z.string()).optional(),
draft: z.boolean().default(false),
career_paths: z.array(z.enum(CareerPathsList)),
price: z.string(),
currency: z.string(),
}),
});
Sources: src/content.config.ts:6-21
Automated E2E Visual Testing
A significant part of the testing strategy is an automated end-to-end (E2E) script that captures a screenshot of the database page. This script, scripts/screenshot.js, uses Puppeteer to ensure the page renders correctly in a headless browser.
The script is executed as the final step of the build command.
*Sources: package.json:7, scripts/screenshot.js
Screenshot Script Workflow
The script performs several actions to simulate a user visiting the page and to capture a clean visual of the data table.
The following diagram illustrates the workflow of the screenshot script.
Sources: scripts/screenshot.js, package.json:7
Key Dependencies
This visual testing process relies on the following key devDependencies:
| Package | Purpose |
|---|---|
puppeteer | Drives a headless Chrome instance to navigate and screenshot the page. |
sharp | Optimizes and processes the captured screenshot image. |
Sources: package.json:33, package.json:35
Contribution Guidelines
The CONTRIBUTING.md file provides guidelines for contributors, which include a directive to write tests.
- Write Tests: If applicable, write tests for your changes to ensure they work as intended.
This indicates an expectation for contributors to validate their changes. However, the absence of a formal testing framework in the repository suggests that this may refer to manual testing or that contributors are expected to add tests if they introduce a new feature that requires them.
Sources: CONTRIBUTING.md:12-13
Debugging and Monitoring
The project integrates tools for debugging and error monitoring, which contribute to the overall quality assurance strategy.
| Tool | Purpose |
|---|---|
@sentry/astro | Integrated for error monitoring. It is enabled during development (import.meta.env.DEV). |
@spotlightjs/astro | An in-browser debugging tool, likely used during development to inspect components and state. |
These integrations are configured in astro.config.ts.
Sources: astro.config.ts:16-21, package.json:18-19
Summary
The testing strategy for CyberPath is pragmatic, prioritizing build-time correctness and visual integrity over traditional unit tests. It combines static analysis via TypeScript, data validation with Zod, and a unique E2E visual testing script using Puppeteer. While formal test suites are not present, the combination of these automated checks, along with developer-facing tools like Sentry and SpotlightJS, creates a robust quality assurance process.