Skip to content

refactor: use import aliases in test files#2130

Merged
danielroe merged 4 commits intomainfrom
shuuji3/refactor/use-import-alias
Mar 18, 2026
Merged

refactor: use import aliases in test files#2130
danielroe merged 4 commits intomainfrom
shuuji3/refactor/use-import-alias

Conversation

@shuuji3
Copy link
Member

@shuuji3 shuuji3 commented Mar 18, 2026

🔗 Linked issue

N/A

🧭 Context

Currently, most test files uses the path traverse (../../../ ...) to import testing modules.

📚 Description

  • This PR replaces most of the path traverses with the shorter, readable import aliases such as ~ and #server etc.
  • Used the same conventional naming as Nuxt for the aliaes like ~~.

@vercel
Copy link

vercel bot commented Mar 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs.npmx.dev Ready Ready Preview, Comment Mar 18, 2026 4:56pm
npmx.dev Ready Ready Preview, Comment Mar 18, 2026 4:56pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
npmx-lunaria Ignored Ignored Mar 18, 2026 4:56pm

Request Review

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 60c237fe-087e-4baa-ae2c-7d6c5253d0b1

📥 Commits

Reviewing files that changed from the base of the PR and between 2a5d9d7 and cd9e05e.

📒 Files selected for processing (1)
  • vite.config.ts

📝 Walkthrough

Walkthrough

This PR updates import paths across the test suite to use TypeScript path aliases instead of relative file paths. New alias mappings are added to vite.config.ts for root-level modules (~~), whilst existing alias mappings for app (~), shared (#shared/), server (#server/), and CLI (~~/) modules are utilised throughout test files. Additionally, some .ts file extensions are removed from imports, relying on module resolution. No functional changes to test logic or assertions are introduced.

Possibly related PRs

  • PR #1105: Adds the lock.spec.ts test file that this PR updates with path alias imports
  • PR #2063: Refactors the cli/src/mock-state module that test imports reference in the updated import paths
  • PR #258: Introduces mock-connector helper modules that are being updated with path alias imports

Suggested reviewers

  • serhalp
🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The PR description clearly relates to the changeset, explaining that relative imports are being replaced with import aliases for improved readability.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch shuuji3/refactor/use-import-alias
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/unit/cli/server.spec.ts (1)

5-10: ⚠️ Potential issue | 🟠 Major

Mock target path is incorrect for the logger module.

On line 5, ~~/cli/logger resolves to <root>/cli/logger, but the logger is located at cli/src/logger.ts. The import in cli/src/server.ts uses from './logger.ts', which resolves to cli/src/logger.ts. This mismatch means the mock will not intercept the logger imports, and tests may run with the actual logger instead of the mock.

🔧 Proposed fix
-vi.mock('~~/cli/logger', () => {
+vi.mock('~~/cli/src/logger', () => {
   return {
     logError: () => {},
     logDebug: () => {},
   }
 })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7ab83e11-1559-41e2-8f3f-c0d54cd1b142

📥 Commits

Reviewing files that changed from the base of the PR and between da2cf3e and 48f95ad.

📒 Files selected for processing (58)
  • test/e2e/helpers/mock-connector-state.ts
  • test/e2e/helpers/mock-connector.ts
  • test/nuxt/components/HeaderConnectorModal.spec.ts
  • test/nuxt/composables/use-colors.spec.ts
  • test/nuxt/composables/use-preferences-provider.spec.ts
  • test/nuxt/composables/use-settings.spec.ts
  • test/unit/app/composables/use-charts.spec.ts
  • test/unit/app/composables/use-number-formatter.spec.ts
  • test/unit/app/router.options.spec.ts
  • test/unit/app/utils/chart-data-buckets.spec.ts
  • test/unit/app/utils/chart-data-prediction.spec.ts
  • test/unit/app/utils/charts.spec.ts
  • test/unit/app/utils/colors.spec.ts
  • test/unit/app/utils/date.spec.ts
  • test/unit/app/utils/download-anomalies.spec.ts
  • test/unit/app/utils/file-icons.spec.ts
  • test/unit/app/utils/formatters.spec.ts
  • test/unit/app/utils/frameworks.spec.ts
  • test/unit/app/utils/install-command.spec.ts
  • test/unit/app/utils/install-scripts.spec.ts
  • test/unit/app/utils/npm/common.spec.ts
  • test/unit/app/utils/package-name.spec.ts
  • test/unit/app/utils/platform-packages.spec.ts
  • test/unit/app/utils/publish-security.spec.ts
  • test/unit/app/utils/run-command.spec.ts
  • test/unit/app/utils/versions.spec.ts
  • test/unit/cli/npm-client.spec.ts
  • test/unit/cli/schemas.spec.ts
  • test/unit/cli/server.spec.ts
  • test/unit/config/env.spec.ts
  • test/unit/scripts/next-version.spec.ts
  • test/unit/search-case-normalization.spec.ts
  • test/unit/server/utils/atproto/lock.spec.ts
  • test/unit/server/utils/code-highlight.spec.ts
  • test/unit/server/utils/dependency-analysis.spec.ts
  • test/unit/server/utils/dependency-resolver.spec.ts
  • test/unit/server/utils/docs/format.spec.ts
  • test/unit/server/utils/docs/render.spec.ts
  • test/unit/server/utils/docs/text.spec.ts
  • test/unit/server/utils/error-handler.spec.ts
  • test/unit/server/utils/file-tree.spec.ts
  • test/unit/server/utils/gravatar.spec.ts
  • test/unit/server/utils/image-proxy.spec.ts
  • test/unit/server/utils/import-resolver.spec.ts
  • test/unit/server/utils/likes-evolution.spec.ts
  • test/unit/server/utils/provenance.spec.ts
  • test/unit/server/utils/readme-loaders.spec.ts
  • test/unit/server/utils/readme.spec.ts
  • test/unit/server/utils/shiki.spec.ts
  • test/unit/shared/types/index.spec.ts
  • test/unit/shared/utils/async.spec.ts
  • test/unit/shared/utils/binary-detection.spec.ts
  • test/unit/shared/utils/dev-dependency.spec.ts
  • test/unit/shared/utils/html.spec.ts
  • test/unit/shared/utils/package-analysis.spec.ts
  • test/unit/shared/utils/parse-package-param.spec.ts
  • test/unit/shared/utils/severity.spec.ts
  • vitest.config.ts

@danielroe danielroe enabled auto-merge March 18, 2026 16:55
@danielroe danielroe added this pull request to the merge queue Mar 18, 2026
Merged via the queue into main with commit e8b51b0 Mar 18, 2026
23 checks passed
@danielroe danielroe deleted the shuuji3/refactor/use-import-alias branch March 18, 2026 17:02
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