Problem Summary
Storybook snapshot test on static storybook returning blank screenshots even though they look fine on localhost:8080
when I ran npx http-server storybook-static
Tech stack and relevant code
- Vue 3
- Vite
- Storybook
- Jest
- Storyshots
- Puppeteer
I have components and their respective stories. npm run storybook
works perfectly fine. My storybook.spec.js
is as follows:
import { imageSnapshot } from "@storybook/addon-storyshots-puppeteer"
import initStoryshots from "@storybook/addon-storyshots"
initStoryshots({
suite: "Image storyshots",
test: imageSnapshot(
storybookUrl: 'file://absolute/path/to/my/storybook-static'
)
})
I ran the following. fyi, I did not modify any file in storybook-static after running npm run build-storybook
.
npm run build-storybook
npm run test
npm run test
constitutes jest --config=jest.config.js test
Problem
Unfortunately, the screenshots I get are all blank and fail the snapshot test.
I suspect it might be due to a CORS error just like other Storybook users when they click <project-root>/storybook-static/index.html
after running npm run build-storybook
, to which I want to ask for a solution as well, because I wanna run test remotely on a headless server.
Note
I used absolute path because relative path caused a resource not found error during the testing process.
None of the images were loading within my pipeline but worked fine locally, ended up being because the components were fetching images using a relative path
<img src="/my-image" />
which apparently is not allowed using the file protocol.I ended up doing 2 things:
Another (arguably better) approach would be to run the tests through a server where you can access the images