Skip to content

chore: setup test environment#82

Open
kishandev2509 wants to merge 4 commits into
mdsaban:mainfrom
kishandev2509:tests
Open

chore: setup test environment#82
kishandev2509 wants to merge 4 commits into
mdsaban:mainfrom
kishandev2509:tests

Conversation

@kishandev2509

@kishandev2509 kishandev2509 commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Title: Add Husky Pre-Commit Hook to Run Vitest Tests

Description:
This PR adds a pre-commit hook to ensure that all tests are run before code is committed, preventing accidental breaking changes. The setup uses Vitest for testing and Husky for Git hooks, with pnpm as the package manager.

Changes Included:

  1. Vitest test script:

    • Added "test": "vitest run" to package.json so pnpm test runs all tests.
  2. Husky pre-commit hook:

    • Configured Husky to run pnpm test before every commit.
    • Commits will fail if any test fails, enforcing code quality.
  3. Documentation updates:

    • Added instructions in CONTRIBUTING.md on creating tests.

Benefits:

  • Prevents accidental breaking changes from being committed.
  • Encourages developers to run tests before committing.
  • Improves overall repository stability and contributor confidence.

Testing:

  • Verified that pnpm test runs all Vitest test cases successfully.
  • Verified that the Husky pre-commit hook blocks commits if tests fail.

Closes #81

Summary by CodeRabbit

  • New Features

    • Integrated project-level testing workflow and configured pre-commit to run tests before linting.
  • Tests

    • Added comprehensive test suite covering deep-link generation across 17+ social platforms.
  • Documentation

    • Updated contributor guide with testing examples and guidance.
  • Chores

    • Added a top-level test run task and a project test script to enable unified test execution.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Adds a repository-wide Vitest-based testing workflow: new test scripts, a Turbo "test" task, Husky pre-commit updated to run tests before linting, TypeScript excludes for tests, and a comprehensive generateDeepLink test suite with supporting test types and contributor docs updates.

Changes

