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

BackstopJS + CircleCI + Docker で、HTML/CSSの自動テスト...

BackstopJS + CircleCI + Docker で、HTML/CSSの自動テストをした話。(WordPressのテーマ編)

Frontend Nagoya #3 での登壇資料です。

Toro_Unit (Hiroshi Urabe)

January 27, 2018
Tweet

More Decks by Toro_Unit (Hiroshi Urabe)

Other Decks in Technology

Transcript

  1. Toro_Unit ઎෦ ߛ (͏Β΂ ͻΖ͠) HAMWORKS • Frontend Engineer •

    WordPress Plugin and Theme Developer • Custom Post Type Permalinks • Vanilla • more... Github: @torounit Twitter: @Toro_Unit 3
  2. 5

  3. Why? • ؅ཧ͠ʹ͍͘ɻ • ؆୯ʹ্ॻ͖Ͱ͖ͯ͠·͏ɻ • ͜ΘΕ΍͍͢ɻ • Өڹൣғ͕σΧΠ •

    1ຕͷCSS͕୔ࢁͷHTMLʹద༻͞Ε͍ͯΔɻ • CMS౳ͰɺHTML͕มߋ͞ΕΔ͜ͱ΋ଟ͍ɻ 8
  4. • όάमਖ਼ɻ • ςʔϚΧελϚΠβʔ͕͏·͘ಈ͍͍ͯͳ͍ͱ͔ɺ৭ΜͳϨΠϠʔʹ·͕ͨ Δमਖ਼͕ඞཁͳ৔߹΋͋Δɻ • ؅ཧը໘͔Β͍Ζ͍Ζมߋग़དྷΔΑ͏ʹ͍ͯ͠ΔͱͲ͏ͯ͠΋ൃੜ͕ͪ͠ɻ • ػೳͷ௥Ճ •

    ࣗ෼Ͱ࢖͍ͬͯΔதͰ΍Γ͍ͨ͜ͱ΋ग़ͯ͘Δɻ • ͦͷͨͼʹผͷςʔϚΛ࡞Δͷ΋ɻɻɻɻ • ͳΜͱͳ͘Styls΍Ί͍ͨɻ • WordPress ͷ৽ػೳ΁ͷରԠɻ 23
  5. Gutenberg • WordPress 5.0 Ͱ౥ࡌ༧ఆͷ৽͍͠Τ σΟλɻ • ϒϩοΫϕʔεɻ • ΤσΟλͷදݱྗ͕େ෯ʹڧԽɻ

    • ςʔϚͰίϨΛͪΌΜͱαϙʔτ͢ Δʹ͸ɺ͍Ζ͍Ζมߋ͕ඞཁɻ • ओʹCSSपΓΛվम͢Δඞཁ͕͋ Δɻ 24
  6. ڪාΛͲ͏ݮΒ͍͔ͯ͘͠ • ςετ΍ɺLint ͷࣗಈԽɻ • ྫ͑͹ɺPHPͷ৔߹͸ɺPHPUnit ΍ PHPCS౳Λ༻͍Δɻ • JSͳΒɺMocha

    ͱ͔ɺJest ͱ͔ɻ • ࣗಈతɾఆظతʹ࣮ߦɻ • Travis CI / Circle CI / Jenkins ౳Ͱ ίϛοτ͝ͱʹࣗಈ࣮ߦɻ • ϏϧυͷࣗಈԽɻ 27
  7. ܧଓతΠϯςάϨʔγϣϯͱ͸ • Continuous Integration. ུͯ͠ CI. • ओʹϓϩάϥϚʔͷΞϓϦέʔγϣϯ࡞੒࣌ͷ඼࣭վળ΍ೲ ظͷ୹ॖͷͨΊͷश׳ͷ͜ͱ(by Wikipedia)

    • ۩ମతͳऔΓ૊Έͱͯ͠͸ςετ΍ϏϧυͳͲͷఆظతͳ࣮ ߦͳͲɻ • ࣗಈԽ͢ΔͨΊʹɺCI༻ͷαʔόʔΛ༻ҙͨ͠Γɻ 30
  8. BackstopJS • WEBαΠτɺΞϓϦͷݟͨ໨ͷճؼ ςετΛߦ͏πʔϧɻ • ϔουϨεϒϥ΢β( Headless Chrome ΍ɺPhamtomJS ౳)

    ͰεΫ ϦʔϯγϣοτΛऔಘɾൺֱ͠ɺม ߋΛݕ஌Ͱ͖Δɻ • ෳ਺ͷը໘αΠζɾϢʔβʔΤʔδΣ ϯτͳͲͰςετՄೳɻ 34
  9. Πϯετʔϧ $ npm install -g backstopjs • άϩʔόϧ͡Όͳͯ͘΋OK. • Headless

    Chrome Λ࢖͏৔߹͸ɺGoogle Chrome ͳ͍͠ɺ Chromium ΋Πϯετʔϧɻ 35
  10. ίϚϯυ $ backstop init ઃఆϑΝΠϧͷͻͳܗੜ੒ $ backstop reference ϦϑΝϨϯε(ਖ਼ղͷεΫϦʔϯγϣο τ)Λऔಘɻ

    $ backstop test ςετ࣮ߦ $ backstop approve ςετ݁ՌΛϦϑΝϨϯεʹऔΓࠐΈɻ 36
  11. { "id": "vanilla_wp", "viewports": [ { "label": "phone", "width": 320,

    "height": 480 }, ], "onBeforeScript": "chromy/onBefore.js", "onReadyScript": "chromy/onReady.js", "scenarios": [ { "label": "Markup HTML Tags and Formatting", "url": "http://localhost/markup-html-tags-and-formatting/", "selectors": [] }, { "label": "Page Markup And Formatting", "url": "http://localhost/about/page-markup-and-formatting/", "selectors": [] }, ], "report": ["CI"], "engine": "chrome" } 37
  12. 38

  13. 39

  14. • ෳ਺ͷ Viewport ͷΤϛϡϨʔτ΋Մೳɻ • Cookie Λྲྀ͠ࠐΊ͹ɺϩάΠϯ͕ඞཁͳϖʔδ΋ɻ • Ϛ΢εͷૢ࡞ͳͲ΋JSͰઃఆՄೳͳͷͰɺhoverɺclick࣌ͳ Ͳ΋ςετग़དྷΔɻ

    ϨϙδτϦͷReadme ͱɺexample ΛݟΔͱ͔ͳΓ৭Μͳίτ ͕ग़དྷΔɻ https://github.com/garris/BackstopJS/tree/master/examples 40
  15. ࡶͳ Docker Πϝʔδͷ࡞Γํղઆɻ Dockerfile ʹɺͣΒͣΒίϚϯυΛهड़ɻ FROM ubuntu:16.04 RUN apt-get install

    -y chromium-browser ENV CHROME_PATH /usr/bin/chromium-browser RUN apt-get install -y nodejs Ubuntu ʹ Chromium ͱ Node.js ͕ೖͬͨ؀ڥΛखܰʹ࡞੒Ͱ ͖Δɻ 49
  16. BackstopJS ͱ WordPress ͷ࣮ߦ؀ڥΛ Docker Ͱ࡞ͬͨɻ • torounit/wp-theme-test-env - Docker

    Hub • Github: torounit/wp-theme-test-env Chromium / Node.js / Noto Sans ͱ WordPress ͷಈ࡞؀ڥɻ WordPress ͷ ςʔϚϢχοτςετσʔλ΋ઃఆࡁΈɻ 53
  17. ࠓճ͸ Circle CI • OSSͩͱແྉͰ࢖͑Δɻ • Docker αϙʔτɻ • store_artifacts

    Ͱੜ੒෺Λอଘ& ϒϥ΢βͰ؆୯ʹ֬ೝͰ͖ΔͷͰɺ BackstopJSΛ࢖͏ͱ͖͸ศརɻ 56
  18. 57

  19. version: 2.0 jobs: test: docker: - image: torounit/wp-theme-test-env:latest working_directory: /var/www/wordpress/wp-content/themes/vanilla

    steps: - checkout - setup_remote_docker: docker_layer_caching: true - run: command: npm install - run: command: sudo service php7.0-fpm start & sudo service nginx start & sudo service mysql start - run: command: wp theme activate vanilla --path=/var/www/wordpress - run: command: curl http://localhost > /dev/null - run: command: npm test - store_artifacts: path: backstop_data destination: artifacts - store_test_results: path: backstop_data/ci_report 59