Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

Commit

Permalink
chore: Add Jest and testing-library
Browse files Browse the repository at this point in the history
- Add jest
- Configure jest to work with [TypeScript][1] and [Gatsby][2]
- Add [testing-library][3] to help with unit-testing
- Refine storybook's file-glob search to match the new filename
  conventions

In order to remove some noise, components will follow a new name
convention, where each component will be be accompanied by
`stories.mdx` and `test.tsx` files.

TypeScript definitions for the testing-library matchers [are not used by
the compiler][4], unless we manually import the matchers on each test,
instead of using the `setupAfterEnvFiles` property from Jest.

[1]: https://kulshekhar.github.io/ts-jest/user/config/
[2]: https://www.gatsbyjs.org/docs/unit-testing/
[3]: https://testing-library.com/docs/dom-testing-library/example-intro
[4]: testing-library/jest-dom#11 (comment)
  • Loading branch information
Couto committed Aug 28, 2019
1 parent 2fa585a commit 8c59bf5
Show file tree
Hide file tree
Showing 9 changed files with 2,408 additions and 29 deletions.
5 changes: 4 additions & 1 deletion .storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ window.___navigate = pathname => {
addDecorator(withA11y);
addDecorator(withKnobs);

configure(require.context('../src', true, /\.stories\.(mdx|tsx)$/), module);
configure(
require.context('../src', true, /(.*)(\.*)stories\.(js|ts|md)x*/),
module,
);
20 changes: 20 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
preset: 'ts-jest',
collectCoverage: true,
moduleNameMapper: {
'.+\\.(css|styl|less|sass|scss)$': `identity-obj-proxy`,
'.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': `<rootDir>/support/file-mock.js`,
},
testPathIgnorePatterns: [
`node_modules`,
`.cache`,
'.storybook',
'coverage',
'public',
'storybook-static',
],
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
globals: {
__PATH_PREFIX__: ``,
},
};
Loading

0 comments on commit 8c59bf5

Please sign in to comment.