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
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.6k
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
2.6k
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.3k
漸進。
ssssota
0
3.7k
Preact、HooksとSignalsの両立 / Preact: Harmonizing Hooks and Signals
ssssota
1
3.8k
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
巨大モノリシックアプリ モダン化大作戦
ktcryomm
0
970
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
130
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
180
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
140
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
150
Security issues being discussed on Web Platforms
petamoriken
0
880
AHC070解法紹介
eijirou
0
110
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
480
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
110
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
200
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
0
250
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
310
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
77
5.5k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
480
A Soul's Torment
seathinner
7
3.6k
KATA
mclloyd
PRO
35
15k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
Optimizing for Happiness
mojombo
378
71k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
740
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
270
Being A Developer After 40
akosma
91
590k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
240
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
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というライブラリで結構簡単に作れる。 みんなもコード変換しまくろう!