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
210
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
110
作成中のFlutterアプリの中間発表
wheatandcat
0
93
最近読んだ技術書を簡単紹介
wheatandcat
0
120
ユニバーサルリンク/アプリリンクを使ってQRコードでゲストログインできるようにする
wheatandcat
0
390
Firebase App Checkを実装したので紹介
wheatandcat
0
330
PlanetScaleの無料プランがなくなるので、NeonとTiDBを試してみた
wheatandcat
0
430
Flutter HooksとRiverpodの解説
wheatandcat
0
590
T3 Stack(応用編: Next Auth & SSRの実装紹介)
wheatandcat
1
410
App Routerの紹介
wheatandcat
0
160
Other Decks in Programming
See All in Programming
Webエンジニアなのにブラウザの仕組みがわからないので、Pythonで自作してみた
tatsuki12
3
750
楽しそうなつよつよエンジニアと目が死んでる僕/A brilliant engineer having a blast, and dead-eyed me.
3l4l5
2
200
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
350
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
210
書籍「プロフェッショナルAI駆動開発」紹介スライド
juntaromatsumoto
0
210
AIが無かった頃の素敵な出会いの話
codmoninc
1
480
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
350
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
340
Building a Meta Ray-Ban display app
akkeylab
0
170
Android CLI
fornewid
0
230
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
2
160
FastAPI の並行処理モデルを完全に理解する
hoto17296
1
390
Featured
See All Featured
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.5k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
460
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Technical Leadership for Architectural Decision Making
baasie
3
510
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
How to train your dragon (web standard)
notwaldorf
97
6.8k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
KATA
mclloyd
PRO
35
15k
Bash Introduction
62gerente
615
220k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.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 移行が進んでいるので、合わせてテストフレームワークも移行を検討すると良い かなと思います。
ご清聴ありがとうございました