Loki and Chromatic are both visual regression testing tools for Storybook, but they differ fundamentally in approach: Chromatic is a cloud-based service that automates visual testing, review, and publishing, while Loki is a free, open-source tool that runs locally and uses Docker to capture and compare screenshots. This article explains the key differences, trade-offs, and how to choose between them for your project.
Background: What These Tools Do
Visual regression testing (also called visual testing) catches unintended UI changes by taking screenshots of components and comparing them against a baseline. Storybook is a popular tool for developing UI components in isolation, and both Loki and Chromatic integrate with it to automate this process. The core idea is the same: every time you change code, the tool renders your components, takes screenshots, and flags any visual differences so a developer can approve or reject them.
How Each Tool Works
Loki
Loki is an open-source npm package that you run in your own environment. It uses Docker to launch headless Chrome (or Firefox) containers to render your Storybook. You configure it with a loki.config.js file, and it produces a set of PNG screenshots stored in your repo. When you run loki test, it compares new screenshots against the baseline and generates a report showing pixel differences. You approve changes by running loki approve, which updates the baseline. Everything stays on your machine or CI server.
Chromatic
Chromatic is a commercial SaaS platform built by the Storybook team. You install the chromatic npm package and run chromatic in your CI. It uploads your Storybook to Chromatic's cloud, where it renders your stories in a controlled environment, takes screenshots, and compares them against the previous build. The results appear in a web dashboard where you can review visual diffs, approve or reject changes, and manage baselines. Chromatic also offers additional features like UI review for teammates, accessibility checks, and a component explorer for publishing.
Key Differences at a Glance
- Hosting: Loki runs locally (or in your CI), Chromatic runs in the cloud.
- Cost: Loki is free (open-source), Chromatic has a free tier for small teams but requires a paid plan for larger usage.
- Setup: Loki requires Docker and manual configuration; Chromatic requires an npm package and a project token.
- Baseline management: Loki stores baselines as files in your repo; Chromatic manages baselines in the cloud per branch.
- Review workflow: Chromatic offers a rich web UI for review and approval; Loki shows a simple HTML report locally.
- Integration: Chromatic integrates natively with GitHub, GitLab, and Bitbucket; Loki can be wired into any CI but with more effort.
Trade-offs and When to Choose Each
Choosing between Loki and Chromatic often comes down to your team's size, budget, and workflow preferences. Here are the main considerations:
- Budget: If you need a zero-cost solution, Loki is the clear winner. Chromatic’s free tier allows 5,000 snapshots per month, which may be enough for small projects, but larger teams will likely need to pay.
- Infrastructure: Loki requires Docker and a local or CI environment that can run it. If your team is not comfortable with Docker, Chromatic’s cloud approach is simpler.
- Review process: Chromatic shines when you need non-technical stakeholders (designers, product managers) to review visual changes. Its web interface is intuitive and supports comments and approvals. Loki’s report is developer-centric.
- Speed: Loki can be faster for small projects because it runs locally, but Chromatic’s parallel rendering in the cloud can be faster for large component libraries.
- Security: If your codebase cannot leave your network, Loki is the only option because Chromatic uploads your Storybook to its servers.
Common Problems and How to Avoid Them
Both tools have known quirks that can trip up teams. Here are the most frequent issues and how to address them:
- Flaky screenshots due to animations: Animations can cause false positives. Use Storybook’s
parametersto disable animations in tests, or use Loki’s--disableAnimationsflag. - Font loading differences: Different environments may load fonts differently, causing layout shifts. Ensure your fonts are loaded consistently, or use a font-loading strategy that works in headless browsers.
- Baseline bloat: Loki stores every approved screenshot as a file, which can bloat your repository over time. Consider using a separate branch or an external storage solution.
- Chromatic build timeouts: Large Storybooks can exceed Chromatic’s build time limit. Optimize your Storybook by using lazy loading or excluding unnecessary stories.
- Cross-platform differences: Loki runs in Docker, which helps consistency, but if you run it on different OSes or CI providers, you may see differences. Use the same Docker image everywhere.
Costs and Licensing
Loki is released under the Apache-2.0 license, meaning you can use it freely in commercial projects. There are no direct costs, but you must provide your own infrastructure (Docker, CI minutes, storage). Chromatic offers a free tier with 5,000 snapshots per month and unlimited viewers, but paid plans start at a monthly fee per user, which includes more snapshots and features like accessibility checks. For a large team, the subscription cost can be significant, but it saves engineering time by providing a polished review workflow out of the box.
Alternatives and Related Tools
If neither Loki nor Chromatic fits your needs, there are other options worth considering:
- Percy: A commercial visual testing platform that also integrates with Storybook, similar to Chromatic but from BrowserStack.
- BackstopJS: An open-source tool that uses Puppeteer to capture screenshots and compare them. It offers more flexibility but requires more setup.
- jest-image-snapshot: A Jest matcher that lets you write visual tests as part of your unit test suite.
- StoryShots: A Storybook addon that uses Jest for snapshot testing, though it focuses on DOM snapshots rather than visual screenshots.
- Manual testing: For very small projects, a simple checklist and manual review may be sufficient.
Frequently Asked Questions
Can I use Loki with CI without Docker?
No, Loki requires Docker to run browsers in a controlled environment. If your CI does not support Docker, you cannot use Loki. Chromatic, on the other hand, only needs Node.js and an internet connection.
Does Chromatic work with Storybook 7 and 8?
Yes, Chromatic supports Storybook 7 and 8. You need to install the matching version of the Chromatic package and follow the setup instructions for your Storybook version.
How do I handle dynamic content in my components?
Dynamic content (like dates or random IDs) can cause false positives. You can mock such values in your stories or use Chromatic’s freeze feature to freeze time. Loki has similar options via Storybook parameters.
Is Loki still maintained?
Loki is open-source and has not seen recent major updates, but it remains functional for many projects. However, if you need active development and support, Chromatic is a safer bet.
Can I migrate from Loki to Chromatic easily?
Migration is straightforward because both tools work with Storybook. You would remove Loki’s configuration and scripts, install Chromatic, and run its setup. You will lose your existing baselines, but Chromatic will create new ones from your current code.
Which tool is better for a large enterprise team?
For large teams, Chromatic is often preferred because it provides a centralized review platform, role-based access, and integrations with version control. Loki can be used but requires more internal tooling to manage baselines and approvals.