#
Getting started
Welcome to the Chromado documentation, a library to seamlessly integrate Chromatic + Azure Pipelines. On this page, you'll discover how this package can optimize your workflow and learn how to set it up for your environment.
#
Features
Chromado aims to provide a workflow similar to the native Chromatic GitHub integration. While it's hardly as good, it's a functional workflow until Chromatic offers a native Azure Pipelines integration.
#
Build notifications
The Chromatic Azure Pipelines documentation explains how to integrate Chromatic within an existing pipeline through its CLI, but it's basically it, it lacks build notifications, it's up to you to figure out this part.
Chromado resolves this by automatically providing build notifications as pull request comments whenever a Chromatic build is completed:
#
TurboSnap
Chromado is compatible with TurboSnap and will by default trigger Chromatic builds with TurboSnap activated.
If TurboSnap is disabled for your build, the PR message will indicate so. In some cases, such as for a "rebuild", this is fine. However, in most cases, you should review the details of your Chromatic build to understand why TurboSnap was disabled:
Using TurboSnap is important because we pay for every snapshot captured by Chromatic. We still pay for TurnoSnaps, but they cost 1/5th of a regular snapshot.
#
Squash merge
Chromatic doesn't offer any mechanism to support squash merge on Azure DevOps. This means that when using Azure DevOps as a Git provider, if you wish to keep your Chromatic baselines up-to-date, you would be constrained to merging your pull requests with regular merge commits. Fortunately, Chromado implements a workflow based on Chromatic's auto-accept-changes feature, allowing pull requests to be completed with squash merges.
Here's how it works:
Whenever you create or update a pull request, a Chromatic build will automatically be triggered. If the build fails, the Chromatic pipeline will fail, and the team will need to either accept the changes or fix the issues before completing the pull request. If the changes are accepted, unfortunately the
main
branch baselines will not be updated.To update the baselines of the
main
branch, once the pull request has been merged, a new Chromatic build will be triggered on themain
branch. This new build will automatically accept all the changes (which is fine since they have been reviewed in the pull request) and update themain
branch baselines.
#
Setting up your workflow
First, let's create a new
#
Create a new Chromatic project
Request the owner of the Chromatic
gsoft-inc-ado
organization to create a new Chromatic project for your application. Ensure that you are added as a "collaborator" to the new project.Once created, login to Chromatic and select your application project from the list.
Save your Chromatic project id. You can find the project id in the project URL under the
appId
parameter. For example, if your project id is123
, the project URL would behttps://www.chromatic.com/manage?appId=123
.Go to
Manage
>Configure
>Project
>Setup Chromatic with this project token
and save the project token.With the Chromatic project id and token in hand, proceed to the next sections.
#
Configure your project
- Create a
chromatic.config.json
file at the root of your VSCode project and paste the following content:
{
"projectId": "<YOUR_CHROMATIC_PROJECT_ID>"
}
- Replace
<YOUR_CHROMATIC_PROJECT_ID>
by your Chromatic project id.
#
Create a new Azure pipeline
- First, open your application project and create a new YAML file called
chromatic.yml
. This file will store the configuration of your Chromatic Azure pipeline.
2.1. If your project already includes a template file to set up your pipelines, then paste the following configuration:
# Run Chromatic on the "main" branch after a pull request has been merged
# (currently required to update the baseline when doing "squash" merge for pull requests).
trigger:
branches:
include:
- main
# Run Chromatic on every pull request targeting the "main" branch as destination
# that is ready for review (not a draft).
pr:
branches:
include:
- main
drafts: false
steps:
# Chromatic needs the full Git history to compare the baselines.
# Checkout must happen before the setup template.
- checkout: self
displayName: Get full Git history
fetchDepth: 0
# Your project custom setup template.
- template: templates/setup.yml
- task: CmdLine@2
displayName: Chromatic
inputs:
script: pnpm dlx @workleap/chromado
env:
CHROMATIC_PROJECT_TOKEN: $(CHROMATIC_PROJECT_TOKEN)
CHROMATIC_PULL_REQUEST_COMMENT_ACCESS_TOKEN: $(PULL_REQUEST_COMMENT_ACCESS_TOKEN)
Most of Chromatic CLI options are accepted by the @workleap/chromado
script. If an option is not accepted, the script will output an error message.
2.2. If your project doesn't include a template file to set up your pipelines, paste the following configuration:
# Run Chromatic on the "main" branch after a pull request has been merged
# (currently required to update the baseline when doing "squash" merge for pull requests).
trigger:
branches:
include:
- main
# Run Chromatic on every pull request targeting the "main" branch as destination
# that is ready for review (not a draft).
pr:
branches:
include:
- main
drafts: false
steps:
# Chromatic needs the full Git history to compare the baselines.
# Checkout must happen before the setup template.
- checkout: self
displayName: Get full Git history
fetchDepth: 0
- task: UseNode@1
displayName: Use Node.js >=20.0.0
inputs:
version: ">=20.0.0"
checkLatest: true
- task: Cache@2
displayName: Cache pnpm
inputs:
key: '"pnpm" | "$(Agent.OS)" | pnpm-lock.yaml'
restoreKeys: |
"pnpm" | "$(Agent.OS)"
"pnpm"
path: $(Pipeline.Workspace)/.pnpm-store
- script: |
corepack enable
corepack prepare pnpm@latest-8 --activate
pnpm config set store-dir $(Pipeline.Workspace)/.pnpm-store
displayName: Setup pnpm
# Optional
- task: npmAuthenticate@0
displayName: Authenticate to private npm feed
inputs:
workingFile: .npmrc
- script: pnpm install --frozen-lockfile
displayName: pnpm install
- task: CmdLine@2
displayName: Chromatic
inputs:
script: pnpm dlx @workleap/chromado
env:
CHROMATIC_PROJECT_TOKEN: $(CHROMATIC_PROJECT_TOKEN)
CHROMATIC_PULL_REQUEST_COMMENT_ACCESS_TOKEN: $(PULL_REQUEST_COMMENT_ACCESS_TOKEN)
Most of Chromatic CLI options are accepted by the @workleap/chromado
script. If an option is not accepted, the script will output an error message.
Create a new Azure pipeline from an existing YAML file. Name this new pipeline "Chromatic" or choose a name that best suits your project.
Add the newly created Chromatic pipeline as a required build validation for your
main
branch. Ensure that the build validation is required. This is crucial as any visual changes detected by Chromatic will automatically be accepted on the main branch.Integrate the Chromatic project id and token, saved earlier, as pipeline variables of the newly created Chromatic pipeline. These variables should be named
CHROMATIC_PROJECT_TOKEN
andCHROMATIC_PULL_REQUEST_COMMENT_ACCESS_TOKEN
, respectively. Optionally, you can create theCHROMATIC_PULL_REQUEST_COMMENT_ACCESS_TOKEN
variable as a variable group.
#
Best practices
Be sure to read our best practices page to help Workleap stay within its monthly Chromatic snapshot budget.
#
Try it 🚀
To test your new Chromatic pipeline, follow these steps:
Start a Chromatic build locally by opening a terminal at the root of the project and executing the following command:
pnpm chromatic --project-token <YOUR_CHROMATIC_PROJECT_TOKEN>
.Go to the Chromatic application and accept all the changes to create a baseline. This guide assumes that your application already includes a few Storybook stories.
Move to a new Git branch and update an existing component watched by Chromatic to trigger a visual change. Commit the change.
Create a pull request for your new branch in Azure DevOps.
A Chromatic build should automatically trigger for the pull request, and a comment with the visual change should be added to it. The comment should indicate that Chromatic detected at least one visual change.
In the pull request comment, click on the "Build URL" link. Accept the changes in the Chromatic application.
Re-queue the Chromatic pipeline by clicking on the "Re-queue" button of the pipeline in the pull request.
- Once the Chromatic pipeline completes successfully, merge the pull request.
- A new Chromatic build should automatically trigger for the
main
branch. The changes from this new build should be automatically accepted by Chromatic, and the pipeline should complete successfully.
#
Troubleshoot issues
If you encounter pnpm-lock.yaml [file] (not found)
when executing the Chromatic pipeline, ensure that the pipeline point to the exact location of your project package-lock.yaml
file. For example, if your package-lock.yaml
is nested under a /frontend
, update key: '"pnpm" | "$(Agent.OS)" | pnpm-lock.yaml'
for key: '"pnpm" | "$(Agent.OS)" | $(System.DefaultWorkingDirectory)/frontend/pnpm-lock.yaml'
.
If you encounter any other issues with the Chromatic pipeline, follow these steps:
- Try adding the
CHROMATIC_DEBUG
environment variable tochromatic.yml
and review the the pipeline logs for diagnosis:
- task: CmdLine@2
displayName: Chromatic
inputs:
script: pnpm dlx @workleap/chromado
env:
CHROMATIC_PROJECT_TOKEN: $(CHROMATIC_PROJECT_TOKEN)
CHROMATIC_PULL_REQUEST_COMMENT_ACCESS_TOKEN: $(PULL_REQUEST_COMMENT_ACCESS_TOKEN)
CHROMATIC_DEBUG: true
Verify that the
CHROMATIC_PROJECT_TOKEN
pipeline variable value is correct. To find your Chromatic project token, log in to Chromatic, select your project in the list, and go toManage
>Configure
>Project
and look forSetup Chromatic with this project token
.Confirm that the
projectId
field in yourchromatic.config.json
file contains the correct project id. You can find the project id in the Chromatic project URL under theappId
parameter. For example, if your project id is123
, the project URL would behttps://www.chromatic.com/manage?appId=123
.Ensure that the
PULL_REQUEST_COMMENT_ACCESS_TOKEN
pipeline variable value is a valid, non-expired token.If issues persist, consider disabling TurboSnap by adding the
CHROMATIC_DISABLE_TURBOSNAP
environment variable thechromatic.yml
:
- task: CmdLine@2
displayName: Chromatic
inputs:
script: pnpm dlx @workleap/chromado
env:
CHROMATIC_PROJECT_TOKEN: $(CHROMATIC_PROJECT_TOKEN)
CHROMATIC_PULL_REQUEST_COMMENT_ACCESS_TOKEN: $(PULL_REQUEST_COMMENT_ACCESS_TOKEN)
CHROMATIC_DISABLE_TURBOSNAP: true
TurboSnap should be re-enabled promptly as Chromatic snapshots are not cheap. We pay for every snapshot that Chromatic takes.