-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add component tests #163
base: master
Are you sure you want to change the base?
Add component tests #163
Conversation
… by subject ID' test.
Notes on mocking modules:
|
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.
A couple of comments about ESM. Not sure if they're relevant.
I highly recommend using Nock to mock the Panoptes API, rather than mocking the clients.
} | ||
|
||
// Jest doesn't like 'export' (i.e. ES6 modules), so we use module.exports (CommonJS modules). | ||
// Probably because it's running in Node.js. |
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.
Node supports export
but only for ESM, ie. type: 'module'
in package.json
or .mjs
files.
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.
This repo's package.json
doesn't declare the package type, so Node and Jest default to CommonJS.
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 Jim, that's very helpful to know! I didn't realise Node.js could support ESM.
I took some time to explore converting this package to an ESM, but that's gonna be a work in progress.
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.
Pure ESM might be a good idea when starting a new project, but it's definitely a fair bit of work converting an existing package.
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.
Also, #153 is failing the tests because @zooniverse/react-components
now depends on d3, for SVG data subjects, and d3 is pure ESM.
TODO: this isn't working, as the SubjectImage seems to continue updating outside the act() | ||
Perhaps we need to implement useSWR (https://github.com/zooniverse/community-catalog/pull/131) (to avoid using setState in useEffect), or look into other patterns that handle async calls. | ||
(@shaunanoordin 20230826) |
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.
React 18 has a new, concurrent data-fetching model. They recommend using a framework like Remix or NextJS, rather than implementing your own data-fetching model (Alice and FEM both have examples of how that can go wrong.)
https://react.dev/blog/2022/03/29/react-v18#suspense-in-data-frameworks
Updates:
Moving forward:
Example: error message when `@zooniverse/panoptes-js` module **isn't** mocked, in SubjectImage.spec.jsResults as of commit 47c54aa. Similar results whether we've made those ESM conversions or not.
|
PR Overview
This PR adds component tests, to flesh out the Catalog's test suite beyond the absolutely minimal "can the App render without crashing?" test in App.spec.js.
Status
WIP