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
TypeScriptとDocumentaion tests / Documentation t...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
TOMIKAWA Sotaro
January 12, 2024
Programming
4.3k
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
TypeScriptとDocumentaion tests / Documentation tests with TypeScript
TOMIKAWA Sotaro
January 12, 2024
More Decks by TOMIKAWA Sotaro
See All by TOMIKAWA Sotaro
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3.2k
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
2.7k
Atomics APIを知る / Understanding Atomics API
ssssota
2
1.5k
なんでRustの環境構築してないのにRust製のツールが動くの? / Why Do Rust-Based Tools Run Without a Rust Environment?
ssssota
15
57k
Web技術を最大限活用してRAW画像を現像する / Developing RAW Images on the Web
ssssota
2
3.4k
漸進。
ssssota
0
3.8k
Preact、HooksとSignalsの両立 / Preact: Harmonizing Hooks and Signals
ssssota
1
3.9k
useSyncExternalStoreを使いまくる
ssssota
6
7.1k
React CompilerとFine Grained Reactivityと宣言的UIのこれから / The next chapter of declarative UI
ssssota
8
6.4k
Other Decks in Programming
See All in Programming
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
330
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
1
180
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
golang-bob.pdf
iwatsukayura
0
130
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
370
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
150
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
740
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
16k
JIS keyboard support in Omarchy
lef237
0
100
contenteditable と日本語入力に向き合う
colorful12
0
190
Featured
See All Featured
How to build a perfect <img>
jonoalderson
1
6.1k
A better future with KSS
kneath
240
18k
Mobile First: as difficult as doing things right
swwweet
225
10k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
400
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
410
Agile that works and the tools we love
rasmusluckow
331
22k
Making the Leap to Tech Lead
cromwellryan
135
10k
Thoughts on Productivity
jonyablonski
76
5.4k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
490
Code Review Best Practice
trishagee
74
20k
Transcript
TypeScriptとDocumentation tests ssssota
だれ • ssssota • 冨川宗太郎 • {"x": "ssssotaro", "github": "ssssota"}
• JSのビルド周りのツールチェーンに関心がある
Documentation testsとは /// ``` /// let result = doccomments::add(2, 3);
/// assert_eq!(result, 5); /// ``` pub fn add(a: i32, b: i32) -> i32 { a + b } ↑はRustのドキュメントに書いてあるもの 最近のJSエンジニアはRustが必修と聞いているのでみなさんご存知。 コード内(外)のドキュメントに記述されたコードを実行することで ドキュメントの信頼性を担保する。
JSのDocumentation tests • Supabase CEO作 https://github.com/kiwicopple/doctest-js • azu氏 作 https://github.com/azu/power-doctest
• https://github.com/davidchambers/doctest いずれもJavaScriptにサポートが限定される。 (3つ目はなぜかCoffeeScriptサポートがある) TypeScriptのファイルでもDocumentation testsしたい!
作った https://github.com/ssssota/doc-vitest Vitest向けのプラグインとして作ることでTypeScriptのトランスパイルは Vite(esbuild)に、テスト周りのCLI,assertionはVitestに全乗っかり。 /** * @import.meta.vitest * ```ts *
expect(add(1, 2)).toBe(3); * assert(add(3, 4) === 7); * ``` */ export function add(a: number, b: number) { return a + b; }
仕組み(変換) /** * @import.meta.vitest * ```ts:1+2=3 * expect(add(1, 2)).toBe(3); *
``` */ export function add(a: number, b: number) { return a + b; } /** * @import.meta.vitest * ```ts:1+2=3 * expect(add(1, 2)).toBe(3); * ``` */ export function add(a: number, b: number) { return a + b; } if (import.meta.vitest) { const {assert,...} = import.meta.vitest; import.meta.vitest.test("1+2=3", async()=>{ expect(add(1, 2)).toBe(3); }); }
仕組み(Vitest) Vitest用プラグインと書いたが正確にはVite用プラグイン。Vitestからの実行時に のみ変換が有効化される VitestのIn-Source Testingと呼ばれる機能で追記されたテストが実行される In-source Testingでは変換前の時点で import.meta.vitest の記述があるファイル だけを実行対象にするので
@import.meta.vitest という記述が必要だった テスト対象を抜き出せばOKなので、Markdown内のコードブロックもサポートし ている
おわりに JavaScriptの開発では至る所でコード変換されている。 (トランスパイル、バンドル、ミニファイ、Svelte/Vueコンポーネント、、、) webpackやViteのプラグインはUnpluginというライブラリで結構簡単に作れる。 みんなもコード変換しまくろう!