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
Documentation testsの恩恵 / Documentation testing ...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
TOMIKAWA Sotaro
May 11, 2024
Programming
2
1.2k
Documentation testsの恩恵 / Documentation testing benefits
TSKaigi 2024
の発表資料です
TOMIKAWA Sotaro
May 11, 2024
Tweet
Share
More Decks by TOMIKAWA Sotaro
See All by TOMIKAWA Sotaro
Atomics APIを知る / Understanding Atomics API
ssssota
1
1k
なんでRustの環境構築してないのにRust製のツールが動くの? / Why Do Rust-Based Tools Run Without a Rust Environment?
ssssota
15
54k
Web技術を最大限活用してRAW画像を現像する / Developing RAW Images on the Web
ssssota
2
2.9k
漸進。
ssssota
0
3.4k
Preact、HooksとSignalsの両立 / Preact: Harmonizing Hooks and Signals
ssssota
1
3.3k
useSyncExternalStoreを使いまくる
ssssota
6
6.5k
React CompilerとFine Grained Reactivityと宣言的UIのこれから / The next chapter of declarative UI
ssssota
8
5.9k
新しいAPI createRawSnippet触ってみた / What is the createRawSnippet?
ssssota
2
280
脱法Svelte / Evasion of svelte rules
ssssota
1
300
Other Decks in Programming
See All in Programming
AI活用のコスパを最大化する方法
ochtum
0
120
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
420
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
3
1.2k
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
1.3k
2026年は Rust 置き換えが流行る! / 20260220-niigata-5min-tech
girigiribauer
0
210
atmaCup #23でAIコーディングを活用した話
ml_bear
4
720
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
120
DevinとClaude Code、SREの現場で使い倒してみた件
karia
1
840
株式会社 Sun terras カンパニーデック
sunterras
0
1.9k
オブザーバビリティ駆動開発って実際どうなの?
yohfee
3
650
Ruby x Terminal
a_matsuda
5
550
モジュラモノリスにおける境界をGoのinternalパッケージで守る
magavel
0
3.4k
Featured
See All Featured
Abbi's Birthday
coloredviolet
2
5k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
The browser strikes back
jonoalderson
0
740
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.1k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
150
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
110
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
The Curse of the Amulet
leimatthew05
1
9.3k
The Language of Interfaces
destraynor
162
26k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
300
Transcript
Documentation testsの恩恵 ssssota
自己紹介 冨川宗太郎 Tomikawa Sotaro (ssssota) { GitHub: "ssssota", X: "ssssotaro"}
フロントエンドエンジニア sは合計4つ
突然ですがこちらのコードをご覧ください
/// ``` /// use biome_unicode_table::is_js_ident; /// /// assert!(is_js_ident("id0")); /// assert!(is_js_ident("$id$"));
/// assert!(is_js_ident("_id_")); /// assert!(is_js_ident("𐊧")); /// /// assert!(!is_js_ident("")); /// assert!(!is_js_ident("@")); /// assert!(!is_js_ident("custom-id")); /// assert!(!is_js_ident("0")); /// ``` pub fn is_js_ident(s: &str) -> bool { if s.is_empty() { return false; Rust製Linter/Formatterである Biomeのコードを一部抜粋 ソースコード中のドキュメント に 関数の入出力が記載されている Rust(Cargo)にはデフォルトで 搭載されている機能で実際に利 用されている https://github.com/biomejs/biome/blob/7 245146125fa76c19780f68653092ed24fcdb717/ crates/biome_unicode_table/src/lib.rs#L4 2-L57
TypeScriptでは次のようなもの(vite-plugin-doctestの例) JSDocとして記載されたコメント内でassert関数を用い関数をテストしている それだけ /** * @example * ```ts @import.meta.vitest *
assert(add(1, 2) === 3); * ``` */ export const add = (a: number, b: number) => a + b; Documentation testsとは?
1. ソースコードのすぐそばに、テストコードが記載できる。 index.test.ts など別途ファイルを作成することなく、すぐにテストを書 き始めることができる。 2. ドキュメントに記載したコードを実行してその動作が保証できる。 ライブラリ等で、動かないサンプルコードを見たことが...。 3. 関数利用時にIDE(LSP)を介して「動作保証されたサンプルが閲覧できる」。
Documentation testsの恩恵
Documentation testsの恩恵 こんなシーンを見たことが... • ドキュメントにサンプルコードを書いても廃れる • そもそもJSDoc誰も読み書きしない... →実装のすぐとなりにテストコード(=JSDoc)を書くことで、 そもそもJSDocに触れる機会が増え、 それがサンプルコードとなり、生きたドキュメントになる。
ドキュメンテーションテストとの向き合い方 ドキュメンテーションテストは銀の弾丸(万能)ではない。 次のようなテストは向かない(書けない)。 • ライフサイクル関数が必要 • モックが必要 • UIテスト カジュアルにドキュメントおよびテストを書き始める手段の一つ。
いま型をカジュアルに書くように、 よりドキュメント/テストをカジュアルに書く世界。
npm i -D vitest vite-plugin-doctest import { defineConfig } from
'vitest/config'; import { doctest } from 'vite-plugin-doctest'; export default defineConfig({ plugins: [doctest()], // markdownファイルもサポートしている test: { includeSource: ['./src/**/*.[jt]s?(x)', './**/*.md'] }, }); npx vitest 導入方法(vite-plugin-doctest)
TypeScriptでは次のようなもの(vite-plugin-doctestの例) JSDocとして記載されたコメント内でassert関数を用い関数をテストしている それだけ /** * @example * ```ts @import.meta.vitest *
assert(add(1, 2) === 3); * ``` */ export const add = (a: number, b: number) => a + b; Documentation testsとは?
Documentation testsで 生きてるドキュメントとテストを書こう!