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
2.9k
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
2.7k
Atomics APIを知る / Understanding Atomics API
ssssota
2
1.4k
なんでRustの環境構築してないのにRust製のツールが動くの? / Why Do Rust-Based Tools Run Without a Rust Environment?
ssssota
15
56k
Web技術を最大限活用してRAW画像を現像する / Developing RAW Images on the Web
ssssota
2
3.4k
漸進。
ssssota
0
3.7k
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.3k
Other Decks in Programming
See All in Programming
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
410
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
18
16k
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
3.6k
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
840
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
260
wkhtmltopdfの次どうするか問題2026
willnet
2
1.7k
setup-vp GitLab対応の裏側
naokihaba
0
120
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
210
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
670
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
400
GitHubハンズオン講座 — 実務レベルのチーム開発のフローを身につけよう
junhat6
0
110
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
940
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
37
4k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
500
A Modern Web Designer's Workflow
chriscoyier
699
190k
Bash Introduction
62gerente
615
220k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
390
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
560
The Cost Of JavaScript in 2023
addyosmani
55
10k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
300
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
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というライブラリで結構簡単に作れる。 みんなもコード変換しまくろう!