Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loki

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loki

Visual Regression Testing for react-storybook

  • 0.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
35K
increased by6.53%
Maintainers
1
Weekly downloads
 
Created
Source
Loki

Visual Regression Testing for Storybook

Loki

Rationale

There's a few visual regression tools for the web, but most use phantomjs which is deprecated and a browser nobody is actually using, and they usually require you to maintain fixtures. Also with react-native it's now possible to target multiple platforms with a single code base and there's no tool supporting all to my knowledge.

Supported platforms

  • Chrome
    • Local computer
    • Docker
  • iOS simulator
  • Android emulator

Prerequsites

  • Node 7.6 or higher
  • Either docker or Chrome 59+
  • Optionally GraphicsMagick

Installation

yarn add loki --dev
yarn run loki init

Configuration

The init command will add a loki section to your package.json, but you can edit it to your wishes.

Example package.json:

{
  "name": "my-project",
  "version": "1.0.0",
  "loki": {
    "chrome-selector": "#my-decorator > *",
    "configurations": {
      "chrome.laptop": {
        "target": "chrome.app",
        "width": 1366,
        "height": 768
      },
      "chrome.iphone7": {
        "skip-stories": "loading|MyFailingComponent",
        "target": "chrome.app",
        "preset": "iPhone 7"
      },
      "ios": {
        "target": "ios.simulator"
      },
      "android": {
        "target": "android.emulator"
      }
    }
  }
}

chrome-selector

Similar to the --chrome-selector CLI argument, this setting is a CSS selector to the part of the page you want screenshots of. This is useful if you have decorators that's not really part of the component itself. Note that it doesn't screenshot the DOM element itself but rather the crops the screenshot to those dimensions, so if you have any elements absolutely positioned above they will be included.

skip-stories

Similar to the --skip-stories CLI argument, this setting is a regular expression matched against the concatenated kind and story name (${kind} ${story}), case insensitive. It's useful if some story breaks the tests or contains animations as an alternative to comment it out.

filter-stories

Opposite to skip-stories.

configurations

NameTypeDescriptionTargets
targetstringTarget platform, possible values are chrome.app, chrome.docker, ios.simulator, android.emulator.All
skip-storiesstringSame as loki.skip-stories, but applied to only this configuration.All
filter-storiesstringSame as loki.filter-stories, but applied to only this configuration.All
chrome-selectorstringSame as loki.chrome-selector, but applied to only this configuration.chrome.*
presetstringPredefined bundled configuration, possible values are Retina Macbook Pro 15, iPhone 7, iPhone 5 and Google Pixel.chrome.*
userAgentstringCustom user agent.chrome.*
widthintegerBrowser viewport width.chrome.*
heightintegerBrowser viewport height.chrome.*
deviceScaleFactorintegerBrowser pixel density multiple, use 2 for retina, not supported in docker.chrome.app
mobilebooleanWhether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more.chrome.*
fitWindowbooleanWhether a view that exceeds the available browser window area should be scaled down to fit.chrome.*

Running visual tests

Make sure your storybook server is running, and any simulator/emulator if you target them, before running this command.

yarn run storybook
yarn run loki

Commands

loki test

yarn run loki test -- --port 9009

If you run loki via yarn, you need to make sure to prepend your argument list with -- so that yarn passes them though to loki. You can add ./node_modules/.bin to your PATH to be able to run loki directly too.

FlagDescriptionDefault
--hostStorybook hostlocalhost
--portStorybook portNone
--react-portReact Storybook port6006
--react-native-portReact Native Storybook port7007
--referencePath to screenshot reference folder./screenshots/reference
--outputPath to screenshot output folder./screenshots/current
--differencePath to image diff folder${outputFolder}/diff
--diffing-engineWhat diffing engine to use, currently supported are looks-same and gmlooks-same
--chrome-concurrencyHow many stories to test in paralell when using chrome4
--chrome-selectorCSS selector to the part of the DOM to screenshot. Useful you have decorators that should be excluded.#root > *
--chrome-flagsCustom chrome flags.--headless --disable-gpu --hide-scrollbars
--skip-storiesRegular expression for stories that should not be tested, it will be tested against a string with the format ${kind} ${story}.None
--stories-filterOpposite of --skip-stories.None
--configuration-filterRegular expression for targets that should be tested.None
--target-filterRegular expression for targets that should be tested.None
--update-referenceUpdate reference files instead of testing.No
--require-referenceFail stories without reference image, useful for CI.No

loki init

yarn run loki init path/to/storybook -- --force
FlagDescriptionDefault
--configPath to storybook folder.storybook & storybook
--forceOverwrite loki configurationfalse

License

MIT License. © Joel Arvidsson 2017

Keywords

FAQs

Package last updated on 11 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc