Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Vitestの紹介
Search
Yohei Iino
February 19, 2023
Programming
200
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Vitestの紹介
Vitestの紹介
Yohei Iino
February 19, 2023
More Decks by Yohei Iino
See All by Yohei Iino
1年半放置したExpo製アプリを最新化してみた
wheatandcat
0
100
作成中のFlutterアプリの中間発表
wheatandcat
0
83
最近読んだ技術書を簡単紹介
wheatandcat
0
110
ユニバーサルリンク/アプリリンクを使ってQRコードでゲストログインできるようにする
wheatandcat
0
380
Firebase App Checkを実装したので紹介
wheatandcat
0
310
PlanetScaleの無料プランがなくなるので、NeonとTiDBを試してみた
wheatandcat
0
410
Flutter HooksとRiverpodの解説
wheatandcat
0
580
T3 Stack(応用編: Next Auth & SSRの実装紹介)
wheatandcat
1
400
App Routerの紹介
wheatandcat
0
150
Other Decks in Programming
See All in Programming
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
13
6.3k
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
220
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
400
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
270
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
130
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
320
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
970
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
15
7.2k
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
560
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.8k
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
170
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
810
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
170
Crafting Experiences
bethany
1
190
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
170
Writing Fast Ruby
sferik
630
63k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
590
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Statistics for Hackers
jakevdp
799
230k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.8k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Transcript
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 移行が進んでいるので、合わせてテストフレームワークも移行を検討すると良い かなと思います。
ご清聴ありがとうございました