Cohort / File(s) Summary
Pre-commit & root scripts
./.husky/pre-commit, ./package.json, ./turbo.json
Pre-commit hook changed to run pnpm test && pnpm exec lint-staged; root package.json adds "test": "turbo run test" and Vitest devDependency; Turbo gains a top-level test task.
Core package tests & scripts
packages/core/package.json, packages/core/src/tests/*, packages/core/src/tests/types.ts
packages/core adds "test": "vitest run" and Vitest devDependency; new Vitest test suite index.test.ts for generateDeepLink and test type definitions.
TypeScript config
tsconfig.json, packages/core/tsconfig.json
Updated exclude arrays to skip test files (src/tests/**/*, **/*.test.ts).
Docs & public API export change
packages/core/CONTRIBUTING.md
Moved public handlers export to packages/core/src/platforms/index.ts and updated contributor guide with a tests section and example test case.

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Developer (git commit)
  participant Husky as Husky pre-commit
  participant PNPM as pnpm
  participant Turbo as Turbo
  participant Vitest as Vitest
  participant Lint as lint-staged

  rect rgb(230,245,255)
    Dev->>Husky: git commit
    Husky->>PNPM: run `pnpm test` (pre-commit)
    PNPM->>Turbo: `turbo run test`
    Turbo->>Vitest: invoke package tests
    Vitest-->>Turbo: test result (pass/fail)
    Turbo-->>PNPM: exit code
  end

  alt tests pass
    PNPM->>Husky: success
    Husky->>PNPM: run `pnpm exec lint-staged`
    PNPM->>Lint: lint-staged checks
    Lint-->>PNPM: lint result
    PNPM-->>Husky: success
    Husky-->>Dev: allow commit
  else tests fail
    PNPM-->>Husky: failure
    Husky-->>Dev: block commit (tests failed)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰

I hopped through hooks and scripts anew,
Ran tests before the linting crew —
A burrow full of checks and cheer,
Safe commits hop ever near! 🧪✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes changes beyond the core requirements from issue #81, such as moving handler exports to platforms/index.ts and updating CONTRIBUTING.md with test examples, which are not directly specified in the acceptance criteria. Consider separating the handler refactoring and documentation updates into a separate PR, keeping this PR focused solely on test environment setup as specified in issue #81.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: setup test environment' directly relates to the main objective of setting up testing infrastructure with Vitest and Husky hooks.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #81: Vitest is integrated with pnpm test script, Husky pre-commit hook runs tests before commits, and test files with comprehensive coverage are added.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @packages/core/package.json:
- Line 23: Add vitest to this package's devDependencies in
packages/core/package.json so the "test": "vitest run" script has an explicit
local dependency; use the same version range as the root workspace (or a
compatible one), add an entry "vitest": "<version>" under devDependencies, then
run your package manager install (npm/yarn/pnpm) to update node_modules and
lockfile.
🧹 Nitpick comments (3)
turbo.json (1)

16-18: Consider disabling cache for the test task.

By default, Turbo will cache test results based on input hashes. This means if source files haven't changed, tests won't re-run. While this improves performance, it might hide test failures caused by external factors (environment, timing, etc.). Consider adding "cache": false if tests should always run, or carefully configure cache inputs.

⚙️ Proposed configuration to disable caching
     "test": {
+      "cache": false,
       "outputs": []
     }

Or, if you want to keep caching but ensure it's based on the right inputs:

     "test": {
+      "dependsOn": ["^build"],
       "outputs": []
     }
.husky/pre-commit (1)

1-1: Consider adding tests to the CI pipeline and monitoring performance as test coverage grows.

Currently, the project has minimal test coverage (one test file), so pre-commit performance impact is negligible. However, as the project matures, running the full test suite on every commit may slow the workflow. More importantly, tests should run in CI alongside the existing checks in pr-checks.yml, rather than only at pre-commit. Once tests are integrated into the CI pipeline, you can either:

  • Remove tests from pre-commit and rely on CI validation
  • Keep pre-commit tests lightweight (e.g., affected tests only)
  • Monitor commit times as test coverage grows and adjust as needed
packages/core/src/tests/index.test.ts (1)

202-204: Nice use of dynamic test generation!

Using Object.entries() to iterate over test cases is an elegant approach that automatically generates test suites for all platforms. This makes it easy to add new platforms—just add to the testCases object.

Consider adding edge case tests in future iterations, such as:

  • Invalid URLs for each platform
  • Malformed URLs
  • URLs with special characters or encoding
  • Missing path segments

This would strengthen the test coverage beyond happy paths.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3670c1c and 413169d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • .husky/pre-commit
  • package.json
  • packages/core/CONTRIBUTING.md
  • packages/core/package.json
  • packages/core/src/tests/index.test.ts
  • packages/core/src/tests/types.ts
  • packages/core/tsconfig.json
  • tsconfig.json
  • turbo.json
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-01-02T21:27:30.363Z
Learnt from: tanmoyPaul12
Repo: mdsaban/universal-app-opener PR: 0
File: :0-0
Timestamp: 2026-01-02T21:27:30.363Z
Learning: In the mdsaban/universal-app-opener repository, the Platform type in packages/core/src/types.ts already includes 'github' and 'twitch' platforms in the main branch.

Applied to files:

  • packages/core/src/tests/types.ts
🧬 Code graph analysis (1)
packages/core/src/tests/types.ts (1)
packages/core/src/types.ts (1)
  • Platform (1-18)
🔇 Additional comments (8)
tsconfig.json (1)

15-15: LGTM!

The test file exclusion patterns are appropriate and follow standard practices for separating test files from production compilation.

package.json (2)

11-11: LGTM!

The test script correctly delegates to Turbo's task runner, enabling coordinated test execution across the monorepo.


23-23: No action required. Vitest 4.0.16 is a valid release (published December 16, 2025) with no known security vulnerabilities. The critical CVE-2025-24964 affects only vitest ≤3.0.4 and does not impact this version.

packages/core/CONTRIBUTING.md (1)

89-107: Excellent addition to the contributor guide!

The test documentation is clear and provides a concrete example that matches the actual test structure in packages/core/src/tests/index.test.ts. This will help contributors understand how to add test coverage for new platform handlers.

packages/core/tsconfig.json (1)

12-12: LGTM! Proper test exclusion.

Excluding test files from the TypeScript compilation output is the correct approach for production builds.

packages/core/src/tests/types.ts (1)

1-11: Well-designed test types!

The type definitions provide strong typing for the test suite:

  • PlatformLink correctly uses string | null for iOS and Android deep links, accommodating platforms that may not have native app support.
  • SocialLinks as Record<Platform, PlatformLink[]> ensures compile-time verification that all platforms have test coverage.
packages/core/src/tests/index.test.ts (2)

5-18: Clean test helper implementation!

The generateDeepLinkTest helper function follows the DRY principle and provides good structure for generating platform-specific test suites. The assertions cover all critical fields (platform, webUrl, ios, android).


20-200: Comprehensive platform coverage!

The test suite covers all 16 named platforms (discord, facebook, github, instagram, linkedin, pinterest, reddit, snapchat, spotify, substack, telegram, threads, twitch, whatsapp, youtube, zoom) plus the unknown case for a total of 17 platforms. The test data is well-organized and thorough with proper deep link handling across all platforms.

All tested platforms have corresponding handler implementations that are properly exported from packages/core/src/platforms/index.ts, ensuring complete alignment between test coverage and actual handler implementations.

Comment thread packages/core/package.json
Comment thread packages/core/src/tests/index.test.ts
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.

Create Test Environment

2 participants