Skip to content

テスト用のヘルパー関数を追加する #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 15, 2025

Conversation

XeicuLy
Copy link
Owner

@XeicuLy XeicuLy commented Mar 15, 2025

close #31

Summary by CodeRabbit

  • 新機能
    • テスト環境向けに、状態管理ストアの初期状態を簡単に設定できるユーティリティを追加しました。
    • 非同期コンポーネントのマウントをサポートするテストツールを導入し、効率的な検証と開発体験の向上を実現しました。

@XeicuLy XeicuLy self-assigned this Mar 15, 2025
Copy link

coderabbitai bot commented Mar 15, 2025

"""

Walkthrough

新たにテスト用のヘルパー関数が2点追加されました。
bindTestingPinia は Pinia のテストインスタンスを生成し、オプションで初期状態を受け付けます。
また、mountSuspendedComponent は非同期コンポーネントのマウントに対応し、Nuxt のテストユーティリティを利用します。
これらの関数は、src/helpers/test/index.ts で再エクスポートされています。

Changes

ファイル 変更概要
src/helpers/test/bindTestingPinia.ts Pinia のテストインスタンス生成用関数 bindTestingPinia を追加(初期状態のオプション対応)
src/helpers/test/mountSuspendedComponent.ts 非同期コンポーネントのマウントを行う mountSuspendedComponent 関数を追加(Nuxt、Pinia 対応の設定あり)
src/helpers/test/index.ts 上記2関数(bindTestingPiniamountSuspendedComponent)の再エクスポートを追加

Sequence Diagram(s)

sequenceDiagram
    participant T as テスター
    participant B as bindTestingPinia
    participant P as createTestingPinia (@pinia/testing)

    T->>B: bindTestingPinia(initialState) を呼び出す
    B->>P: createTestingPinia({stubActions: false, ...initialState})
    P-->>B: TestingPinia インスタンスを返す
    B-->>T: TestingPinia インスタンスを返す
Loading
sequenceDiagram
    participant T as テスター
    participant M as mountSuspendedComponent
    participant N as mountSuspended (Nuxt Test Utility)

    T->>M: mountSuspendedComponent(component, testingPinia, options) を呼び出す
    M->>N: mountSuspended(mergedOptions, component) を呼び出す
    N-->>M: VueWrapper を返す
    M-->>T: VueWrapper を返す
Loading

Possibly related PRs

  • Vitestの設定 #19: bindTestingPinia 関数の導入により、mountSuspendedComponent 関数との関連が強い。

Poem

ぴょんぴょんと跳ねる僕から
新しい関数に胸が高鳴るよ
Pinia と共にテストの舞台へ
非同期の風を感じながら
コードの森で夢広がる 🐰🌟
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/helpers/test/mountSuspendedComponent.ts

Oops! Something went wrong! :(

ESLint: 9.22.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/compat' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot added the 開発環境 開発環境の構築に関連する label Mar 15, 2025
Copy link

@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.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between d54ee87 and 4a91878.

📒 Files selected for processing (1)
  • src/helpers/test/mountSuspendedComponent.ts (1 hunks)
🔇 Additional comments (4)
src/helpers/test/mountSuspendedComponent.ts (4)

1-3: インポート構成は問題ありません。
主に@nuxt/test-utils/runtime@vue/test-utilsの組み合わせが適切で、PiniaとVueの型を正しく参照できています。


32-67: ドキュメントコメントが丁寧で分かりやすいです。
パラメータの説明やサンプルコードも充実しており、利用者が迷わずに使える構成になっています。


68-70: ジェネリクスを用いてコンポーネント側の型安全性を高めている点が良いです。
<VMValue>を明示的に指定することで、vm 経由でコンポーネント内部に型付きでアクセスできるのは便利です。


21-30:

✅ Verification successful

TypeScript 4.9 以降で導入された satisfies 演算子の利用を確認してください。
as const satisfies MountOptions は非常に有用ですが、プロジェクトで使用しているTypeScriptのバージョンが 4.9 未満の場合はビルドが通らない可能性があります。


🌐 Web query:

Which TypeScript version introduced the 'satisfies' operator?

💡 Result:

The satisfies operator was introduced in TypeScript 4.9, released in November 2022[1][4][8]. This operator allows developers to validate that an expression's type matches a specified type without altering the inferred type of the expression, enabling both type safety and preserved type narrowing[1][4][6].

Key features of the satisfies operator:

  • Pre-validation: Checks type compatibility before runtime[1][3]
  • Type narrowing: Maintains specific inferred types (e.g., preserving literal values instead of widening to string)[6][11]
  • Error detection: Catches typos and type mismatches during development[4][8]

Example usage:

type RGB = [number, number, number];
const palette = {
    red: [255, 0, 0],
    green: "#00ff00",
    blue: [0, 0, 255]
} satisfies Record<string, RGB | string>;

// TypeScript knows palette.green is a string
const greenUpper = palette.green.toUpperCase();  // Valid[5][9]

This operator solves common TypeScript dilemmas where developers previously had to choose between type safety and precise type inference[4][6][11].

Citations:


TypeScript 4.9 以降のバージョン確認のお願い

src/helpers/test/mountSuspendedComponent.ts の該当コード

const DEFAULT_OPTIONS = {
  testingPinia: undefined,
  attachTo: undefined,
  props: {},
  slots: {},
  shallow: false,
  stubs: DEFAULT_STUBS,
  mocks: {},
  options: {},
} as const satisfies MountOptions;

は、satisfies 演算子を活用しているため、型チェックとリテラル型の厳密な取り扱いが実現されています。ただし、この構文は TypeScript 4.9 以降で導入されたため、プロジェクト全体で使用している TypeScript のバージョンが 4.9 以上であることを必ずご確認ください。もしビルドエラー等が発生する場合は、TypeScript のバージョンが古い可能性があるので、tsconfig.json や依存関係の設定を見直してください。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
開発環境 開発環境の構築に関連する
Projects
None yet
Development

Successfully merging this pull request may close these issues.

テスト用ヘルパー関数を用意する
1 participant