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
3.3k
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
2.8k
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
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
1.2k
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.4k
気持ちぃ〜角丸 Squircle
ryu1013
0
340
AI-Powered Domain-Driven Design
ziobrando
0
320
パスワード再設定メールのURLについて知っておこう
uyuki234
0
190
React Native에 현대적인 빌드 도구 더하기: Rollipop 구현기
leegeunhyeok
0
150
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
160
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
200
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
1.8k
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
220
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
11
8.3k
No More NoSuchMethodError
exoego
1
110
Featured
See All Featured
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
Mind Mapping
helmedeiros
1
410
Amusing Abliteration
ianozsvald
1
360
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
490
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.2k
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.1k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
550
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
940
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
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というライブラリで結構簡単に作れる。 みんなもコード変換しまくろう!