Upgrade to Pro — share decks privately, control downloads, hide ads and more …

1粒で3度おいしいStorybook

 1粒で3度おいしいStorybook

Yosuke Kurami

April 19, 2018
Tweet

More Decks by Yosuke Kurami

Other Decks in Programming

Transcript

  1. Why do you need component catalogue?  ΞϓϦέʔγϣϯʹ͸ϨΞέʔε΍ҟৗܥ͕͖ͭ΋ͷ  ௨ৗಈ࡞Ͱ͸౸ୡͰ͖ͳ͍ݟͨ໨

     7JFX͕औΓಘΔঢ়ଶ͸͢΂ͯΞΫηεՄೳͰ͋Δ΂͖  ϨΞέʔεͷݟͨ໨ΛTUPSZͱͯ͠༻ҙ͢Δ͜ͱͰɺ
 ৗʹ֬ೝՄೳͳঢ়ଶʹ͓ͯ͘͠
  2. Tips: How to deploy Storybook  build-storybook ίϚϯυͰ੩తαΠτग़ྗ  (JU)VC1BHFT΍4ɺ$JSDMF$*"SUJGBDUTʹΞοϓϩʔυ

    # .circleci/config.yml
 - run: yarn run build-storybook -o /tmp/storybook - store_artifacts: path: /tmp/storybook
  3. 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>
  4. 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’)
  5. Does the test make sense…?  %0.ͷΞαʔγϣϯ͸ෆໟʹͳΓ͕ͪ  ʮEJWλάͰ͋Δ͜ͱʯΛ͔֬Ίͯ΋ҙຯͳ͍
 Ͱ΋ʮϨϯμϦϯά͞Εͨ͜ͱʯ͸ݕূ͍ͨ͠

     Կؾͳ͍࢓༷มߋ͕ΞαʔγϣϯΛই͚ͭͯ͠·͏  ࠷ѱͳͷ͸ςετΛॻ͘श׳͕ແ͘ͳͬͯ͠·͏͜ͱ
  6. Snapshot testing  ςετ݁Ռ 4OBQTIPU Λʮਖ਼͍݁͠Ռʯͱͯ͠อଘ  ࣍ճςετ࣌ʹલճ݁Ռͱͷࠩ෼Λݕࠪ͢Δ The latest

    snapshot (DOM String) The actual snapshot (DOM String) Update if snapshot is accepted Assertion
  7. 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(); });
  8. Snapshot with Jest & Storybook  ެࣜΞυΦϯ4UPSZTIPUT  ॻ͍ͨTUPSJFT͕ͦͷ··ςετʹͳΔ௒ศརͳࢠ 

    ֤TUPSZΛ+FTUͷςετέʔεͱͯ͠ɺ
 ࣗಈతʹεφοϓγϣοτςετΛ࣮ߦͯ͘͠ΕΔ
  9. 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