LoginSignup
2
0

More than 3 years have passed since last update.

【Storybook】`storyshots-puppeteer` で異なるデバイスのビジュアルスナップショットを撮る方法

Last updated at Posted at 2019-05-30

Storybook に storyshots-puppeteer を導入した後、異なるデバイスのビジュアルスナップショットを撮れるようにしたいと思い、下記のように書き換えました。


import initStoryshots from '@storybook/addon-storyshots'
import { imageSnapshot } from '@storybook/addon-storyshots-puppeteer'
import pupDevices from 'puppeteer/DeviceDescriptors';

const supportedDevices = new Set(['iPad', 'iPhone 5', 'iPhone 6', 'iPhone 7 Plus'])

initStoryshots({ suite: 'Image storyshots: PC', test: imageSnapshot() })

function createCustomizePage(pupDevice) {
  return function(page) {
    return page.emulate(pupDevice);
  }
}

for (let supportedDevice of supportedDevices) {
  const pupDevice = pupDevices[supportedDevice];

  if (!pupDevice) {
    continue;
  }

  const customizePage = createCustomizePage(pupDevice);

  initStoryshots({
    suite: `Image storyshots: ${pupDevice.name}`,
    test: imageSnapshot({
      customizePage,
    })
  });
}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0