-
Notifications
You must be signed in to change notification settings - Fork 79
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
Blocks: Add jest infrastructure for component testing #211
Conversation
We need to add a few dev packages: `babel-preset-default` is needed locally for jest to detect it. The @WordPress packages are needed since we're not loading the whole WP admin context for these tests. As we write more tests, we will probably have to add more packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look's great!
@@ -21,6 +21,9 @@ | |||
"rememo": "3.0.0" | |||
}, | |||
"devDependencies": { | |||
"@wordpress/babel-preset-default": "4.4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to import this Babel preset anymore if you use @wordpress/scripts
v3.4.0. This was a bug which should be resolved now.
I opened WordPress/gutenberg-examples#84 to explore all of this myself and I identified a couple of things which we can simplify on Gutenberg side to make it more seamless. I will work on it in the following weeks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out – I started out by updating the @wordpress/*
packages but was running into some eslint
issues. Tried again just now and it's fine - I think part of it might've been that I wanted to add eslint-plugin-jest
to our config, but then had trouble replicating it to debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think part of it might've been that I wanted to add
eslint-plugin-jest
to our config, but then had trouble replicating it to debug.
I will handle it as part of WordPress/gutenberg#17016. It might take a few weeks until it gets released though. As soon as you want to override config, you have to bring defaults and this might mean more dependencies. That's why it's so important to do the recommended configs correctly. We will refine @wordpress/scripts
to make it seamless for real :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's why I've been working to remove as much of our overrides as we can 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(but getting the lint errors in the test file was why I started down the eslint-jest path, I ended up just adding a comment to the file in the end, like you did with WordPress/gutenberg-examples#84 )
This removes the need to import `@wordpress/babel-preset-default` explicitly
I guess this looks great as is. I can't think of anything we can improve without doing direct changes to |
We need to add a few dev packages:
babel-preset-default
is needed locally for jest to detect it. The@wordpress/*
packages are needed by jest since we're not loading the whole WP admin context for these tests. As we write more tests, we will probably have to add more packages (but these are not used by webpack, so they do not add to the bundle size).This PR also adds a trivial test suite for
ItemTitle
, which tests each available prop using snapshot testing. The snapshot file is also version controlled, because it should be the same for everyone (though we probably don't need to commit snapshots to SVN). For more about testing, I've also updated the readme for this folder.To test
npm install
to update the dev dependenciesnpm test
to run the tests