Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Vitestの紹介
Search
Yohei Iino
February 19, 2023
Programming
220
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Vitestの紹介
Vitestの紹介
Yohei Iino
February 19, 2023
Transcript
13 slides
Vitest の紹介 Press Space for next page
自己紹介 📝 飯野陽平(wheatandcat ) 🏢 フリーランスエンジニア(シェアフル株式会社CTO ) 💻 Blog: https://www.wheatandcat.me/
🛠 今までに作ったもの memoir ペペロミア Atomic Design Check List
Vitest とは Vitest はVite 環境で動作する高速なテストフレームワーク 領域的にはJest と同じ 特徴は実行速度の速さ。以下、参考記事 Vitest はどれくらい早いのか
~ Jest と比較 ~ 特にwatch モードが高速 その他にも細かいチューニングがされている
Vitest を導入してみる① 導入は以下を参照。 Getting Started | Guide | Vitest
Vitest を導入してみる② コードは以下みたいな感じで書ける。 import { describe, it, expect } from
'vitest' import { add } from "./calc" describe('suite', () => { it('concurrent test 1', async () => { const r = add(1, 2); expect(r).toEqual(3) }) })
Vitest を導入してみる③ コンポーネントのテストなら以下みたいな感じ。 import { describe, expect, it } from
"vitest"; import { render, screen } from "@testing-library/react"; import Demo from "./Demo"; describe("Demo", () => { it(" タイトルに、「デモ」が表示さてている", () => { const props = { title: " デモ" }; render(<Demo {...props} />); expect(screen.getByText(/ デモ/i)).toBeTruthy(); }); });
Vitest を導入してみる④ テストの実行以下のコマンドでOK 👌。 デフォルトでwatch モードで起動。 $ vitest $ vitest
DEV v0.27.1 ./demo ✓ src/lib/calc.ts (2) ✓ src/components/organisms/Demo.test.tsx (1) Test Files 2 passed (2) Tests 2 passed (2) Start at 23:12:20 Duration 3.25s (transform 1.06s, setup 712ms, collect 725ms, tests 70ms)
カバレッジ/Mocking/Testing Type 以下のあたりはJest とほぼ同様に使用できる。 Coverage Mocking Testing Types
Vitest UI Vitest にUI からテスト実行/ 確認行える機能がある。 Vitest UI 以下のコマンドで実行。 ※
デモで説明。 $ vitest --ui
In-source testing 好みは別れるが、Rust みたいにコード上にテストコードを書くこともできる。 In-source testing | Guide | Vitest
// the implementation export function add(...args: number[]) { return args.reduce((a, b) => a + b, 0) } // in-source test suites if (import.meta.vitest) { const { it, expect } = import.meta.vitest it('add', () => { expect(add()).toBe(0) expect(add(1)).toBe(1) expect(add(1, 2, 3)).toBe(6) }) }
Debugging テストコードでデバッガも使用できる。 Debugging | Guide | Vitest ※ デモで説明。
まとめ Jest 互換なので、移行も比較的に容易に行えるのでおすすめ。 機能もかなり充実しているのでプロダクトで使っても、問題なさ気。 現状だとWebpack →Vite 移行が進んでいるので、合わせてテストフレームワークも移行を検討すると良い かなと思います。
ご清聴ありがとうございました
More Decks by Yohei Iino
See All by Yohei Iino
1年半放置したExpo製アプリを最新化してみた
wheatandcat
0
130
作成中のFlutterアプリの中間発表
wheatandcat
0
100
最近読んだ技術書を簡単紹介
wheatandcat
0
130
ユニバーサルリンク/アプリリンクを使ってQRコードでゲストログインできるようにする
wheatandcat
0
410
Firebase App Checkを実装したので紹介
wheatandcat
0
400
PlanetScaleの無料プランがなくなるので、NeonとTiDBを試してみた
wheatandcat
0
450
Flutter HooksとRiverpodの解説
wheatandcat
0
620
T3 Stack(応用編: Next Auth & SSRの実装紹介)
wheatandcat
1
430
App Routerの紹介
wheatandcat
0
180
Other Decks in Programming
See All in Programming
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
660
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
630
Getting Started with Vibe Coding
miccheng
0
250
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
700
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
180
Kotlin Fest 2026: Kotlin コンパイラに Contribute してみよう! - Kotlin/Wasm で深い再帰を書けるようにした話
ternbusty
1
420
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
110
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
110
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
Proxmox x Talos Linux x Terraform で実現するなんかいい感じの Kubernetes クラスタ / A Sleek Kubernetes Cluster Powered by Proxmox, Talos Linux, and Terraform
nnaka2992
0
300
Spec-driven Development with AI
simas
PRO
0
2.3k
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
260
Featured
See All Featured
Building the Perfect Custom Keyboard
takai
2
970
Heart Work Chapter 1 - Part 1
lfama
PRO
11
37k
How STYLIGHT went responsive
nonsquared
100
6.4k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
A better future with KSS
kneath
240
18k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
500
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
570
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3.1k
Technical Leadership for Architectural Decision Making
baasie
4
660
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
630