Skip to content

Conversation

aaronbrethorst
Copy link
Member

No description provided.

- Set up complete testing framework with Vitest, @testing-library/svelte, and MSW
- Create test utilities and fixtures for OneBusAway API data
- Implement map provider mocks for both Leaflet and Google Maps
- Add 228 passing component tests covering navigation, stops, routes, search, and trip-planner
- Configure MSW handlers for realistic API response testing
- Add test setup for Svelte 5 runes compatibility
- Create comprehensive test fixtures with realistic transit data
- Fix all ESLint errors and ensure code quality standards
- Enhanced AlertsModal.test.js with proper Svelte 5 support and mocking
- Updated MobileMenu.test.js for better test reliability
- Improved ModalPane.test.js with comprehensive test coverage
- Fixed component implementations to support improved testing
- Enhanced RouteModal.test.js with better Svelte 5 compatibility
- Improved ViewAllRoutesModal.test.js with comprehensive test coverage
- Updated mocking strategies for better test reliability
- Enhanced SearchField.test.js with proper Svelte 5 support
- Improved SearchPane.test.js with comprehensive test coverage
- Updated SearchResultItem.test.js for better reliability
- Fixed unhandled promise rejection in SearchPane.svelte by adding try-catch error handling
- Updated component implementations to support improved testing
- Enhanced StopItem.test.js with better test coverage
- Improved StopModal.test.js with comprehensive Svelte 5 support
- Updated StopPageHeader.test.js for better reliability
- Enhanced StopPane.test.js with proper mocking and test structure
- Enhanced TripPlanSearchField.test.js with proper Svelte 5 support
- Updated component implementation for better testability
- Improved mocking strategies for reliable test execution
- Enhanced keybinding.test.js with comprehensive test coverage
- Updated keybinding.js implementation for better testability
- Improved utility functions with proper error handling
- Enhanced vitest-setup.js with improved global test configuration
- Added better mock setup for comprehensive test coverage
- Improved test environment configuration for Svelte 5 support
@aaronbrethorst aaronbrethorst requested a review from Copilot July 5, 2025 05:32
@coveralls
Copy link

coveralls commented Jul 5, 2025

Coverage Status

coverage: 74.359% (+58.3%) from 16.097%
when pulling 111fef7 on tests
into d4b0cd3 on main.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive testing infrastructure and component tests for the Svelte application.

  • Introduces a global Vitest setup (vitest-setup.js) with mocks for browser APIs, SvelteKit stores, environment variables, and i18n.
  • Updates vite.config.js to include the Svelte testing plugin, configure coverage reporters, thresholds, and setup files.
  • Adds MSW server setup, mock providers, shared test utilities, fixtures, and dozens of new component tests.

Reviewed Changes

Copilot reviewed 32 out of 33 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vitest-setup.js Adds global mocks for browser APIs, env vars, i18n
vite.config.js Includes @testing-library/svelte plugin and coverage config
src/tests/setup/msw-server.js Configures MSW server lifecycle for tests
src/tests/mocks/mapProviders.js Provides mock implementations for map providers
src/tests/helpers/test-utils.js Shared render and store mock utilities
src/components/search/SearchField.svelte Trim and validate search input with error handling
src/components/search/SearchPane.svelte Wraps route fetch in try/catch
src/lib/keybinding.js Refactors keybinding action to support updates
Comments suppressed due to low confidence (3)

src/components/search/SearchField.svelte:13

  • Add a check for response.ok before parsing JSON. If the response is not OK, handle or forward the error (e.g., call handleSearchResults({ error: ... })) instead of always calling response.json().
	async function handleSearch() {

src/tests/mocks/handlers.js:65

  • [nitpick] Using Date.now() directly in handlers leads to non-deterministic test data. Consider using a fixed timestamp or mocking Date.now() with vi.useFakeTimers() for stable and reproducible tests.
							serviceDate: Date.now(),

src/lib/keybinding.js:15

  • Ensure that setHandler() is invoked on mount (without arguments) so the initial keydown listener is registered. If omitted, the action will never listen for key events until an update occurs.
	const setHandler = (newParams) => {

polyline = mapProvider.createPolyline(shape);
polylines.push(polyline);
try {
const response = await fetch(`/api/oba/stops-for-route/${route.id}`);
Copy link
Preview

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add if (!response.ok) handling after this fetch to avoid unhandled JSON parsing errors. Consider notifying the user or falling back gracefully instead of only logging to console.

Suggested change
const response = await fetch(`/api/oba/stops-for-route/${route.id}`);
const response = await fetch(`/api/oba/stops-for-route/${route.id}`);
if (!response.ok) {
throw new Error(`Failed to fetch route data: ${response.status} ${response.statusText}`);
}

Copilot uses AI. Check for mistakes.

}));

// Mock environment variables
vi.mock('$env/static/public', () => ({
Copy link
Preview

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Tests import $env/dynamic/public in some modules. Consider adding a mock for $env/dynamic/public here to ensure consistent environment variable behavior across tests.

Copilot uses AI. Check for mistakes.

- Remove unused imports and variables
- Fix ESLint no-unused-vars warnings
- Apply Prettier formatting fixes
- Update caniuse-lite to latest version
- Resolves outdated browser data warning
@aaronbrethorst aaronbrethorst merged commit 8b3f045 into main Jul 5, 2025
3 checks passed
@aaronbrethorst aaronbrethorst deleted the tests branch July 5, 2025 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants