Open akphi opened 3 years ago
I also tried to use @jest/global
- https://jestjs.io/blog/2020/05/05/jest-26#a-new-way-to-consume-jest---jestglobals - I have tried to make it work with the following patch
0001-use-jest-globals.patch.txt
but there are a few problems:
jest-extended
https://github.com/facebook/jest/issues/12424 injectGlobals=false
, some test seem to be failing as they assume the global jest
i.e.
jest-canvas-mock,
testing-library`, etc. so maybe it's not worth the effort?I have updated the codebase to use @jest/globals
but still stuck with injectGlobals
. Seems like that flag has more implications than just removing the globals, I start seeing errors in testing-library
and jsdom
as well.
Workaround regarding issue with uuid
has been resolved by https://github.com/finos/legend-studio/pull/1453
Jest
has this weird problem around Promise
, sometimes, .mockResolvedValue()
does not work as intended
See https://github.com/facebook/jest/issues/2549
See https://github.com/facebook/jest/issues/6645
See https://github.com/facebook/jest/issues/2549
Maybe it's not a bad idea to switch to another test framework, we could consider https://github.com/vitest-dev/vitest
Looks like it has a killer VSCode plugin for running tests https://marketplace.visualstudio.com/items?itemName=ZixuanChen.vitest-explorer
Read more about Vite vs Jest
here - https://blog.bitsrc.io/vite-is-better-than-webpack-d5dd59610d56
There seems to be a small problem with its performance https://github.com/vitest-dev/vitest/issues/579 https://vitest.dev/guide/features.html#threads https://blog.logrocket.com/testing-vite-minimal-config-using-vitest/
on this note, we could also look at Vite
instead of webpack
to simplify toolchain
jest does not fully support ESM - See https://github.com/facebook/jest/issues/9430. When we upgrade and use
ESM
support, we can:main
field inpackage.json
and letbabel-jest
handle the transform for these ESM modules - There is currently a problem with this - https://github.com/facebook/jest/issues/9771lodash-es
- https://github.com/lodash/lodash/issues/5107uuid
does not fit well withjest-resolve
- https://github.com/uuidjs/uuid/pull/616ESM
because of all the problems in - https://github.com/facebook/jest/issues/9430#issuecomment-851917792 - mainly to do with usage ofjest.mock
andjest.requiresActual
which are only used inGrammarRoundtrip
tests right now. We will be able to get rid of these by using process env variable hack (e.g.process.env.TEST_GRAMMAR_ROUNDTRIP
)This is extracted from the umbrella tracker for
dependencies
#83 We will close this once we can fully adoptESM
in our usage withJest
and make necessary adjustments in the codebaseUPDATED:
We have adopted ESM
exports
style, but we haven't fully immerse inESM
mode yet as it seems fromNode
side there are quite a number of stabilization to be done. And holes to patch, such as problems withuuid
,lodash-es
as mentioned above, so I will keep this PR open for now.