-
Notifications
You must be signed in to change notification settings - Fork 7
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
draw function snapshot testing #15
draw function snapshot testing #15
Conversation
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.
Great work, @TheTallJerry!
tests/draw.spec.ts
Outdated
@@ -0,0 +1,34 @@ | |||
import { MemoryModel } from "../src/memory_model"; |
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.
The two imports are inconsistent, and they shouldn't need to be. You can import both MemoryModel
and draw
from ../src/index
, as that file exports both of them. (Not sure if importing from index.js
is special in some way.)
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 evolved into something larger. Essentially, the new import now looks like
import exports from "../src";
const { MemoryModel, draw } = exports;
which is valid syntax (and cleaner) outside of this context. However, it appears that RoughJS relies on ESM exports, which Jest has confirmed that it won't support. This comes into play with the draw
function as it eventually calls RoughJS.
As a result, with this setup, Jest reports an error along the lines of Unexpected token export
. This is fixed by forcing a manual resolve with Jest, as mentioned on stackoverflow and specifically this comment. The updated Jest config now has
moduleNameMapper: {
// Force module roughjs to resolve with the CJS entry point, because Jest does not support package.json.exports. Elaborated in PR#15.
"roughjs": require.resolve('roughjs'),
},
If Jest at some point supports ESM, or if RoughJS gets updated to be compatible with Jest in this aspect, then this configuration can be removed. As shown above, I left a comment alongside the config for future reference.
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.
Related: because MemoryModel
is exported as a class and then dynamically imported, in order to use it as a type, I had to use InstanceType<typeof MemoryModel>
instead of simply MemoryModel
. See this stackoverflow comment for more elaboration.
d8f88c3
to
160c52d
Compare
160c52d
to
fc5ba62
Compare
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.
Great work, thank you @TheTallJerry!
draw
function, testing an exact same generated SVG should the seed be provided.