finos / legend-studio

Legend Studio
https://legend.finos.org
Apache License 2.0
89 stars 114 forks source link

Re-evaluate usage of `Jest` as test-runner #502

Open akphi opened 3 years ago

akphi commented 3 years ago

jest does not fully support ESM - See https://github.com/facebook/jest/issues/9430. When we upgrade and use ESM support, we can:


This is extracted from the umbrella tracker for dependencies #83 We will close this once we can fully adopt ESM in our usage with Jest and make necessary adjustments in the codebase


UPDATED:

We have adopted ESM exports style, but we haven't fully immerse in ESM mode yet as it seems from Node side there are quite a number of stabilization to be done. And holes to patch, such as problems with uuid, lodash-es as mentioned above, so I will keep this PR open for now.

akphi commented 2 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:

akphi commented 2 years ago

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.

See https://github.com/finos/legend-studio/pull/1190

akphi commented 2 years ago

Workaround regarding issue with uuid has been resolved by https://github.com/finos/legend-studio/pull/1453

akphi commented 2 years ago

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