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
1粒で3度おいしいStorybook
Search
Yosuke Kurami
April 19, 2018
Programming
6.3k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
1粒で3度おいしいStorybook
Yosuke Kurami
April 19, 2018
More Decks by Yosuke Kurami
See All by Yosuke Kurami
TypeScript LSP の今までとこれから
quramy
1
2.1k
フロントエンドテストの育て方
quramy
12
3.9k
App Router 悲喜交々
quramy
8
750
上手に付き合うコンポーネントテスト
quramy
6
2.4k
Patched fetch did not work
quramy
6
800
GraphQL あるいは React における自律的なデータ取得について
quramy
18
5.9k
Next.js App Router
quramy
15
3.9k
Fragment Composition of GraphQL
quramy
17
4.9k
reg-viz VRT tools
quramy
4
1.7k
Other Decks in Programming
See All in Programming
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
340
霧の中の代数的エフェクト
funnyycat
1
480
その節約、円になってますか?
isamumumu
1
700
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
290
Foundation Models frameworkで画像分析
ryodeveloper
1
590
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
140
継続モナドとリアクティブプログラミング
yukikurage
3
690
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
140
Google Apps Script で Ruby を動かす
kawahara
0
130
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.3k
テーブルをDELETEした
yuzneri
0
140
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
160
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Navigating Weather and Climate Data
rabernat
0
450
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
410
The agentic SEO stack - context over prompts
schlessera
0
860
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Accessibility Awareness
sabderemane
1
170
How to Talk to Developers About Accessibility
jct
2
490
For a Future-Friendly Web
brad_frost
183
10k
RailsConf 2023
tenderlove
30
1.5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Ruling the World: When Life Gets Gamed
codingconduct
0
290
Transcript
ҰཻͰ ࡾ͓͍͍͠ Storybook
Today’s theme: Storybook in FOLIO
Storybook in FOLIO '0-*0ϑϩϯτνʔϜͰͷ4UPSZCPPLར༻ྫ ϝϦοτΛ3ͭհ͢ΔΑ ༰ͷେ3FBDUʹґଘ͠ͳ͍Α
ؼͬͨΒ4UPSZCPPL͕͍ͨ͘ͳΔʂͣ
Introduction
Storybook is a development environment for UI components. https://github.com/storybooks/storybook
Storybook basics $PNQPOFOUΧλϩάΛੜ͢Δπʔϧ ݩʑ3FBDU͕λʔήοτ ݱࡏ༷ʑͳ6*GSBNFXPSLTʹରԠ "OHVMBS
7VFKT 3FBDU/BUJWF 1PMZNFS
None
1. Developer experience
Story driven development ίϯϙʔωϯτΛ༻ҙ͢Δ ίϯϙʔωϯτΛࢀরͨ͠TUPSJFTϑΝΠϧΛ࡞Δ QSPQTͷύλʔϯʹԠͯ͡TUPSZΛ૿͍ͯ͘͠
).3 )PU.PEVMF3FQMBDFNFOU ରԠͯ͠ΔͷͰɺ αΫαΫը໘Λ։ൃͰ͖Δ
Demo
Tips: Scaffold your stories TUPSJFTͷܗΛੜ͢ΔTDSJQUΛ࡞͓ͬͯ͘ͱศར ྫ+49$44.PEVMFTTUPSJFT NVTUBDIFNJOJNJTUJORVJSFSΛΈ߹ΘͤΔͱ͓
खܰʹ$-*͕࡞ΕΔ ϝϯόʔͷͨΊʹಋೖোนগ͠Ͱ͓ܰͯ͘͘͠
Why do you need component catalogue? ΞϓϦέʔγϣϯʹϨΞέʔεҟৗܥ͕͖ͭͷ ௨ৗಈ࡞Ͱ౸ୡͰ͖ͳ͍ݟͨ
7JFX͕औΓಘΔঢ়ଶͯ͢ΞΫηεՄೳͰ͋Δ͖ ϨΞέʔεͷݟͨΛTUPSZͱͯ͠༻ҙ͢Δ͜ͱͰɺ ৗʹ֬ೝՄೳͳঢ়ଶʹ͓ͯ͘͠
Stories for abnormal properties ࣮ࡍͷΞϓϦέʔγϣϯͰ࠶ݱ͕໘ͳύλʔϯୡ
2. Accelerate communication
With reviewers ʮ7JFX͕औΓಘΔঢ়ଶʹΞΫηεՄೳʯͰ͋Δҙຯ 6*ίϯϙʔωϯτͷมߋΛ4UPSZCPPLͰ֬ೝՄೳ ։ൃऀಉ࢜ͷϨϏϡʔḿΔ
With reviewers ֬ೝ͖͢TUPSZ͕Ұྎવ
With designers 4UPSZCPPLΛνʔϜͰڞ༗͢Εɺ࣮ͨ͠6*ͷ ϑΟʔυόοΫΛಘ͍͢ ΞχϝʔγϣϯάϥϑͳͲɺσβΠϯΧϯϓͷΈ Ͱදݱ͕͍͠6*ͰޮՌత σβΠϯ࣮ͷαΠΫϧΛΑΓૣ͘ճ͢͜ͱ͕Ͱ
͖Δ
Tips: How to deploy Storybook build-storybook ίϚϯυͰ੩తαΠτग़ྗ (JU)VC1BHFT4ɺ$JSDMF$*"SUJGBDUTʹΞοϓϩʔυ
# .circleci/config.yml - run: yarn run build-storybook -o /tmp/storybook - store_artifacts: path: /tmp/storybook
As CircleCI artifacts
3. Improve unit testing
BTW, How to test view?
What should we assert? <template> <div class="greeting"> <div v-if="lang==='en'"> Good
evening, {{name}}. </div> <div class="fr" v-if="lang==='fr'"> Bon soir, {{name}}! </div> </div> </template> <template> <div class="greeting"> <div v-if="lang==='en'"> Good evening, {{name}}. </div> <div class="fr" v-if="lang==='fr'"> Bon soir, {{name}}! </div> </div> </template>
What should we assert? <template> <div class="greeting"> <div v-if="lang==='en'"> Good
evening, {{name}}. </div> <div class="fr" v-if="lang==='fr'"> Bon soir, {{name}}! </div> </div> </template> <template> <div class="greeting"> <div v-if="lang==='en'"> Good evening, {{name}}. </div> <div class="fr" v-if="lang==='fr'"> Bon soir, {{name}}! </div> </div> </template> assert.equal(node.textContents, ‘Bon soir Quramy!’) assert(node.hasClass(‘fr’)) assert.equal(node.nodeName, ’div’)
Does the test make sense…? %0.ͷΞαʔγϣϯෆໟʹͳΓ͕ͪ ʮEJWλάͰ͋Δ͜ͱʯΛ͔֬Ίͯҙຯͳ͍ ͰʮϨϯμϦϯά͞Εͨ͜ͱʯݕূ͍ͨ͠
Կؾͳ͍༷มߋ͕ΞαʔγϣϯΛই͚ͭͯ͠·͏ ࠷ѱͳͷςετΛॻ͘श׳͕ແ͘ͳͬͯ͠·͏͜ͱ
So, snapshot testing
Snapshot testing ςετ݁Ռ 4OBQTIPU Λʮਖ਼͍݁͠Ռʯͱͯ͠อଘ ࣍ճςετ࣌ʹલճ݁ՌͱͷࠩΛݕࠪ͢Δ The latest
snapshot (DOM String) The actual snapshot (DOM String) Update if snapshot is accepted Assertion
Snapshot with Jest import React from 'react'; import Link from
'../Link.react'; import renderer from 'react-test-renderer'; it('renders correctly', () => { const tree = renderer .create(<Link page="http://www.facebook.com">Facebook</Link>) .toJSON(); expect(tree).toMatchSnapshot(); });
Snapshot with Jest & Storybook ެࣜΞυΦϯ4UPSZTIPUT ॻ͍ͨTUPSJFT͕ͦͷ··ςετʹͳΔศརͳࢠ
֤TUPSZΛ+FTUͷςετέʔεͱͯ͠ɺ ࣗಈతʹεφοϓγϣοτςετΛ࣮ߦͯ͘͠ΕΔ
Workflow with Storyshots ίϯϙʔωϯτͷग़ྗ %0. ʹมߋ͕ͳ͍έʔε લճͷεφοϓγϣοτͱࠓճͷεφοϓγϣοτ ʹ͕ࠩੜ͡ͳ͍ͨΊɺςετ0,
Workflow with Storyshots ίϯϙʔωϯτͷग़ྗ %0. ʹมߋ͕͋Δέʔε εφοϓγϣοτʹ͕ࠩੜ͡ɺςετࣦഊ͢Δ
Workflow with Storyshots εφοϓγϣοτϑΝΠϧΛߋ৽ͯ͠ɺ 13ͷϒϥϯνʹؚΊΔ ϨϏϡΞʔɺมߋ͞ΕͨεφοϓγϣοτϑΝΠϧ ؚΊͯϨϏϡʔΛߦ͏
ҙਤ͠ͳ͍มߋ͕͋Δ߹ϨϏϡʔͰغ٫͢Δ
Tips: Coverage 4UPSZTIPUT7JFXͷΧόϨοδऔಘͯ͘͠ΕΔ
Furthermore: Screenshot test 4UPSZCPPLͰը૾ճؼςετ '0-*0Ͱະணख 4UPSZCPPLͱSFHTVJUͰؾܰʹ͡ΊΔ7JTVBM 3FHSFTTJPO5FTUJOH
https://blog.wadackel.me/2018/storybook-chrome-screenshot-with-reg-viz/ 4DSFFOTIPUUFTUJOHXJUI3FBDUBOE4UPSZCPPL https://medium.com/bleeding-edge/screenshot-testing-with-react-and- storybook-19ab7e49ec92
Summary
Storybook provides ίϯϙʔωϯτΛαΫαΫ࡞ΕΔڥ ࣮ࡍʹʮಈ͘ʯ6*ΛνʔϜશମʹڞ༗ ͦͷ··7JFXͷςετج൫ͱͯ͑͠Δ
What’s important ಋೖʹΑΔෆརӹ͕Ͳ͜ʹແ͍ ʮςετॻ͚ʂʯͰॻ͍ͯ͘ΕΕۤ࿑͠ͳ͍ ؾ͍ͮͨΒςετʹͳͬͯɺଞͷϝϯόʔتΜͰ͘ ΕΔͬͯɺ࠷ߴ͡Όͳ͍Ͱ͔͢ʁ
Appendix ࣮4UPSZCPPLΛಋೖͨ͠ͷൺֱత࠷ۙ 5; ͓Αͦϲ݄ͰͲͷఔΘΕ͍ͯΔ͔ d4UPSJFT
$PWFSBHF
Storybook is a development environment for UI components. https://github.com/storybooks/storybook
Thank you! By @Quramy