The following test passes locally, and the Chromatic build step passes, but in the Bitbucket pipeline it fails. I suspect it has to do with the async behavior and usage of waitFor.
const statuses = ['Open', 'In Progress', 'Cancelled', 'Closed'];
export const Default: PlayableStory = {
args: {
title: 'Filter by status',
options: statuses.map(status => ({ value: status, label: status })),
},
play: async () => {
const { getByText } = screen;
statuses.forEach(status => expect(getByText(status)).toBeInTheDocument());
const unSelectedBackgroundColor = 'rgba(0, 0, 0, 0)';
const selectedBackgroundColor = 'rgba(0, 0, 0, 0.08)';
async function expectChipSelected(text: string, selected = true) {
await waitFor(() => {
const chip = screen.getByRole('button', { name: text });
expect(getComputedStyle(chip).backgroundColor).toEqual(
selected ? selectedBackgroundColor : unSelectedBackgroundColor,
);
});
}
// select one
await expectChipSelected(statuses[0], false);
fireEvent.click(getByText(statuses[0]));
await expectChipSelected(statuses[0]);
// and more similar tests
},
};
The relevant pipeline step:
- step:
name: 'Run storybook tests'
caches:
- node
script:
- npm install --legacy-peer-deps
- npx playwright install --with-deps
- npm run build-storybook --silent
- npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
"npx http-server storybook-static --port 6006 --silent" \
"npx wait-on tcp:6006 && npm run test-storybook"