-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[addon-storyshots] storyshots found 0 stories: TypeError: Cannot destructure property 'instrument' of 'undefined' as it is undefined. #15916
Comments
Just ran into this with |
Facing similar issue with mdx stories as well. I am using latest stable storybook version i.e. |
I looked into the issue a bit more...after Jest 27, the API of Also, Jest don't export But if we change to use Someone has pointed this out in jest repo... |
Okay I guess I figure it out... because we want the story file be processed by other transformer first and then append Guess I can open an issue to the jest repo then |
Any workaround for getting Jest 27 to work with mdx stories? |
Same issue here :( |
I wrote a makeshift jest-transform to get around it. // https://github.com/storybookjs/storybook/blob/v6.4.14/addons/storyshots/storyshots-core/injectFileName.js#L12
function findTransform(transform, fileName) {
const self = transform.find(([pattern]) =>
new RegExp(pattern).test(fileName),
);
const transformExcludeSelf = transform.filter(t => t !== self);
return transformExcludeSelf.find(([pattern]) => new RegExp(pattern).test(fileName));
}
function generateCJS(fileName, { code }) {
return `${code};
if(exports.default != null) {
exports.default.parameters = exports.default.parameters || {};
exports.default.parameters.fileName = '${fileName.replace(/\\/g, '\\\\')}';
}
`;
}
module.exports = {
process(src, fileName, config) {
const [,transformFileName] = findTransform(config.config.transform, fileName);
const processed = require(transformFileName).default.process(src, fileName, config);
return generateCJS(fileName, processed);
},
}; jest.config.js: transform: {
'^.+\\.stories\\.tsx?$': '<rootDir>/injectFileName.js',
// '^.+\\.stories\\.tsx?$': '@storybook/addon-storyshots/injectFileName',
'^.+\\.[jt]sx?$': 'babel-jest',
}, |
@eiel That definitely did not work for me and just caused more errors. :/ |
- Fix story name suggested by eslint - We cannot go beyond jest 26 because jest >= 27 breaks storyshot Ref: storybookjs/storybook#15916
I've created a basic repro using 6.4.22 + the Vite builder here: https://github.com/aendra-rininsland/storybook-vite-storyshots-react-repro Everything works fine out of the box, it's only when I add the MDX story that everything goes to pot. Downgrading Jest to 26 fixes everything. |
https://www.npmjs.com/package/jest-chain-transform is a better approach than trying to do it inside of another transformer that has logic. Note that it won't work with ESM transformers (or native ESM in code) (but 'use strict';
const dedent = require('dedent');
// simplified version of https://github.com/storybookjs/storybook/blob/82696f194790378720ecb5e946f4bb3636a9e0df/addons/storyshots/storyshots-core/injectFileName.js
module.exports = {
process(src, fileName) {
return {
code: dedent`${src};
if(exports.default != null) {
exports.default.parameters = exports.default.parameters || {};
exports.default.parameters.fileName = '${fileName.replace(/\\/g, '\\\\')}';
}
`,
};
},
}; Jest probably should have a way of chaining transformers natively |
Hello. Same problem for me with jest 28 and storybook 6.5 with MDX stories |
I got this issue a few days back when I try to update all my dependencies, looks like StoryShots is not compatible with Jest 27 and beyond. But because of this answer It went well but still required to create a test file per component, so I refactored my approach and manage to have similar result as StoryShots and this is my final file: https://github.com/glrodasz/cero-components/blob/master/storybook.test.js The config is still specified for my project but maybe can help you What I'm doing is the following:
If you were using StoryShots only to create DOM snapshots this will do the same for you without StoryShots addon. |
The future of storyshots is the test-runner: And use the play function for expectations: We will not be making any improvement / changes to storyshots. |
Describe the bug
A clear and concise description of what the bug is.
I upgraded
jest
from26.6.3
to27.0.6
. All other tests are passing (after addingtestEnvironment: 'jest-environment-jsdom',
to myjest.config.js
), its only the storybook snapshots that are failing.To Reproduce
Please create a reproduction by running
npx sb@next repro
and following the instructions. Read our documentation to learn more about creating reproductions.Paste your repository and deployed reproduction here. We prioritize issues with reproductions over those without.
System
Please paste the results of
npx sb@next info
here.Additional context
Add any other context about the problem here.
I tried to reproduce it with the new repo but I'm going to have to come back to that in a bit >_<
The text was updated successfully, but these errors were encountered: