スキル一覧に戻る
knoopx

vitest

by knoopx

pi.ai config

2🍴 0📅 2026年1月21日
GitHubで見るManusで実行

SKILL.md


name: vitest description: Manage JavaScript/TypeScript testing projects with Vitest (test execution, configuration, mocking, coverage, and debugging). Use when running tests, configuring environments, generating coverage, or debugging tests.

Installation

Install Vitest as a dev dependency:

bun add -D vitest

Requirements: Vite >=v6.0.0 and Node >=v20.0.0

Writing Tests

Tests must contain .test. or .spec. in their file name.

Example:

sum.js

export function sum(a, b) {
  return a + b;
}

sum.test.js

import { expect, test } from "vitest";
import { sum } from "./sum.js";

test("adds 1 + 2 to equal 3", () => {
  expect(sum(1, 2)).toBe(3);
});

Add to package.json scripts:

{
  "scripts": {
    "test": "vitest",
    "test:run": "vitest run",
    "coverage": "vitest run --coverage"
  }
}

Run tests with bun run test, etc.

Configuration

Vitest shares config with Vite. Use vitest.config.ts or add test property to vite.config.ts.

Example vitest.config.ts:

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    environment: "node", // or 'jsdom', 'happy-dom'
    globals: true, // use global test functions
    setupFiles: ["./setup.ts"],
  },
});

For Vite users, add to vite.config.ts:

/// <reference types="vitest/config" />
import { defineConfig } from "vite";

export default defineConfig({
  // ... other config
  test: {
    // test options
  },
});

Command Line Interface

  • bun run vitest: tmux new -d 'bun run vitest' (run tests in watch mode)
  • bun run vitest run: Run tests once
  • bun run vitest run --coverage: Run with coverage
  • bun run vitest --config <file>: Specify config file
  • bun run vitest --help: Show all options

Mocking

Use vi.mock() to mock modules:

import { vi } from "vitest";

vi.mock("./module.js", () => ({
  functionName: vi.fn(),
}));

Coverage

Enable coverage with --coverage flag or config:

export default defineConfig({
  test: {
    coverage: {
      reporter: ["text", "json", "html"],
    },
  },
});

Debugging

Use --inspect or --inspect-brk for Node.js debugging.

In VS Code, add launch config for debugging tests.

Projects Support

Define multiple projects in config for different environments or setups.

export default defineConfig({
  test: {
    projects: [
      "packages/*",
      {
        test: {
          name: "e2e",
          environment: "jsdom",
        },
      },
    ],
  },
});
  • bun: Use Bun as the runtime for running tests with Vitest, or manage dependencies in testing projects.
  • typescript: Ensure type safety in your tests by following TypeScript best practices when writing test code with Vitest.
  • lsp: Query language server for definitions, references, types, symbols, diagnostics, rename, and code actions.

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です