Testing with Vitest
Relevant source files
The following files were used as context for generating this wiki page:
Testing in the Messenger Unleashed project is powered by Vitest, a Vite-native testing framework. The project utilizes Vitest for unit testing core utility logic, ensuring the reliability of critical functions such as URL filtering, GraphQL body parsing, and quiet hours calculations. While the project primarily relies on manual passes for UI and Electron feature verification, the Vitest suite provides a rigorous automated foundation for non-UI logic.
Sources: package.json:28-30, vitest.config.ts:3-15, AGENTS.md:27-32
Test Configuration
The testing environment is configured via vitest.config.ts. It is set up to run in a Node.js environment and specifically targets files matching the src/**/*.test.ts pattern.
Coverage and Environment
The configuration includes integrated code coverage using the v8 provider. It is configured to report results in both text and html formats. The coverage scope includes all TypeScript files within the src directory while explicitly excluding test files to ensure accurate metrics.
The diagram shows the structural configuration of the Vitest testing runner as defined in the project root.
Sources: vitest.config.ts:3-15
Test Execution Commands
The project defines several scripts in package.json for managing the test lifecycle using the Bun runtime.
| Command | Action | Description |
|---|---|---|
bun run test | vitest run | Runs the test suite once. |
bun run test:watch | vitest | Starts Vitest in watch mode for development. |
bun run test:coverage | vitest run --coverage | Runs tests and generates a code coverage report. |
bun run check | ... && bun run test | Validates the project by running linting, typechecking, and tests. |
Sources: package.json:17-21
Unit Testing Areas
Automated tests are concentrated in src/main/utils.test.ts, focusing on pure utility functions that drive the application's core logic.
1. URL Authorization (shouldAllowUrl)
Tests ensure that the application only opens trusted domains (messenger.com, facebook.com) or internal protocols (about:blank, blob:, data:). It validates that external or malicious URLs are denied.
2. GraphQL Parsing (parseGraphqlBody)
This suite validates the logic used to intercept and interpret Messenger's network traffic. It tests both URL-encoded and JSON body formats to extract friendlyName, docId, and variables.
3. Presence and Quiet Hours (isWithinQuietHours)
Tests cover time-based logic, specifically ensuring that Quiet Hours correctly handle same-day ranges and overnight ranges (e.g., 10 PM to 7 AM).
This diagram illustrates the relationship between the test suites and the functional utility logic they validate.
Sources: src/main/utils.test.ts:1-135, src/main/utils.ts:5-84
Implementation Example: Utility Tests
The project uses standard describe, it, and expect syntax. Below is an illustration of how quiet hours logic is validated:
describe("isWithinQuietHours", () => {
it("handles overnight range (e.g., 22:00 - 07:00)", () => {
const at11pm = new Date("2024-01-01T23:00:00");
const at10am = new Date("2024-01-01T10:00:00");
expect(isWithinQuietHours("22:00", "07:00", at11pm)).toBe(true);
expect(isWithinQuietHours("22:00", "07:00", at10am)).toBe(false);
});
});
Sources: src/main/utils.test.ts:111-122
Summary
Vitest serves as the automated gatekeeper for the core logical components of Messenger Unleashed. By focusing on pure utility functions in src/main/utils.ts, the test suite ensures that critical features like privacy-based URL filtering and scheduling logic remain stable across builds. Developers are encouraged to run bun run test or bun run check before submitting pull requests to maintain code quality.
Sources: AGENTS.md:27-32, package.json:21